@Test public void when_assembling2INDArrays_expect_stackedAsResult() { INDArray[] input = new INDArray[] { Nd4j.create(new double[] { 1.0, 2.0, 3.0 }), Nd4j.create(new double[] { 10.0, 20.0, 30.0 }), }; HistoryStackAssembler sut = new HistoryStackAssembler(); INDArray result = sut.assemble(input); assertEquals(2, result.shape().length); assertEquals(2, result.shape()[0]); assertEquals(3, result.shape()[1]); assertEquals(1.0, result.getDouble(0, 0), 0.00001); assertEquals(2.0, result.getDouble(0, 1), 0.00001); assertEquals(3.0, result.getDouble(0, 2), 0.00001); assertEquals(10.0, result.getDouble(1, 0), 0.00001); assertEquals(20.0, result.getDouble(1, 1), 0.00001); assertEquals(30.0, result.getDouble(1, 2), 0.00001); }
@Override public INDArray assemble(INDArray[] elements) { long[] elementShape = elements[0].shape(); long[] newShape = new long[elementShape.length + 1]; newShape[0] = elements.length; System.arraycopy(elementShape, 0, newShape, 1, elementShape.length); INDArray result = Nd4j.create(newShape); for(int i = 0; i < elements.length; ++i) { result.putRow(i, elements[i]); } return result; }
HistoryStackAssembler implements HistoryMergeAssembler { @Override public INDArray assemble(INDArray[] elements) { long[] elementShape = elements[0].shape(); long[] newShape = new long[elementShape.length + 1]; newShape[0] = elements.length; System.arraycopy(elementShape, 0, newShape, 1, elementShape.length); INDArray result = Nd4j.create(newShape); for(int i = 0; i < elements.length; ++i) { result.putRow(i, elements[i]); } return result; } }
HistoryStackAssembler implements HistoryMergeAssembler { @Override public INDArray assemble(INDArray[] elements) { long[] elementShape = elements[0].shape(); long[] newShape = new long[elementShape.length + 1]; newShape[0] = elements.length; System.arraycopy(elementShape, 0, newShape, 1, elementShape.length); INDArray result = Nd4j.create(newShape); for(int i = 0; i < elements.length; ++i) { result.putRow(i, elements[i]); } return result; }  }
HistoryStackAssembler implements HistoryMergeAssembler { @Override public INDArray assemble(INDArray[] elements) { long[] elementShape = elements[0].shape(); long[] newShape = new long[elementShape.length + 1]; newShape[0] = elements.length; System.arraycopy(elementShape, 0, newShape, 1, elementShape.length); INDArray result = Nd4j.create(newShape); for(int i = 0; i < elements.length; ++i) { result.putRow(i, elements[i]); } return result; }  @Override INDArray assemble(INDArray[] elements); }
HistoryStackAssembler implements HistoryMergeAssembler { @Override public INDArray assemble(INDArray[] elements) { long[] elementShape = elements[0].shape(); long[] newShape = new long[elementShape.length + 1]; newShape[0] = elements.length; System.arraycopy(elementShape, 0, newShape, 1, elementShape.length); INDArray result = Nd4j.create(newShape); for(int i = 0; i < elements.length; ++i) { result.putRow(i, elements[i]); } return result; }  @Override INDArray assemble(INDArray[] elements);  }