What is the precise specification of `broadcast` in ND4j / DL4j?

廉价感情. 提交于 2020-03-05 03:13:49

问题


What is the precise definition of INDArray.broadcast(long...) in ND4j?

The description of both methods only says "Broadcasts this ndarray to be the specified shape", and does not explain the requirements for acceptable shapes to be broadcast.

The following code (meant to broadcast an ndarray to a shape of an extra first dimension of length 3) does not work:

INDArray array = Nd4j.create(new double[] {1.,2.,3.,4.}, new int[] {2,2}, 'c');
System.out.println("array: " + array);
System.out.println("array.broadcast(3,2,2): " + array.broadcast(3,2,2));

I had previously tried broadcasting an array of shape (4) to (3,4) and that worked. I tried (2,2) to (2,2,3) and got an error about incompatible shapes. In the (2,2) to (3,2,2) above I do not get an error about incompatible shapes, so I guess they are compatible and it should work, but I get the following error:

Error at [D:/jenkins/ws/dl4j-deeplearning4j-1.0.0-beta4-windows-x86_64-cpu/libnd4j/include/ops/declarable/generic/transforms/tile.cpp:83:0]:
TILE op: this op requires repeats vector, either as IArgs or second array with length equal to rank of input array to be tiled !
Exception in thread "main" java.lang.RuntimeException: Op [tile] execution failed
    at org.nd4j.linalg.cpu.nativecpu.ops.NativeOpExecutioner.exec(NativeOpExecutioner.java:1645)
    at org.nd4j.linalg.api.ops.executioner.DefaultOpExecutioner.execAndReturn(DefaultOpExecutioner.java:714)
    at org.nd4j.linalg.api.ndarray.BaseNDArray.broadcast(BaseNDArray.java:5451)
    at org.nd4j.linalg.api.ndarray.BaseNDArray.broadcast(BaseNDArray.java:5465)
    at com.sri.ai.praise.core.representation.interfacebased.factor.core.table.NDArraySandbox.main(NDArraySandbox.java:21)
Caused by: java.lang.RuntimeException: Op validation failed
    at org.nd4j.nativeblas.Nd4jCpu$NativeOps.execCustomOp(Native Method)
    at org.nd4j.linalg.cpu.nativecpu.ops.NativeOpExecutioner.exec(NativeOpExecutioner.java:2045)
    at org.nd4j.linalg.cpu.nativecpu.ops.NativeOpExecutioner.exec(NativeOpExecutioner.java:1637)
    ... 4 more

来源:https://stackoverflow.com/questions/60143939/what-is-the-precise-specification-of-broadcast-in-nd4j-dl4j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!