Skip to content

Commit ebf64f9

Browse files
committed
TEnsors that need more than Integer.Max_INTEGER bytes cannot be created
1 parent 3bf74cf commit ebf64f9

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/main/java/io/bioimage/modelrunner/onnx/tensor/TensorBuilder.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public static <T extends Type<T>> OnnxTensor build(RandomAccessibleInterval<T> r
124124
private static OnnxTensor buildByte(RandomAccessibleInterval<ByteType> tensor, OrtEnvironment env) throws OrtException
125125
{
126126
long[] ogShape = tensor.dimensionsAsLongArray();
127-
if (CommonUtils.int32Overflows(ogShape))
127+
if (CommonUtils.int32Overflows(ogShape, 1))
128128
throw new IllegalArgumentException("Provided tensor with shape " + Arrays.toString(ogShape)
129129
+ " is too big. Max number of elements per tensor supported: " + Integer.MAX_VALUE);
130130
tensor = Utils.transpose(tensor);
@@ -162,9 +162,9 @@ private static OnnxTensor buildByte(RandomAccessibleInterval<ByteType> tensor, O
162162
private static OnnxTensor buildInt(RandomAccessibleInterval<IntType> tensor, OrtEnvironment env) throws OrtException
163163
{
164164
long[] ogShape = tensor.dimensionsAsLongArray();
165-
if (CommonUtils.int32Overflows(ogShape))
165+
if (CommonUtils.int32Overflows(ogShape, 4))
166166
throw new IllegalArgumentException("Provided tensor with shape " + Arrays.toString(ogShape)
167-
+ " is too big. Max number of elements per tensor supported: " + Integer.MAX_VALUE);
167+
+ " is too big. Max number of elements per tensor supported: " + Integer.MAX_VALUE / 4);
168168
tensor = Utils.transpose(tensor);
169169
long[] tensorShape = tensor.dimensionsAsLongArray();
170170
int size = 1;
@@ -200,9 +200,9 @@ private static OnnxTensor buildInt(RandomAccessibleInterval<IntType> tensor, Ort
200200
private static OnnxTensor buildFloat(RandomAccessibleInterval<FloatType> tensor, OrtEnvironment env) throws OrtException
201201
{
202202
long[] ogShape = tensor.dimensionsAsLongArray();
203-
if (CommonUtils.int32Overflows(ogShape))
203+
if (CommonUtils.int32Overflows(ogShape, 4))
204204
throw new IllegalArgumentException("Provided tensor with shape " + Arrays.toString(ogShape)
205-
+ " is too big. Max number of elements per tensor supported: " + Integer.MAX_VALUE);
205+
+ " is too big. Max number of elements per tensor supported: " + Integer.MAX_VALUE / 4);
206206
tensor = Utils.transpose(tensor);
207207
long[] tensorShape = tensor.dimensionsAsLongArray();
208208
int size = 1;
@@ -238,9 +238,9 @@ private static OnnxTensor buildFloat(RandomAccessibleInterval<FloatType> tensor,
238238
private static OnnxTensor buildDouble(RandomAccessibleInterval<DoubleType> tensor, OrtEnvironment env) throws OrtException
239239
{
240240
long[] ogShape = tensor.dimensionsAsLongArray();
241-
if (CommonUtils.int32Overflows(ogShape))
241+
if (CommonUtils.int32Overflows(ogShape, 8))
242242
throw new IllegalArgumentException("Provided tensor with shape " + Arrays.toString(ogShape)
243-
+ " is too big. Max number of elements per tensor supported: " + Integer.MAX_VALUE);
243+
+ " is too big. Max number of elements per tensor supported: " + Integer.MAX_VALUE / 8);
244244
tensor = Utils.transpose(tensor);
245245
long[] tensorShape = tensor.dimensionsAsLongArray();
246246
int size = 1;

0 commit comments

Comments
 (0)