/** * Creates a buffer of the specified length based on the data opType * * @param length the length of te buffer * @return the buffer to create */ public static DataBuffer createBuffer(long length) { return createBuffer(length, true); }
public BaseComplexNDArray(float[] data, long[] shape, long[] stride, long offset, Character order) { this.data = Nd4j.createBuffer(data); /* this.stride = ArrayUtil.copy(stride); this.offset = offset; this.ordering = order; init(shape);*/ throw new UnsupportedOperationException(); }
/** * @param data * @param shape * @param offset * @return */ @Override public IComplexNDArray createComplex(double[] data, int[] shape, long offset) { return createComplex(Nd4j.createBuffer(data), shape, offset); }
/** * Construct an ndarray of the specified shape. * * @param shape the shape of the ndarray * @param stride the stride of the ndarray * @param offset the desired offset * @param ordering the ordering of the ndarray * @param initialize Whether to initialize the INDArray. If true: initialize. If false: don't. */ public BaseNDArray(int[] shape, int[] stride, long offset, char ordering, boolean initialize) { this(Nd4j.createBuffer(ArrayUtil.prodLong(shape), initialize), shape, stride, offset, ordering); }
/** * @param data * @param shape * @param offset * @param ordering * @return */ @Override public IComplexNDArray createComplex(double[] data, int[] shape, long offset, char ordering) { return createComplex(Nd4j.createBuffer(data), shape, offset, ordering); }
/** * Get the shape from * the given int buffer * @param buffer the buffer to get the shape information for * @return */ public static DataBuffer stride(DataBuffer buffer) { int rank = rank(buffer); return Nd4j.createBuffer(buffer, 1 + rank, rank); }
private void setIndexes(BaseSparseNDArrayCOO coo, boolean oneBased) { int incr = oneBased ? 1 : 0; int[] idx = coo.getIncludedIndices().asInt(); int[] rows = new int[nnz]; int[] cols = new int[nnz]; for (int i = 0; i < nnz; i++) { rows[i] = idx[i * 2] + incr; cols[i] = idx[(i * 2) + 1] + incr; } rowInd = Nd4j.createBuffer(rows); colInd = Nd4j.createBuffer(cols); }
/** * Get the shape from * the given int buffer * @param buffer the buffer to get the shape information for * @return */ public static DataBuffer shapeOf(DataBuffer buffer) { int rank = (int) buffer.getLong(0); return Nd4j.createBuffer(buffer, 1, rank); }
/** * Construct an ndarray of the specified shape * with an empty data array * * @param shape the shape of the ndarray * @param stride the stride of the ndarray * @param offset the desired offset * @param ordering the ordering of the ndarray */ public BaseNDArray(int[] shape, int[] stride, long offset, char ordering) { this(Nd4j.createBuffer(ArrayUtil.prodLong(shape)), shape, stride, offset, ordering); }
/** * * @param shape * @param offset * @param ordering */ public BaseComplexNDArray(int[] shape, long offset, char ordering) { this(Nd4j.createBuffer(ArrayUtil.prodLong(shape) * 2), shape, Nd4j.getComplexStrides(shape, ordering), offset, ordering); }
/** * * @param shape */ public BaseComplexNDArray(int[] shape) { this(Nd4j.createBuffer(ArrayUtil.prodLong(shape) * 2), shape, Nd4j.getComplexStrides(shape)); }
@Override public INDArray create(long[] shape, long[] stride, long offset, char ordering) { if (shape.length == 1 && shape[0] == 0) { shape = new long[] {1, 1}; } return create(Nd4j.createBuffer(ArrayUtil.prodLong(shape)), shape, stride, offset, ordering); }
@Override public INDArray create(float[] data, char order) { int[] shape = new int[] {1, data.length}; return create(Nd4j.createBuffer(data), shape, Nd4j.getStrides(shape, order), order, 0); }
public BaseNDArray(double[] data, long[] shape, long[] stride, long offset, char ordering) { setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, offset, Shape.elementWiseStride(shape, stride, ordering == 'f'), ordering)); if (data != null && data.length > 0) { this.data = Nd4j.createBuffer(data, offset); if (offset >= data.length) throw new IllegalArgumentException("invalid offset: must be < data.length"); } init(shape, stride); }
public BaseNDArray(float[] data, long[] shape, long[] stride, long offset, char ordering) { setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, offset, Shape.elementWiseStride(shape, stride, ordering == 'f'), ordering)); if (data != null && data.length > 0) { this.data = Nd4j.createBuffer(data, offset); if (offset >= data.length) throw new IllegalArgumentException("invalid offset: must be < data.length"); } init(shape, stride); }
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); }
protected static DataBuffer internalCreateBuffer(float[] data) { val perfX = PerformanceTracker.getInstance().helperStartTransaction(); val buffer = Nd4j.createBuffer(data); PerformanceTracker.getInstance().helperRegisterTransaction(0, perfX, data.length * Nd4j.sizeOfDataType(), MemcpyDirection.HOST_TO_HOST); return buffer; }
protected static DataBuffer internalCreateBuffer(int[] data) { val perfX = PerformanceTracker.getInstance().helperStartTransaction(); val buffer = Nd4j.createBuffer(data); PerformanceTracker.getInstance().helperRegisterTransaction(0, perfX, data.length * Nd4j.sizeOfDataType(), MemcpyDirection.HOST_TO_HOST); return buffer; }
public BaseNDArray(DataBuffer buffer, long[] shape, long[] stride, long offset, char ordering) { this.data = offset > 0 ? Nd4j.createBuffer(buffer, offset, ArrayUtil.prodLong(shape)) : buffer; setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, offset, Shape.elementWiseStride(shape, stride, ordering == 'f'), ordering)); init(shape, stride); // Shape.setElementWiseStride(this.shapeInfo(),Shape.elementWiseStride(shape, stride, ordering == 'f')); }
@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); }