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

Add missing dtypes. #887

Merged
merged 2 commits into from
Sep 15, 2023
Merged
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
23 changes: 12 additions & 11 deletions keras_core/utils/dtype_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
from keras_core import ops


DTYPE_TO_SIZE = {
**{f"float{i}": i for i in (16, 32, 64)},
**{f"int{i}": i for i in (8, 16, 32, 64)},
**{f"uint{i}": i for i in (8, 16, 32, 64)},
"bfloat16": 16,
"bool": 1,
}

def dtype_size(dtype):
if dtype in ("bfloat16", "float16"):
return 16
if dtype in ("float32", "int32"):
return 32
if dtype in ("float64", "int64"):
return 64
if dtype == "uint8":
return 8
if dtype == "bool":
return 1
raise ValueError(f"Invalid dtype: {dtype}")
size = DTYPE_TO_SIZE.get(dtype, None)
if size is None:
raise ValueError(f"Invalid dtype: {dtype}")
return size


def is_float(dtype):
Expand Down