-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathZarrDatatype.m
More file actions
102 lines (84 loc) · 3.28 KB
/
Copy pathZarrDatatype.m
File metadata and controls
102 lines (84 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
classdef ZarrDatatype
%ZARRDATATYPE Datatype of Zarr data
% Represents the datatype mapping between MATLAB, Tensorstore, and Zarr
% Copyright 2025-2026 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 (Access = private)
% 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)
% 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
tensorstoreType (1,1) string {ZarrDatatype.mustBeTensorstoreType}
end
ind = find(tensorstoreType == ZarrDatatype.TensorstoreTypes);
obj = ZarrDatatype(ind);
end
function obj = fromZarrType(zarrType)
% Create a datatype object based on Zarr datatype name
arguments
zarrType (1,1) string {ZarrDatatype.mustBeZarrType}
end
ind = find(zarrType == ZarrDatatype.ZarrTypes);
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
function mustBeZarrType(type)
% Validator for Zarr types
mustBeMember(type, ZarrDatatype.ZarrTypes)
end
end
end