protected void init(long[] shape, long[] stride) { //default row vector if (shape.length == 1) { init(new long[] {1, shape[0]}, new long[] {1, stride[0]}); } //null character if (ordering() == '\u0000') { //Shape.setOrder(shapeInfo(), Nd4j.order()); throw new IllegalStateException("setOrder() shouldn't ever happen here"); } }
protected void init(int[] shape, int[] stride) { //default row vector if (shape.length == 1) { init(new int[] {1, shape[0]}, new int[] {1, stride[0]}); } //null character if (ordering() == '\u0000') { //Shape.setOrder(shapeInfo(), Nd4j.order()); throw new IllegalStateException("setOrder() shouldn't ever happen here"); } }
@Override public int innerMostStride() { if (ordering() == 'c') return stride(-1); return stride(0); }
/** * 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()); }
/** * in place (element wise) division of two matrices * * @param other the second ndarray to divide * @return the result of the divide */ @Override public INDArray div(INDArray other) { return divi(other, Nd4j.createUninitialized(this.shape(), this.ordering())); }
/** * copy (element wise) multiplication of two matrices * * @param other the second ndarray to multiply * @return the result of the addition */ @Override public INDArray mul(INDArray other) { return muli(other, Nd4j.createUninitialized(this.shape(), this.ordering())); }
@Override public INDArray rsub(Number n) { //return dup().rsubi(n); return rsubi(n, Nd4j.createUninitialized(this.shape(), this.ordering())); }
@Override public INDArray div(Number n) { //return dup().divi(n); return divi(n, Nd4j.createUninitialized(this.shape(), this.ordering())); }
@Override public INDArray sub(Number n) { //return dup().subi(n); return subi(n, Nd4j.createUninitialized(this.shape(), this.ordering())); }
@Override public INDArray add(Number n) { //return dup().addi(n); return addi(n, Nd4j.createUninitialized(this.shape(), this.ordering())); }
@Override public INDArray mul(Number n) { // return dup().muli(n); return muli(n, Nd4j.createUninitialized(this.shape(), this.ordering())); }
@Override public void setShapeAndStride(int[] shape, int[] stride) { setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, 0, -1, ordering())); }
@Override public INDArray rdiv(Number n) { //return dup().rdivi(n); return rdivi(n, Nd4j.createUninitialized(this.shape(), this.ordering())); }
@Override public Number percentileNumber(Number quantile) { if (quantile.intValue() < 0 || quantile.intValue() > 100) throw new ND4JIllegalStateException("Percentile value should be in 0...100 range"); if (isScalar()) return this.getDouble(0); INDArray sorted = Nd4j.sort(this.dup(this.ordering()), true); return getPercentile(quantile, sorted); }
@Override public void setStride(long[] stride) { setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape(), stride, 0, elementWiseStride(), ordering())); }
@Override public void setStride(int[] stride) { setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape(), ArrayUtil.toLongArray(stride), 0, elementWiseStride(), ordering())); }
/** * Negate each element. */ @Override public INDArray neg() { return Nd4j.getExecutioner().exec(new Negative(this, Nd4j.createUninitialized(this.shape(), this.ordering()))) .z(); }
@Override public INDArray dup() { WorkspaceUtils.assertValidArray(this, "Cannot duplicate INDArray"); if (this.isCompressed() && this.ordering() == Nd4j.order().charValue()) { INDArray ret = Nd4j.createArrayFromShapeBuffer(data().dup(), this.shapeInfoDataBuffer()); ret.markAsCompressed(true); return ret; } Nd4j.getCompressor().autoDecompress(this); INDArray ret = Shape.toOffsetZeroCopy(this); return ret; }
@Override public INDArray dup(char order) { WorkspaceUtils.assertValidArray(this, "Cannot duplicate INDArray"); if (this.isCompressed() && this.ordering() == order) { INDArray ret = Nd4j.createArrayFromShapeBuffer(data().dup(), this.shapeInfoDataBuffer()); ret.markAsCompressed(true); return ret; } Nd4j.getCompressor().autoDecompress(this); return Shape.toOffsetZeroCopy(this, order); }