Skip to content

Commit 11464ae

Browse files
committed
fix for type correction.
1 parent 53f9cbf commit 11464ae

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

+types/+util/checkDtype.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
try
8282
val = types.util.correctType(val, type);
8383
catch ME
84-
keyboard;
8584
error('MATNWB:CASTERROR', 'Could not cast type `%s` to `%s` for property `%s`',...
8685
class(val), type, name);
8786
end

+types/+util/correctType.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
%CORRECTTYPE upcasts if type is smaller than minimum
33
% Will error if type is simply incompatible
44
% Will throw if casting is impossible
5-
5+
if nargin < 3
6+
allowDowncast = false;
7+
end
68
%check different types and correct
79

810
if startsWith(type, 'float') && ~isfloat(val)
@@ -18,8 +20,8 @@
1820
end
1921

2022
%check different types sizes and upcast to meet minimum (if applicable)
21-
if any(strcmp(type, {'float64' 'float32'})
22-
if issingle(val)
23+
if any(strcmp(type, {'float64' 'float32'}))
24+
if isa(val, 'single')
2325
val = double(val);
2426
elseif allowDowncast && strcmp(type, 'float32')
2527
val = single(val);
@@ -33,7 +35,7 @@
3335
typsz = sscanf(type, pattern);
3436
valsz = sscanf(class(val), pattern);
3537

36-
if valsz < typsz || (nargin > 2 && allowDowncast)
38+
if valsz < typsz || allowDowncast
3739
val = eval([type '(val)']);
3840
end
3941
end

0 commit comments

Comments
 (0)