@Override public void setShapeAndStride(int[] shape, int[] stride) { setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, 0, -1, ordering())); }
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); }
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); }
private static DataBuffer getIm2ColShape(INDArray img, int kernelHeight, int kernelWidth, int outHeight, int outWidth) { //number of images long n = img.size(0); //number of channels (depth) long c = img.size(1); return Nd4j.getShapeInfoProvider().createShapeInformation(new long[] {n, c, kernelHeight, kernelWidth, outHeight, outWidth}, 'c').getFirst(); }
@Override public void setShape(long[] shape) { setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride(), 0, elementWiseStride(), ordering())); }
@Override public void setOrder(char order) { setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape(), stride(), 0, elementWiseStride(), order)); }
/** * * @param buffer */ public BaseNDArray(DataBuffer buffer) { this.data = buffer; if (buffer.length() >= Integer.MAX_VALUE) throw new IllegalArgumentException("Length of buffer can not be >= Integer.MAX_VALUE"); int[] shape = {1, (int) buffer.length()}; int[] stride = Nd4j.getStrides(shape); setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, 0, 1, Nd4j.order())); init(shape, stride); }
@Override public void setStride(long[] stride) { setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape(), stride, 0, elementWiseStride(), ordering())); }
public BaseNDArray(long newRows, long newColumns, char ordering) { this.data = Nd4j.createBuffer((long) newRows * newColumns); long[] shape = new long[] {newRows, newColumns}; long[] stride = Nd4j.getStrides(shape, ordering); setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, 0, Shape.elementWiseStride(shape, stride, ordering == 'f'), ordering)); init(shape, stride); }
/** * This method creates compressed INDArray from Java double array, skipping usual INDArray instantiation routines * * @param data * @param shape * @param order * @return */ @Override public INDArray compress(double[] data, int[] shape, char order) { DoublePointer pointer = new DoublePointer(data); DataBuffer shapeInfo = Nd4j.getShapeInfoProvider().createShapeInformation(shape, order).getFirst(); DataBuffer buffer = compressPointer(DataBuffer.TypeEx.DOUBLE, pointer, data.length, 8); return Nd4j.createArrayFromShapeBuffer(buffer, shapeInfo); }
public BaseSparseNDArrayCOO(DataBuffer values, DataBuffer indices, DataBuffer sparseInformation, int[] shape) { this.values = Nd4j.createBuffer(values, 0, values.length()); this.indices = indices; setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape)); init(shape); this.sparseInformation = sparseInformation; this.length = countNNZ(); }
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 void setStride(int[] stride) { setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape(), ArrayUtil.toLongArray(stride), 0, elementWiseStride(), ordering())); }
@Override public void setShape(int[] shape) { setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(ArrayUtil.toLongArray(shape), stride(), 0, elementWiseStride(), ordering())); }
/** * Creates a new <i>n</i> times <i>m</i> <tt>DoubleMatrix</tt>. * * @param newRows the number of rows (<i>n</i>) of the new matrix. * @param newColumns the number of columns (<i>m</i>) of the new matrix. */ public BaseNDArray(int newRows, int newColumns, char ordering) { this.data = Nd4j.createBuffer((long) newRows * newColumns); int[] shape = new int[] {newRows, newColumns}; int[] stride = Nd4j.getStrides(shape, ordering); setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, 0, Shape.elementWiseStride(shape, stride, ordering == 'f'), ordering)); init(shape, stride); }
/** * * @param buffer * @param shape * @param stride * @param offset * @param ordering */ public BaseNDArray(DataBuffer buffer, int[] shape, int[] 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')); }
/** * * @param data * @param shape * @param stride * @param offset */ public BaseNDArray(DataBuffer data, int[] shape, int[] stride, long offset) { this.data = Nd4j.createBuffer(data, offset, ArrayUtil.prodLong(shape)); setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, offset, Shape.elementWiseStride(shape, stride, Nd4j.order() == 'f'), Nd4j.order())); init(shape, stride); // Shape.setElementWiseStride(this.shapeInfo(),Shape.elementWiseStride(shape, stride, Nd4j.order() == 'f')); }
public BaseSparseNDArrayCOO(float[] values, int[][] indices, int[] shape) { checkArgument(values.length == indices.length); checkArgument(values.length == 0 || indices[0].length == shape.length); this.values = Nd4j.createBuffer(values); this.indices = Nd4j.createBuffer(ArrayUtil.flatten(indices)); setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape)); init(shape); this.length = values.length; int[] flags = new int[rank()]; long[] sparseOffsets = new long[rank()]; int[] hiddenDimension = new int[] {-1}; this.sparseInformation = Nd4j.getSparseInfoProvider().createSparseInformation(flags, sparseOffsets, hiddenDimension, rank()); }
public BaseSparseNDArrayCOO(DataBuffer values, DataBuffer indices, int[] shape) { checkArgument(values.length() * shape.length == indices.length()); this.values = Nd4j.createBuffer(values, 0, values.length()); this.indices = indices; setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape)); init(shape); this.length = values.length(); int[] flags = new int[rank()]; long[] sparseOffsets = new long[rank()]; int[] hiddenDimension = new int[] {-1}; this.sparseInformation = Nd4j.getSparseInfoProvider().createSparseInformation(flags, sparseOffsets, hiddenDimension, rank()); }
public BaseSparseNDArrayCSR(DataBuffer data, int[] columnsPointers, int[] pointerB, int[] pointerE, int[] shape) { checkArgument(pointerB.length == pointerE.length); setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape)); init(shape); this.values = data; this.columnsPointers = Nd4j.getDataBufferFactory().createInt(data.length()); this.columnsPointers.setData(columnsPointers); this.length = columnsPointers.length; // The size of these pointers are constant int pointersSpace = rows; this.pointerB = Nd4j.getDataBufferFactory().createInt(pointersSpace); this.pointerB.setData(pointerB); this.pointerE = Nd4j.getDataBufferFactory().createInt(pointersSpace); this.pointerE.setData(pointerE); }