@@ -16,11 +16,13 @@ function validateShape(propertyName, validShapes, value)
1616 end
1717 elseif isa(value , ' types.untyped.DataPipe' )
1818 valueShape = value .internal .maxSize ;
19- % For data pipes, vectors can be exported to HDF5 files as 2D arrays
20- % (columnar (n,1) or row (1,n)). The types.util.checkDims function allows
21- % this, even if the valid shape specifies that the data should be 1D.
22- % Use 'enforceScalarShape' to ensure that 2D-like vectors do not
23- % pass validation when the valid shape specifies 1D data.
19+ % For DataPipe objects, vectors can be exported to HDF5 files as 2D arrays
20+ % with shape [n,1] (column) or [1,n] (row). By default, types.util.checkDims
21+ % allows these 2D shapes to pass validation even when the valid shape
22+ % specifies 1D data (e.g., [Inf]). However, for DataPipe, the maxSize
23+ % property determines the actual shape in the exported file, so we need
24+ % stricter validation. Set 'enforceScalarShape' to true to ensure that
25+ % shapes like [n,1] or [1,n] are not accepted when [Inf] is specified.
2426 enforceScalarShape = true ;
2527 elseif istable(value )
2628 valueShape = [height(value ) 1 ];
@@ -49,7 +51,17 @@ function validateShape(propertyName, validShapes, value)
4951 % Check actual size of DataPipe and warn if it is not valid
5052 if isa(value , ' types.untyped.DataPipe' )
5153 try
54+ if enforceScalarShape
55+ % Reset enforceScalarShape to false when validating the current
56+ % data size. Strict validation is only needed for maxSize, which
57+ % determines the final shape of the dataset in the exported file.
58+ % The current data size is allowed to be more flexible (e.g.,
59+ % [n,1] can match [Inf]).
60+ enforceScalarShape = false ;
61+ end
62+
5263 valueShape = size(value );
64+
5365 types .util .checkDims(valueShape , validShapes , enforceScalarShape );
5466 catch ME
5567 warning(...
0 commit comments