@Override public INDArray backprop(INDArray output, int miniBatchSize) { if (output == null) return null; // In a few cases: output may be null, and this is valid. Like time series data // -> embedding layer // Need to reshape FeedForward layer epsilons (2d) to 3d (for use in RNN layer backprop // calculations) if (output.rank() != 2) throw new IllegalArgumentException( "Invalid input: expect NDArray with rank 2 (i.e., epsilons from feed forward layer)"); if (output.ordering() == 'c') output = Shape.toOffsetZeroCopy(output, 'f'); int[] shape = output.shape(); INDArray reshaped = output.reshape('f', miniBatchSize, shape[0] / miniBatchSize, shape[1]); return reshaped.permute(0, 2, 1); }