-
Notifications
You must be signed in to change notification settings - Fork 179
ucar.ma2.Array.factory(DataType type, int[] shape) creates an array of unexpected size when shape is empty #1211
Comments
Greetings! The As an example: Array scalar = Array.factory(DataType.INT, new int[0]);
Array multidim = Array.factory(DataType.INT, new int[] {3, 4});
System.out.printf("scalar Rank: %d\n", scalar.getRank());
System.out.printf("scalar Number of elements: %d\n", scalar.getSize());
System.out.println();
System.out.printf("multidim Rank: %d\n", multidim.getRank());
System.out.printf("multidim Number of elements: %d\n", multidim.getSize()); would give: scalar Rank: 0
scalar Number of elements: 1
multidim Rank: 2
multidim Number of elements: 12 |
Greetings, thank you for the prompt reply! So just to clarify: the only way to create an Array of size == 0 is to use a non-empty shape array where the elements' product is equal to 0, e.g.:
Side question: do I understand correctly then, that the reported behaviour is not considered a bug but a feature? Best regards |
Hmmm, that's a good question. I'm not sure if it even makes sense for netCDF-Java to be able to create a zero sized |
It is possible to create a variable with a zero-size dimension using UNLIMITED.
|
A |
May be relevant: #1212 |
Summary
When creating an Array given an empty shape, the value returned by
Array.getSize()
is equal to 1 e.g.:Array array = Array.factory(DataType.INT, new int[0]);
whereas we'd expect it to be zero.
Note 1: whether the
DataType
version of the method is used, or an overloaded one taking aClass
does not matter. Neither does the type - the size is always== 1
for empty shapes.Note 2: We're using edu.ucar:cmd-4.6.7.
If this behaviour is expected, can you please point out to documentation highliting the reasoning for that (if available).
The text was updated successfully, but these errors were encountered: