/** * @param data the data to use * @param shape the shape of the ndarray * @param offset the desired offset * @param ordering the ordering of the ndarray */ public BaseNDArray(float[] data, int[] shape, long offset, char ordering) { this(data, shape, Nd4j.getStrides(shape, ordering), offset); }
/** * Constructor for stride and offset * * @param buffer * @param shape * @param offset * @param ordering */ public BaseNDArray(DataBuffer buffer, int[] shape, long offset, char ordering) { this(buffer, shape, Nd4j.getStrides(shape, ordering), offset, ordering); }
/** * * @param shape * @param offset * @param ordering */ public BaseNDArray(int[] shape, long offset, char ordering) { this(shape, Nd4j.getStrides(shape, ordering), offset, ordering); }
/** * * @param shape * @param offset */ public BaseNDArray(int[] shape, long offset) { this(shape, Nd4j.getStrides(shape), offset); }
/** * Create an ndarray from the specified slices. * This will go through and merge all of the * data from each slice in to one ndarray * which will then take the specified shape * * @param slices the slices to merge * @param shape the shape of the ndarray */ public BaseNDArray(List<INDArray> slices, int[] shape, char ordering) { this(slices, shape, Nd4j.getStrides(shape, ordering), ordering); }
/** * Create an ndrray with the specified shape * * @param data the data to use with tne ndarray * @param shape the shape of the ndarray * @return the created ndarray */ @Override public INDArray create(double[] data, int[] shape) { return create(data, shape, Nd4j.getStrides(shape), 0); }
@Override public INDArray create(float[] data, long[] shape) { //ensure shapes that wind up being scalar end up with the write shape if (shape.length == 1 && shape[0] == 0) { shape = new long[] {1, 1}; } return create(data, shape, Nd4j.getStrides(shape), 0); }
@Override public INDArray create(double[] data, long[] shape) { //ensure shapes that wind up being scalar end up with the write shape if (shape.length == 1 && shape[0] == 0) { shape = new long[] {1, 1}; } return create(data, shape, Nd4j.getStrides(shape), 0); }
/** * Create with the specified shape and buffer * * @param shape the shape * @param buffer the buffer */ public BaseNDArray(int[] shape, DataBuffer buffer) { this.data = buffer; init(shape, Nd4j.getStrides(shape)); }
/** * Get the strides based on the shape * and NDArrays.order() * * @param shape the shape of the ndarray * @return the strides for the given shape * and order specified by NDArrays.order() */ public static int[] getStrides(int[] shape) { return getStrides(shape, Nd4j.order()); }
/** * Get the strides based on the shape * and NDArrays.order() * * @param shape the shape of the ndarray * @return the strides for the given shape * and order specified by NDArrays.order() */ public static long[] getStrides(long[] shape) { return getStrides(shape, Nd4j.order()); }
/** * Calculate the strides based on the given indices * * @param ordering the ordering to calculate strides for * @param indexes the indices to calculate stride for * @return the strides for the given indices */ public static int[] strides(char ordering, NDArrayIndex... indexes) { return Nd4j.getStrides(shape(indexes), ordering); }
@Override public INDArray create(double[] data, char order) { return create(data, new int[] {1, data.length}, Nd4j.getStrides(new int[] {1, data.length}, order), order, 0); }
/** * Creates an ndarray with the specified shape * * @param shape the shape of the ndarray * @return the instance */ @Override public INDArray create(long[] shape) { //ensure shapes that wind up being scalar end up with the write shape return create(shape, Nd4j.getStrides(shape), 0L); }
@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); }
/** * * @param data * @param shape */ public BaseNDArray(DataBuffer data, int[] shape) { this(data, shape, Nd4j.getStrides(shape, Nd4j.order()), 0, Nd4j.order()); }
@Override public INDArray create(float[] data, int[] shape, char ordering) { //ensure shapes that wind up being scalar end up with the write shape if (shape.length == 1 && shape[0] == 0) { shape = new int[] {1, 1}; } return create(Nd4j.createBuffer(data), shape, Nd4j.getStrides(shape, ordering), 0, ordering); }
/** * * @param floatBuffer * @param order */ public BaseNDArray(DataBuffer floatBuffer, char order) { this(floatBuffer, new int[] {(int) floatBuffer.length()}, Nd4j.getStrides(new int[] {(int) floatBuffer.length()}, order), 0, order); if (floatBuffer.length() >= Integer.MAX_VALUE) throw new IllegalArgumentException("Length of buffer can not be >= Integer.MAX_VALUE"); }
/** * * @param buffer * @param shape * @param offset */ public BaseNDArray(DataBuffer buffer, int[] shape, long offset) { this(Nd4j.createBuffer(buffer, offset, ArrayUtil.prodLong(shape)), shape, Nd4j.getStrides(shape), offset, Nd4j.order()); }
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); }