/** * In place addition of a column vector * * @param columnVector the column vector to add * @return the result of the addition */ @Override public INDArray subColumnVector(INDArray columnVector) { return dup().subiColumnVector(columnVector); }
@Override public Number amaxNumber() { return amax(Integer.MAX_VALUE).getDouble(0); }
@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); }
/** * See: http://www.mathworks.com/help/matlab/ref/permute.html * * @param rearrange the dimensions to swap to * @return the newly permuted array */ @Override public INDArray permute(int... rearrange) { Nd4j.getCompressor().autoDecompress(this); if (rearrange.length != rank()) return dup(); boolean alreadyInOrder = true; //IntBuffer shapeInfo = shapeInfo(); int rank = Shape.rank(javaShapeInformation); for (int i = 0; i < rank; i++) { if (rearrange[i] != i) { alreadyInOrder = false; break; } } if (alreadyInOrder) return this; checkArrangeArray(rearrange); int[] newShape = doPermuteSwap(shapeOf(), rearrange); int[] newStride = doPermuteSwap(strideOf(), rearrange); char newOrder = Shape.getOrder(newShape, newStride, elementStride()); INDArray value = create(data(), newShape, newStride, offset(), newOrder); return value; }
switch (operation) { case 'a': addi(columnVector.getDouble(0)); break; case 'p': assign(columnVector.getDouble(0)); break; case 's': subi(columnVector.getDouble(0)); break; case 'm': muli(columnVector.getDouble(0)); break; case 'd': divi(columnVector.getDouble(0)); break; case 'h': rsubi(columnVector.getDouble(0)); break; case 't': rdivi(columnVector.getDouble(0)); break; if (!columnVector.isColumnVector() || this.size(0) != columnVector.size(0) || columnVector.length() <= 1) { throw new IllegalStateException("Mismatched shapes (shape = " + Arrays.toString(shape()) + ", column vector shape =" + Arrays.toString(columnVector.shape()) + ")"); if (columnVector.data().sameUnderlyingData(data())) return doColumnWise(columnVector.dup(), operation);
return detach(); } else { return this; if (!this.isView()) { Nd4j.getExecutioner().commit(); DataBuffer buffer = Nd4j.createBuffer(this.lengthLong(), false); Nd4j.getMemoryManager().memcpy(buffer, this.data()); copy = Nd4j.createArrayFromShapeBuffer(buffer, this.shapeInfoDataBuffer()); } else { copy = this.dup(this.ordering()); Nd4j.getExecutioner().commit();
if (Shape.shapeEquals(shape, shape())) return this; if (this.isScalar()) return Nd4j.createUninitialized(shape).assign(this.getDouble(0)); if (count < 0 || thisCount < 0) break; if (shape[count] != shape()[thisCount] && shape[count] != 1 && shape()[thisCount] != 1) { compatible = false; break; throw new IllegalArgumentException("Incompatible broadcast from " + Arrays.toString(shape()) + " to " + Arrays.toString(shape)); List<Integer> nonBroadCastDimensions = new ArrayList<>(); for (int i = 0; i < retShape.length; i++) { if (shape().length == 1) { if (i == 0) { if (i < shape().length) retShape[i] = Math.max(1, shape[i]); else retShape[i] = shape[i]; } else { if (i < shape().length) retShape[i] = Math.max(shape[i], size(i)); else retShape[i] = shape[i];
newShape[0] = this.length(); if (shape[j] >= 1) shapeLength *= shape[j]; long realShape = Math.abs(length() / shapeLength); long[] thisNewShape = new long[shape.length]; for (int j = 0; j < shape.length; j++) { if (prod != this.lengthLong()){ throw new ND4JIllegalStateException("New shape length doesn't match original length: [" + prod + "] vs [" + this.lengthLong() + "]. Original shape: "+Arrays.toString(this.shape())+" New Shape: "+Arrays.toString(newShape)); if (order != ordering()) { ret.setData(dup(order).data()); } else ret.assign(this);
switch (operation) { case 'a': addi(row.getComplex(0)); break; case 's': subi(row.getComplex(0)); break; case 'm': muli(row.getComplex(0)); break; case 'd': divi(row.getComplex(0)); break; case 'h': rsubi(row.getComplex(0)); break; case 't': rdivi(row.getComplex(0)); break; switch (operation) { case 'a': addi(vector.getDouble(0)); break; case 's': subi(vector.getDouble(0)); break; case 'm': muli(vector.getDouble(0));
protected void write(ObjectOutputStream out) throws IOException { if (this.isView()) { //As per Nd4j.write, duplicate before writing to the output stream //BaseDataBuffer.write(...) doesn't know about strides etc, so dup (or equiv. strategy) is necessary here //Furthermore, because we only want to save the *actual* data for a view (not the full data), the shape info // (mainly strides, offset, element-wise stride) may be different in the duped array vs. the view array INDArray copy = this.dup(); copy.shapeInfoDataBuffer().write(out); copy.data().write(out); } else { shapeInformation.write(out); data().write(out); } }
@Override public boolean equals(Object o) { //if (o != null) AtomicAllocator.getInstance().synchronizeHostData((INDArray) o); //AtomicAllocator.getInstance().synchronizeHostData(this); return super.equals(o); }
/** * Generate string representation of the matrix. */ @Override public String toString() { return super.toString(); }
@Override public INDArray permutei(int... rearrange) { Nd4j.getExecutioner().push(); return super.permutei(rearrange); }
/** * in place addition of two matrices * * @param other the second ndarray to add * @return the result of the addition */ @Override public INDArray addi(INDArray other) { return addi(other, this); }
@Override public Number aminNumber() { return amin(Integer.MAX_VALUE).getDouble(0); }
@Override public Number ameanNumber() { return amean(Integer.MAX_VALUE).getDouble(0); }
switch (operation) { case 'a': addi(rowVector.getDouble(0)); break; case 'p': assign(rowVector.getDouble(0)); break; case 's': subi(rowVector.getDouble(0)); break; case 'm': muli(rowVector.getDouble(0)); break; case 'd': divi(rowVector.getDouble(0)); break; case 'h': rsubi(rowVector.getDouble(0)); break; case 't': rdivi(rowVector.getDouble(0)); break; if (!rowVector.isRowVector() || this.rank() > 1 && rowVector.rank() > 1 && this.size(1) != rowVector.size(1) || rowVector.length() <= 1) { throw new IllegalStateException("Mismatched shapes (shape = " + Arrays.toString(shape()) + ", row vector shape =" + Arrays.toString(rowVector.shape()) + ")"); if (rowVector.data().sameUnderlyingData(data())) return doRowWise(rowVector.dup(), operation);