/** * Flattens the array for linear indexing * * @return the flattened version of this array */ @Override public INDArray ravel() { return reshape(1, length()); }
/** * Returns a linear view reference of shape * 1,length(ndarray) * * @return the linear view of this ndarray */ @Override public INDArray linearView() { return reshape(this.ordering(), 1, this.length()); }
/** * Number of slices: aka shape[0] * * @return the number of slices * for this nd array */ @Override public long slices() { if (isRowVector()) return length(); return size(0); }
/** * Checks whether the matrix is a column vector. */ @Override public boolean isColumnVector() { return rank() == 2 && columns() == 1 && length() > 1; }
@Override public INDArray remainderi(Number denominator) { ScalarRemainder op = new ScalarRemainder(this, null, this, this.length(), denominator); Nd4j.getExecutioner().exec(op); return this; }
/** * Assign all of the elements in the given * ndarray to this ndarray * * @param arr the elements to assign * @return this */ @Override public INDArray assign(final INDArray arr) { Nd4j.getExecutioner().exec(new org.nd4j.linalg.api.ops.impl.transforms.Set(this, arr, this, length())); return this; }
@Override public INDArray neqi(INDArray other) { Nd4j.getExecutioner().exec(new OldNotEqualTo(this, other, this, length())); return this; }
@Override public INDArray remainder(Number denominator, INDArray result) { ScalarRemainder op = new ScalarRemainder(this, null, result, this.length(), denominator); Nd4j.getExecutioner().exec(op); return result; }
@Override public INDArray eqi(INDArray other) { Nd4j.getExecutioner().exec(new OldEqualTo(this, other, this, length())); return this; }
@Override public INDArray gti(INDArray other) { Nd4j.getExecutioner().exec(new OldGreaterThan(this, other, this, length())); return this; }
@Override public INDArray fmod(Number denominator, INDArray result) { ScalarFMod op = new ScalarFMod(this, null, result, this.length(), denominator); Nd4j.getExecutioner().exec(op); return result; }
@Override public INDArray lti(INDArray other) { Nd4j.getExecutioner().exec(new OldLessThan(this, other, this, length())); return this; }
@Override public INDArray fmodi(Number denominator) { ScalarFMod op = new ScalarFMod(this, null, this, this.length(), denominator); Nd4j.getExecutioner().exec(op); return this; }
/** * In place epsilon equals than comparison: * If the given number is less than the * comparison number the item is 0 otherwise 1 * * @param other the number to compare * @return */ @Override public INDArray epsi(INDArray other) { Nd4j.getExecutioner().exec(new Eps(this, other, this, length())); return this; }
@Override public INDArray condi(Condition condition) { Nd4j.getCompressor().autoDecompress(this); INDArray linear = this; for (int i = 0; i < length(); i++) { boolean met = condition.apply(linear.getDouble(i)); linear.putScalar(i, met ? 1 : 0); } return this; }
@Override public boolean isView() { /* We don't really use Shape offset value anywhere And it's possible to be not a view, and have non-empty originalBuffer */ // length/data.length can be different in case of Threshold conversion return Shape.offset(javaShapeInformation) > 0 || (length() < data().length() && data.dataType() != DataBuffer.Type.INT) || data().originalDataBuffer() != null; }
protected void read(ObjectInputStream s) { shapeInformation = Nd4j.createBuffer(new int[Shape.shapeInfoLength(rank())], 0); shapeInformation.read(s); setShapeInformation(Pair.create(shapeInformation, shapeInformation.asLong())); data = Nd4j.createBuffer(length(), false); data().read(s); }
@Override public INDArray convertToFloats() { if (data.dataType() == DataBuffer.Type.FLOAT) return this; val factory = Nd4j.getNDArrayFactory(); val buffer = Nd4j.createBuffer(new long[]{this.length()}, DataBuffer.Type.FLOAT); factory.convertDataEx(convertType(data.dataType()), this.data().addressPointer(), DataBuffer.TypeEx.FLOAT, buffer.addressPointer(), buffer.length()); return Nd4j.createArrayFromShapeBuffer(buffer, this.shapeInformation); }
@Override public INDArray convertToDoubles() { if (data.dataType() == DataBuffer.Type.DOUBLE) return this; val factory = Nd4j.getNDArrayFactory(); val buffer = Nd4j.createBuffer(new long[]{this.length()}, DataBuffer.Type.DOUBLE); factory.convertDataEx(convertType(data.dataType()), this.data().addressPointer(), DataBuffer.TypeEx.DOUBLE, buffer.addressPointer(), buffer.length()); return Nd4j.createArrayFromShapeBuffer(buffer, this.shapeInformation); }