public LogEntry(INDArray toLog, String status) { //this.id = toLog.id(); this.shape = toLog.shape(); this.stride = toLog.stride(); this.ndArrayType = toLog.getClass().getName(); this.length = toLog.length(); this.references = toLog.data().references(); this.dataType = toLog.data().dataType() == DataBuffer.Type.DOUBLE ? "double" : "float"; this.timestamp = System.currentTimeMillis(); this.stackTraceElements = Thread.currentThread().getStackTrace(); this.status = status; }
/** * Convert an ndarray to a byte array * @param arr the array to convert * @return the converted byte array * @throws IOException */ public static byte[] toByteArray(INDArray arr) throws IOException { if (arr.length() * arr.data().getElementSize() > Integer.MAX_VALUE) throw new ND4JIllegalStateException(""); ByteArrayOutputStream bos = new ByteArrayOutputStream((int) (arr.length() * arr.data().getElementSize())); DataOutputStream dos = new DataOutputStream(bos); write(arr, dos); byte[] ret = bos.toByteArray(); return ret; }
/** * computes the sum of magnitudes of all vector elements or, for a complex vector x, the sum * * @param arr * @return */ @Override public double asum(INDArray arr) { if (arr.isSparse()) { return Nd4j.getSparseBlasWrapper().level1().asum(arr); } if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, arr); if (arr.data().dataType() == DataBuffer.Type.DOUBLE) { DefaultOpExecutioner.validateDataType(DataBuffer.Type.DOUBLE, arr); return dasum(arr.length(), arr, BlasBufferUtil.getBlasStride(arr)); } else if (arr.data().dataType() == DataBuffer.Type.FLOAT) { DefaultOpExecutioner.validateDataType(DataBuffer.Type.FLOAT, arr); return sasum(arr.length(), arr, BlasBufferUtil.getBlasStride(arr)); } else { DefaultOpExecutioner.validateDataType(DataBuffer.Type.HALF, arr); return hasum(arr.length(), arr, BlasBufferUtil.getBlasStride(arr)); } }
/** * Setup the given byte buffer * for serialization (note that this is for uncompressed INDArrays) * 4 bytes int for rank * 4 bytes for data opType * shape buffer * data buffer * * @param arr the array to setup * @param allocated the byte buffer to setup * @param rewind whether to rewind the byte buffer or nt */ public static void doByteBufferPutUnCompressed(INDArray arr, ByteBuffer allocated, boolean rewind) { // ensure we send data to host memory Nd4j.getExecutioner().commit(); Nd4j.getAffinityManager().ensureLocation(arr, AffinityManager.Location.HOST); ByteBuffer buffer = arr.data().pointer().asByteBuffer().order(ByteOrder.nativeOrder()); ByteBuffer shapeBuffer = arr.shapeInfoDataBuffer().pointer().asByteBuffer().order(ByteOrder.nativeOrder()); //2 four byte ints at the beginning allocated.putInt(arr.rank()); //put data opType next so its self describing allocated.putInt(arr.data().dataType().ordinal()); allocated.put(shapeBuffer); allocated.put(buffer); if (rewind) allocated.rewind(); }
NdIndexIterator ndIndexIterator = new NdIndexIterator(element.shape()); for(int i = 0; i < indices.columns(); i++) { int[] specifiedIndex = indices.getColumn(i).dup().data().asInt(); putScalar(specifiedIndex,element.getDouble(ndIndexIterator.next())); for(int i = 0; i < indices.rows(); i++) { INDArray row = indices.getRow(i); for(int j = 0; j < row.length(); j++) { INDArray slice = slice(row.getInt(j)); Nd4j.getExecutioner().exec(new Assign(new INDArray[]{slice,element},new INDArray[]{slice})); arrList.add(slice(row.getInt(j))); for(int i = 0; i < indices.length(); i++) { arrList.add(slice(indices.getInt(i)));
@Override public INDArray compress(INDArray array) { INDArray dup = array.dup(array.ordering()); Nd4j.getExecutioner().commit(); dup.setData(compress(dup.data())); dup.markAsCompressed(true); return dup; }
/** * spr performs a rank-1 update of an n-by-n packed symmetric matrix a: * a := alpha*x*x' + a. * * @param order * @param Uplo * @param alpha * @param X * @param Ap */ @Override public void spr(char order, char Uplo, double alpha, INDArray X, INDArray Ap) { if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, Ap, X); // FIXME: int cast if (X.data().dataType() == DataBuffer.Type.DOUBLE) { DefaultOpExecutioner.validateDataType(DataBuffer.Type.DOUBLE, X); dspr(order, Uplo, (int) X.length(), alpha, X, X.majorStride(), Ap); } else { DefaultOpExecutioner.validateDataType(DataBuffer.Type.FLOAT, X); sspr(order, Uplo, (int) X.length(), (float) alpha, X, X.majorStride(), Ap); } OpExecutionerUtil.checkForAny(Ap); }
public LogEntry(INDArray toLog, StackTraceElement[] stackTraceElements, String status) { //this.id = toLog.id(); this.shape = toLog.shape(); this.stride = toLog.stride(); this.ndArrayType = toLog.getClass().getName(); this.length = toLog.length(); this.references = toLog.data().references(); this.dataType = toLog.data().dataType() == DataBuffer.Type.DOUBLE ? "double" : "float"; this.timestamp = System.currentTimeMillis(); this.stackTraceElements = stackTraceElements; this.status = status; }
/** * computes a vector by a scalar product. * * @param N * @param alpha * @param X */ @Override public void scal(long N, double alpha, INDArray X) { if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, X); if (X.isSparse()) { Nd4j.getSparseBlasWrapper().level1().scal(N, alpha, X); } else if (X.data().dataType() == DataBuffer.Type.DOUBLE) dscal(N, alpha, X, BlasBufferUtil.getBlasStride(X)); else if (X.data().dataType() == DataBuffer.Type.FLOAT) sscal(N, (float) alpha, X, BlasBufferUtil.getBlasStride(X)); else if (X.data().dataType() == DataBuffer.Type.HALF) Nd4j.getExecutioner().exec(new ScalarMultiplication(X, alpha)); }
@Override public List<long[]> calculateOutputShape() { int numArgs = args().length; if(numArgs < 1) return Collections.emptyList(); val shape = args()[0].getArr(); if(shape == null) return Collections.emptyList(); else { if(shape.length() == 1) { if(shape.getDouble(0) < 1) return Arrays.asList(new long[]{1,1}); else return Arrays.asList(new long[]{1,shape.getInt(0)}); } } return Arrays.asList(shape.data().asLong()); }
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); if (isVector()) { ScalarAdd op = new ScalarAdd(this, columnVector, this, this.length(), 0.0); op.setDimension(1); Nd4j.getExecutioner().exec(op); break; ScalarSet op = new ScalarSet(this, columnVector, this, this.length(), 0.0); op.setDimension(1); Nd4j.getExecutioner().exec(op); break; ScalarSubtraction op = new ScalarSubtraction(this, columnVector, this, this.length(), 0.0); op.setDimension(1); Nd4j.getExecutioner().exec(op); break;
.append(Arrays.toString(ndarray.shapeInfoDataBuffer().asInt())).append("; Values: ").append(Arrays.toString(ndarray.data().asFloat())).append(";\n"); val map = Nd4j.getExecutioner().getCustomOperations();
/** * tpmv computes a matrix-vector product using a triangular packed matrix. * * @param order * @param Uplo * @param TransA * @param Diag * @param Ap * @param X */ @Override public void tpmv(char order, char Uplo, char TransA, char Diag, INDArray Ap, INDArray X) { if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, Ap, X); // FIXME: int cast if (X.data().dataType() == DataBuffer.Type.DOUBLE) { DefaultOpExecutioner.validateDataType(DataBuffer.Type.DOUBLE, X); dtpmv(order, Uplo, TransA, Diag, (int) Ap.length(), Ap, X, X.majorStride()); } else { DefaultOpExecutioner.validateDataType(DataBuffer.Type.FLOAT, X); stpmv(order, Uplo, TransA, Diag, (int) Ap.length(), Ap, X, X.majorStride()); } OpExecutionerUtil.checkForAny(X); }
public static void printNDArrayHeader(INDArray array) { System.out.println(array.data().dataType() + " - order=" + array.ordering() + ", offset=" + array.offset() + ", shape=" + Arrays.toString(array.shape()) + ", stride=" + Arrays.toString(array.stride()) + ", length=" + array.length() + ", data().length()=" + array.data().length()); }
@Override public int iamax(long n, INDArray arr, int stride) { if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL) OpProfiler.getInstance().processBlasCall(false, arr); if (arr.data().dataType() == DataBuffer.Type.DOUBLE) { DefaultOpExecutioner.validateDataType(DataBuffer.Type.DOUBLE, arr); return idamax(n, arr, stride); } else { DefaultOpExecutioner.validateDataType(DataBuffer.Type.FLOAT, arr); return isamax(n, arr, stride); } }
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); ScalarAdd op = new ScalarAdd(this, rowVector, this, this.length(), 0.0); op.setDimension(0); Nd4j.getExecutioner().exec(op); break; ScalarSet op = new ScalarSet(this, rowVector, this, this.length(), 0.0); op.setDimension(0); Nd4j.getExecutioner().exec(op); break; ScalarSubtraction op = new ScalarSubtraction(this, rowVector, this, this.length(), 0.0); op.setDimension(0); Nd4j.getExecutioner().exec(op); break;