/** * This method produces concatenated array, that consist from tensors, fetched from source array, against some dimension and specified indexes * * @param source source tensor * @param sourceDimension dimension of source tensor * @param indexes indexes from source array * @return */ public static INDArray pullRows(INDArray source, int sourceDimension, int[] indexes) { return pullRows(source, sourceDimension, indexes, Nd4j.order()); }
/** * Get whole rows from the passed indices. * * @param rindices */ @Override public INDArray getRows(int[] rindices) { Nd4j.getCompressor().autoDecompress(this); if (!isMatrix() && !isVector()) throw new IllegalArgumentException("Unable to get columns from a non matrix or vector"); if (isVector()) return Nd4j.pullRows(this, 1, rindices); else { INDArray ret = Nd4j.create(rindices.length, columns()); for (int i = 0; i < rindices.length; i++) ret.putRow(i, getRow(rindices[i])); return ret; } }
/** * Get whole columns * from the passed indices. * * @param cindices */ @Override public INDArray getColumns(int... cindices) { if (!isMatrix() && !isVector()) throw new IllegalArgumentException("Unable to get columns from a non matrix or vector"); if (isVector()) { return Nd4j.pullRows(this, 0, cindices, this.ordering()); } else { INDArray ret = Nd4j.create(rows(), cindices.length); for (int i = 0; i < cindices.length; i++) ret.putColumn(i, getColumn(cindices[i])); return ret; } }
INDArray subset = Nd4j.pullRows(as2d, 1, rowsToPull); //Tensor along dimension 1 == rows return subset;
/** * This method produces concatenated array, that consist from tensors, fetched from source array, against some dimension and specified indexes * * @param source source tensor * @param sourceDimension dimension of source tensor * @param indexes indexes from source array * @return */ public static INDArray pullRows(INDArray source, int sourceDimension, int[] indexes) { return pullRows(source, sourceDimension, indexes, Nd4j.order()); }
/** * Get whole columns * from the passed indices. * * @param cindices */ @Override public INDArray getColumns(int... cindices) { if (!isMatrix() && !isVector()) throw new IllegalArgumentException("Unable to get columns from a non matrix or vector"); if (isVector()) { return Nd4j.pullRows(this, 0, cindices, this.ordering()); } else { INDArray ret = Nd4j.create(rows(), cindices.length); for (int i = 0; i < cindices.length; i++) ret.putColumn(i, getColumn(cindices[i])); return ret; } }
/** * Get whole rows from the passed indices. * * @param rindices */ @Override public INDArray getRows(int[] rindices) { Nd4j.getCompressor().autoDecompress(this); if (!isMatrix() && !isVector()) throw new IllegalArgumentException("Unable to get columns from a non matrix or vector"); if (isVector()) return Nd4j.pullRows(this, 1, rindices); else { INDArray ret = Nd4j.create(rindices.length, columns()); for (int i = 0; i < rindices.length; i++) ret.putRow(i, getRow(rindices[i])); return ret; } }
@Override public INDArray preOutput(boolean training) { if (input.columns() != 1) { //Assume shape is [numExamples,1], and each entry is an integer index throw new DL4JInvalidInputException( "Cannot do forward pass for embedding layer with input more than one column. " + "Expected input shape: [numExamples,1] with each entry being an integer index " + layerId()); } int[] indexes = new int[input.length()]; for (int i = 0; i < indexes.length; i++) indexes[i] = input.getInt(i, 0); INDArray weights = getParam(DefaultParamInitializer.WEIGHT_KEY); INDArray bias = getParam(DefaultParamInitializer.BIAS_KEY); INDArray rows = Nd4j.pullRows(weights, 1, indexes); rows.addiRowVector(bias); return rows; }
INDArray subset = Nd4j.pullRows(as2d, 1, rowsToPull); //Tensor along dimension 1 == rows return subset;
INDArray syn1Neg = storage.getArray(WordVectorStorage.SYN_1_NEGATIVE); INDArray words = Nd4j.pullRows(storage.getArray(WordVectorStorage.SYN_0), 1, cbr.getSyn0rows(), 'c'); INDArray neue = words.mean(0);
INDArray syn1Neg = storage.getArray(WordVectorStorage.SYN_1_NEGATIVE); INDArray words = Nd4j.pullRows(storage.getArray(WordVectorStorage.SYN_0), 1, cbr.getSyn0rows(), 'c'); INDArray neue = words.mean(0);
INDArray words = Nd4j.pullRows(storage.getArray(WordVectorStorage.SYN_0), 1, rowsA, 'c'); INDArray mean = words.mean(0);
INDArray words = Nd4j.pullRows(storage.getArray(WordVectorStorage.SYN_0), 1, rowsA, 'c'); INDArray mean = words.mean(0);