Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions graphblas/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ def register_anonymous(dtype, name=None):
if isinstance(dtype, dict):
# Allow dtypes such as `{'x': int, 'y': float}` for convenience
dtype = _np.dtype([(key, lookup_dtype(val).np_type) for key, val in dtype.items()])
elif isinstance(dtype, str) and "[" in dtype and dtype.endswith("]"):
# Allow dtypes such as `"INT64[3, 4]"` for convenience
base_dtype, shape = dtype.split("[", 1)
base_dtype = lookup_dtype(base_dtype)
shape = _np.lib.format.safe_eval(f"[{shape}")
dtype = _np.dtype((base_dtype.np_type, shape))
else:
raise
if dtype in _registry:
Expand Down
2 changes: 2 additions & 0 deletions graphblas/tests/test_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,8 @@ def test_udt():
# arrays as dtypes!
np_dtype = np.dtype("(3,)uint16")
udt2 = dtypes.register_anonymous(np_dtype, "has_subdtype")
udt2alt = dtypes.register_anonymous("UINT16[3]")
assert udt2 == udt2alt
s = Scalar(udt2)
s.value = [0, 0, 0]

Expand Down