-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor datatype mapping #94
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
Changes from all commits
d936d59
90f0caf
b21ae13
1d93264
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
classdef ZarrDatatype | ||
%ZARRDATATYPE Datatype of Zarr data | ||
% Represents the datatype mapping between MATLAB, Tensorstore, and Zarr | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing copyright There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added! |
||
% Copyright 2025 The MathWorks, Inc. | ||
|
||
properties(Constant, Hidden) | ||
% Same-length arrays that represent mapping between | ||
% three kinds of datatypes | ||
MATLABTypes = ["logical", "uint8", "int8", "uint16", "int16",... | ||
"uint32", "int32", "uint64", "int64", "single", "double"]; | ||
TensorstoreTypes = ["bool", "uint8", "int8", "uint16", "int16",... | ||
"uint32", "int32", "uint64", "int64", "float32", "float64"]; | ||
ZarrTypes = ["|b1", "|u1", "|i1", "<u2", "<i2",... | ||
"<u4", "<i4", "<u8", "<i8", "<f4", "<f8"]; | ||
end | ||
|
||
properties (SetAccess = immutable, GetAccess=private, Hidden) | ||
% Index into datatype arrays | ||
Index (1,1) int32 | ||
end | ||
|
||
properties (Dependent, SetAccess = immutable) | ||
% Dependent properties representing the corresponding datatype in | ||
% Zarr, Tensorstore, and MATLAB | ||
ZarrType | ||
TensorstoreType | ||
MATLABType | ||
end | ||
|
||
methods (Hidden) | ||
% "Private" constructor - should not be used directly. | ||
% Use from*Type() static methods instead. | ||
function obj = ZarrDatatype(ind) | ||
obj.Index = ind; | ||
end | ||
end | ||
|
||
methods | ||
function zType = get.ZarrType(obj) | ||
% Get the corresponding Zarr datatype | ||
zType = ZarrDatatype.ZarrTypes(obj.Index); | ||
end | ||
|
||
function tType = get.TensorstoreType(obj) | ||
% Get the corresponding Tensorstore datatype | ||
tType = ZarrDatatype.TensorstoreTypes(obj.Index); | ||
end | ||
|
||
function mType = get.MATLABType(obj) | ||
% Get the corresponding MATLAB datatype | ||
mType = ZarrDatatype.MATLABTypes(obj.Index); | ||
end | ||
end | ||
|
||
methods (Static) | ||
function obj = fromMATLABType(MATLABType) | ||
jhughes-mw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
% Create a datatype object based on MATLAB datatype name | ||
arguments | ||
MATLABType (1,1) string {ZarrDatatype.mustBeMATLABType} | ||
end | ||
|
||
ind = find(MATLABType == ZarrDatatype.MATLABTypes); | ||
obj = ZarrDatatype(ind); | ||
end | ||
|
||
function obj = fromTensorstoreType(tensorstoreType) | ||
% Create a datatype object based on Tensorstore datatype name | ||
arguments | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need the arguments block and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was my initial impulse as well! Unfortunately there seems to be a limitation:
And it felt worse to me to have to re-list valid types again as a literal There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooof. You can call
And then use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! |
||
tensorstoreType (1,1) string {ZarrDatatype.mustBeTensorstoreType} | ||
end | ||
|
||
ind = find(tensorstoreType == ZarrDatatype.TensorstoreTypes); | ||
obj = ZarrDatatype(ind); | ||
end | ||
|
||
|
||
function mustBeMATLABType(type) | ||
% Validator for MATLAB types | ||
mustBeMember(type, ZarrDatatype.MATLABTypes); | ||
end | ||
|
||
function mustBeTensorstoreType(type) | ||
% Validator for Tensorstore types | ||
mustBeMember(type, ZarrDatatype.TensorstoreTypes) | ||
end | ||
end | ||
|
||
end |
Uh oh!
There was an error while loading. Please reload this page.