public void testConcat() { assertTrue(Arrays.equals(EMPTY, Longs.concat())); assertTrue(Arrays.equals(EMPTY, Longs.concat(EMPTY))); assertTrue(Arrays.equals(EMPTY, Longs.concat(EMPTY, EMPTY, EMPTY))); assertTrue(Arrays.equals(ARRAY1, Longs.concat(ARRAY1))); assertNotSame(ARRAY1, Longs.concat(ARRAY1)); assertTrue(Arrays.equals(ARRAY1, Longs.concat(EMPTY, ARRAY1, EMPTY))); assertTrue( Arrays.equals( new long[] {(long) 1, (long) 1, (long) 1}, Longs.concat(ARRAY1, ARRAY1, ARRAY1))); assertTrue( Arrays.equals( new long[] {(long) 1, (long) 2, (long) 3, (long) 4}, Longs.concat(ARRAY1, ARRAY234))); }
long[] aPlusB = Longs.concat(oldShapeA, oldShapeB); return aPlusB;
/** * Create an n x (shape) * ndarray where the ndarray is repeated num times * * @param n the ndarray to replicate * @param num the number of copies to repeat * @return the repeated ndarray */ public static INDArray repeat(INDArray n, int num) { List<INDArray> list = new ArrayList<>(); for (int i = 0; i < num; i++) list.add(n.dup()); long[] nShape = n.shape(); long[] shape = n.isColumnVector() ? new long[] {n.shape()[0]} : nShape; long[] retShape = Longs.concat(new long[] {num}, shape); return Nd4j.create(list, retShape); }
currSlice = currSlice.reshape(Longs.concat(new long[]{1},currSlice.shape()));
INDArray ret = at.mmul(bt); long[] aPlusB = Longs.concat(oldShapeA, oldShapeB); return ret.reshape(aPlusB);
INDArray ret = at.mmul(bt,result); long[] aPlusB = Longs.concat(oldShapeA, oldShapeB); return ret.reshape(aPlusB);
for(int j = 0; j < row.length(); j++) { INDArray put = arrList.get(j).slice(row.getInt(j)); put = put.reshape(Longs.concat(new long[]{1},put.shape())); arrList.set(j,put); for(int i = 0; i < indices.length(); i++) { INDArray add = slice(indices.getInt(i)); add = add.reshape(Longs.concat(new long[] {1,},add.shape())); arrList.add(add);
long[] aPlusB = Longs.concat(oldShapeA, oldShapeB); return f().reshape(ret, aPlusB);
for(int j = 0; j < row.length(); j++) { INDArray put = arrList.get(j).slice(row.getInt(j)); put = put.reshape(Longs.concat(new long[]{1}, put.shape())); arrList.set(j,put);
@Override public INDArray repeat(int dimension, long... repeats) { Nd4j.getCompressor().autoDecompress(this); if (dimension < 0) dimension += rank(); if (repeats.length < rank()) { if (dimension > 0) repeats = Longs.concat(ArrayUtil.nTimes((long) rank() - repeats.length, 1), repeats); //append rather than prepend for dimension == 0 else repeats = Longs.concat(repeats, ArrayUtil.nTimes((long) rank() - repeats.length, 1)); } long[] newShape = new long[rank()]; for (int i = 0; i < newShape.length; i++) newShape[i] = size(i) * repeats[i]; INDArray ret = Nd4j.create(newShape); //number of times to repeat each value long repeatDelta = ArrayUtil.prod(newShape) / length(); for (int i = 0; i < tensorssAlongDimension(dimension); i++) { INDArray thisTensor = tensorAlongDimension(i, dimension); INDArray retTensor = ret.tensorAlongDimension(i, dimension); int retIdx = 0; for (int k = 0; k < thisTensor.length(); k++) { for (int j = 0; j < repeatDelta; j++) { retTensor.putScalar(retIdx++, thisTensor.getDouble(k)); } } } return ret; }
public void testConcat() { assertTrue(Arrays.equals(EMPTY, Longs.concat())); assertTrue(Arrays.equals(EMPTY, Longs.concat(EMPTY))); assertTrue(Arrays.equals(EMPTY, Longs.concat(EMPTY, EMPTY, EMPTY))); assertTrue(Arrays.equals(ARRAY1, Longs.concat(ARRAY1))); assertNotSame(ARRAY1, Longs.concat(ARRAY1)); assertTrue(Arrays.equals(ARRAY1, Longs.concat(EMPTY, ARRAY1, EMPTY))); assertTrue(Arrays.equals( new long[] {(long) 1, (long) 1, (long) 1}, Longs.concat(ARRAY1, ARRAY1, ARRAY1))); assertTrue(Arrays.equals( new long[] {(long) 1, (long) 2, (long) 3, (long) 4}, Longs.concat(ARRAY1, ARRAY234))); }
private void addDataBlocks(){ // make sure can fit the next batch. listener.addBatch(); try(RollbackCloseable rollbackable = new RollbackCloseable()) { { FixedBlockVector newFixed = new FixedBlockVector(allocator, pivot.getBlockWidth()); rollbackable.add(newFixed); newFixed.ensureAvailableBlocks(MAX_VALUES_PER_BATCH); fixedBlocks = ObjectArrays.concat(fixedBlocks, newFixed); tableFixedAddresses = Longs.concat(tableFixedAddresses, new long[]{newFixed.getMemoryAddress()}); } { VariableBlockVector newVariable = new VariableBlockVector(allocator, pivot.getVariableCount()); rollbackable.add(newVariable); newVariable.ensureAvailableDataSpace(pivot.getVariableCount() == 0 ? 0 : MAX_VALUES_PER_BATCH * defaultVariableLengthSize); variableBlocks = ObjectArrays.concat(variableBlocks, newVariable); initVariableAddresses = Longs.concat(initVariableAddresses, new long[]{newVariable.getMemoryAddress()}); openVariableAddresses = Longs.concat(openVariableAddresses, new long[]{newVariable.getMemoryAddress()}); maxVariableAddresses = Longs.concat(maxVariableAddresses, new long[]{newVariable.getMaxMemoryAddress()}); } rollbackable.commit(); } catch (Exception e) { throw Throwables.propagate(e); } }
private void addDataBlocks(){ // make sure can fit the next batch. listener.resized(currentOrdinal + MAX_VALUES_PER_BATCH); try(RollbackCloseable rollbackable = new RollbackCloseable()) { { FixedBlockVector newFixed = new FixedBlockVector(allocator, pivot.getBlockWidth()); rollbackable.add(newFixed); newFixed.ensureAvailableBlocks(MAX_VALUES_PER_BATCH); fixedBlocks = ObjectArrays.concat(fixedBlocks, newFixed); tableFixedAddresses = Longs.concat(tableFixedAddresses, new long[]{newFixed.getMemoryAddress()}); } { VariableBlockVector newVariable = new VariableBlockVector(allocator, pivot.getVariableCount()); rollbackable.add(newVariable); newVariable.ensureAvailableDataSpace(pivot.getVariableCount() == 0 ? 0 : MAX_VALUES_PER_BATCH * defaultVariableLengthSize); variableBlocks = ObjectArrays.concat(variableBlocks, newVariable); initVariableAddresses = Longs.concat(initVariableAddresses, new long[]{newVariable.getMemoryAddress()}); openVariableAddresses = Longs.concat(openVariableAddresses, new long[]{newVariable.getMemoryAddress()}); maxVariableAddresses = Longs.concat(maxVariableAddresses, new long[]{newVariable.getMaxMemoryAddress()}); } rollbackable.commit(); } catch (Exception e) { throw Throwables.propagate(e); } }
tableFixedAddresses = Longs.concat(tableFixedAddresses, new long[]{newFixed.getMemoryAddress()}); initVariableAddresses = Longs.concat(initVariableAddresses, new long[]{newVariable.getMemoryAddress()}); openVariableAddresses = Longs.concat(openVariableAddresses, new long[]{newVariable.getMemoryAddress()}); maxVariableAddresses = Longs.concat(maxVariableAddresses, new long[]{newVariable.getMaxMemoryAddress()});