Skip to content
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

Account for differences between type() and .type #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
16 changes: 6 additions & 10 deletions adept/utils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def json_to_dict(file_path):

_numpy_to_torch_dtype = {
np.float16: torch.float16,
np.float32:torch.float32,
np.float32: torch.float32,
np.float64: torch.float64,
np.uint8: torch.uint8,
np.int8: torch.int8,
Expand All @@ -96,21 +96,17 @@ def numpy_to_torch_dtype(dtype):
if inspect.isclass(dtype):
name = dtype
else:
name = type(dtype)
name = dtype.type
if name not in _numpy_to_torch_dtype:
raise ValueError(
f"Could not convert numpy dtype {dtype.name} to a torch dtype."
)
name = type(dtype)
if name not in _numpy_to_torch_dtype:
raise ValueError(f"Could not convert numpy dtype {dtype.name} to a torch dtype.")
return _numpy_to_torch_dtype[name]


def torch_to_numpy_dtype(dtype):
if dtype not in _torch_to_numpy_dtype:
raise ValueError(
"Could not convert torch dtype {} to a numpy dtype.".format(
dtype
)
)
raise ValueError("Could not convert torch dtype {} to a numpy dtype.".format(dtype))

return _torch_to_numpy_dtype[dtype]

Expand Down