check that broadcast shape is correct before doing broadcast in jvm tensors
@@ -533,12 +533,16 @@ public abstract class JVMTensor<T, TENSOR extends Tensor<T, TENSOR>, B extends J
@Override
public TENSOR broadcast(long... toShape) {
+ if (!Arrays.equals(TensorShape.getBroadcastResultShape(shape, toShape), toShape)) {
+ throw new IllegalArgumentException(
+ "Invalid broadcast shape " + Arrays.toString(toShape) + " from shape " + Arrays.toString(shape)
+ );
+ }
+
long outputLength = TensorShape.getLength(toShape);
long[] outputStride = TensorShape.getRowFirstStride(toShape);
B outputBuffer = getFactory().createNew(outputLength);
- TensorShape.getBroadcastResultShape(shape, toShape);
-
JVMTensorBroadcast.broadcast(buffer, shape, stride, outputBuffer, outputStride);
return create(outputBuffer, toShape, outputStride);
