Skip to content

⌨️⚙️ Update torch type checking #1538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update utils.py
  • Loading branch information
cthoyt committed Apr 20, 2025
commit b4a04aae69664a6b99b10289c6e0101a3252e931
17 changes: 6 additions & 11 deletions src/pykeen/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@
from io import BytesIO
from pathlib import Path
from textwrap import dedent
from typing import (
Any,
Generic,
TextIO,
TypeVar,
overload,
)
from typing import Any, Generic, TextIO, TypeVar, cast, overload

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -944,8 +938,8 @@ def powersum_norm(x: FloatTensor, p: float, dim: int | None, normalize: bool) ->
value = x.abs().pow(p).sum(dim=dim)
if not normalize:
return value
dim = torch.as_tensor(x.shape[-1], dtype=torch.float, device=x.device)
return value / dim
denominator = torch.as_tensor(x.shape[-1], dtype=torch.float, device=x.device)
return value / denominator


def complex_normalize(x: torch.Tensor) -> torch.Tensor:
Expand Down Expand Up @@ -1261,7 +1255,7 @@ def _weisfeiler_lehman_iteration_approx(
:return: shape: `(n,)`
the new node colors
"""
num_colors = colors.max() + 1
num_colors: int = colors.max() + 1

# create random indicator functions of low dimensionality
rand = torch.rand(num_colors, dim, device=colors.device)
Expand Down Expand Up @@ -1330,7 +1324,8 @@ def iter_weisfeiler_lehman(
# only keep connectivity, but remove multiplicity
edge_index = edge_index.unique(dim=1)

num_nodes = num_nodes or edge_index.max().item() + 1
if num_nodes is None:
num_nodes = cast(int, edge_index.max().item() + 1)
colors = edge_index.new_zeros(size=(num_nodes,), dtype=torch.long)
# note: in theory, we could return this uniform coloring as the first coloring; however, for featurization,
# this is rather useless
Expand Down
Loading