Java Code Examples for org.nd4j.linalg.api.shape.Shape#assertValidOrder()
The following examples show how to use
org.nd4j.linalg.api.shape.Shape#assertValidOrder() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseNDArray.java From deeplearning4j with Apache License 2.0 | 6 votes |
/** * 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, int[] stride, char ordering) { Shape.assertValidOrder(ordering); DataBuffer ret = slices.get(0).data().dataType() == (DataType.FLOAT) ? Nd4j.createBuffer(new float[ArrayUtil.prod(shape)]) : Nd4j.createBuffer(new double[ArrayUtil.prod(shape)]); this.data = ret; setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(ArrayUtil.toLongArray(shape), ArrayUtil.toLongArray(stride), Shape.elementWiseStride(shape, stride, ordering == 'f'), ordering, slices.get(0).dataType(), false)); init(shape, stride); // Shape.setElementWiseStride(this.shapeInfo(),Shape.elementWiseStride(shape, stride, ordering == 'f')); if (slices.get(0).isScalar()) { for (int i = 0; i < length(); i++) { putScalar(i, slices.get(i).getDouble(0)); } } else { for (int i = 0; i < slices(); i++) { putSlice(i, slices.get(i)); } } }
Example 2
Source File: BaseNDArray.java From deeplearning4j with Apache License 2.0 | 6 votes |
/** * * @param data * @param shape * @param stride * @param offset * @param ordering */ public BaseNDArray(float[] data, int[] shape, int[] stride, long offset, char ordering) { Shape.assertValidOrder(ordering); setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(ArrayUtil.toLongArray(shape), ArrayUtil.toLongArray(stride), Shape.elementWiseStride(shape, stride, ordering == 'f'), ordering, DataType.FLOAT, data != null && data.length > 0 ? false : true)); if (data != null && data.length > 0) { val perfD = PerformanceTracker.getInstance().helperStartTransaction(); this.data = internalCreateBuffer(data, offset); PerformanceTracker.getInstance().helperRegisterTransaction(0, perfD, data.length * Nd4j.sizeOfDataType(DataType.FLOAT), MemcpyDirection.HOST_TO_HOST); if (offset >= data.length) throw new IllegalArgumentException("invalid offset: must be < data.length"); } init(shape, stride); }
Example 3
Source File: BaseNDArray.java From deeplearning4j with Apache License 2.0 | 5 votes |
public BaseNDArray(DataBuffer buffer, long[] shape, long[] stride, long offset, long ews, char ordering) { Shape.assertValidOrder(ordering); this.data = offset > 0 ? Nd4j.createBuffer(buffer, offset, Shape.lengthOfBuffer(shape, stride)) : buffer; setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, ews, ordering, buffer.dataType(), false )); init(shape, stride); // Shape.setElementWiseStride(this.shapeInfo(),Shape.elementWiseStride(shape, stride, ordering == 'f')); }
Example 4
Source File: BaseNDArray.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * 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) { Shape.assertValidOrder(ordering); this.data = Nd4j.createBuffer((long) newRows * newColumns); val shape = new long[] {newRows, newColumns}; val stride = Nd4j.getStrides(shape, ordering); setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, Shape.elementWiseStride(shape, stride, ordering == 'f'), ordering, Nd4j.dataType(), false)); init(shape, stride); }
Example 5
Source File: BaseNDArray.java From deeplearning4j with Apache License 2.0 | 5 votes |
public BaseNDArray(long newRows, long newColumns, char ordering) { Shape.assertValidOrder(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, Shape.elementWiseStride(shape, stride, ordering == 'f'), ordering, Nd4j.dataType(), false)); init(shape, stride); }
Example 6
Source File: BaseNDArray.java From deeplearning4j with Apache License 2.0 | 5 votes |
public BaseNDArray(float[] data, long[] shape, long[] stride, long offset, char ordering) { Shape.assertValidOrder(ordering); setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, Shape.elementWiseStride(shape, stride, ordering == 'f'), ordering, DataType.FLOAT, data != null && data.length > 0 ? false : true)); if (data != null && data.length > 0) { this.data = Nd4j.createTypedBuffer(data, DataType.FLOAT); if (offset >= data.length) throw new IllegalArgumentException("invalid offset: must be < data.length"); } init(shape, stride); }
Example 7
Source File: BaseNDArray.java From deeplearning4j with Apache License 2.0 | 5 votes |
public BaseNDArray(double[] data, long[] shape, long[] stride, long offset, char ordering) { Shape.assertValidOrder(ordering); setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, Shape.elementWiseStride(shape, stride, ordering == 'f'), ordering, DataType.DOUBLE, data != null && data.length > 0 ? false : true)); 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); }
Example 8
Source File: BaseNDArray.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * * @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); Shape.assertValidOrder(order); if (floatBuffer.length() >= Integer.MAX_VALUE) throw new IllegalArgumentException("Length of buffer can not be >= Integer.MAX_VALUE"); }
Example 9
Source File: BaseNDArray.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * * @param buffer * @param shape * @param stride * @param offset * @param ordering */ public BaseNDArray(DataBuffer buffer, int[] shape, int[] stride, long offset, char ordering) { Shape.assertValidOrder(ordering); this.data = offset > 0 ? Nd4j.createBuffer(buffer, offset, Shape.lengthOfBuffer(shape, stride)) : buffer; setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(ArrayUtil.toLongArray(shape), ArrayUtil.toLongArray(stride), Shape.elementWiseStride(shape, stride, ordering == 'f'), ordering, buffer.dataType(), false)); init(shape, stride); // Shape.setElementWiseStride(this.shapeInfo(),Shape.elementWiseStride(shape, stride, ordering == 'f')); }
Example 10
Source File: BaseNDArrayFactory.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public INDArray create(float[] data, int[] shape, char ordering) { Shape.assertValidOrder(ordering); long length = ArrayUtil.prodLong(shape); if(length == 0) return scalar(0.0); return create(Nd4j.createBuffer(data), shape, Nd4j.getStrides(shape, ordering), 0, ordering); }
Example 11
Source File: BaseNDArrayFactory.java From deeplearning4j with Apache License 2.0 | 5 votes |
/** * This method produces concatenated array, that consist from tensors, fetched from source array, against some dimension and specified indexes * * @param source source tensor * @param sourceDimension dimension of source tensor * @param indexes indexes from source array * @return */ @Override public INDArray pullRows(INDArray source, int sourceDimension, int[] indexes, char order) { Shape.assertValidOrder(order); long vectorLength = source.shape()[sourceDimension]; INDArray ret = Nd4j.createUninitialized(new long[] {indexes.length, vectorLength}, order); for (int cnt = 0; cnt < indexes.length; cnt++) { ret.putRow(cnt, source.tensorAlongDimension((int) indexes[cnt], sourceDimension)); } return ret; }
Example 12
Source File: BaseNDArrayFactory.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Override public INDArray create(double[] data, char order) { Shape.assertValidOrder(order); return create(data, new long[] {data.length}, new long[]{1}, DataType.DOUBLE, Nd4j.getMemoryManager().getCurrentWorkspace()); }
Example 13
Source File: BaseNDArrayFactory.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Override public INDArray create(long[] shape, long[] stride, long offset, char ordering) { Shape.assertValidOrder(ordering); return create(Nd4j.createBuffer(ArrayUtil.prodLong(shape)), shape, stride, offset, ordering); }
Example 14
Source File: BaseNDArrayFactory.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Override public INDArray create(DataBuffer buffer, int[] shape, int[] stride, char order, long offset) { Shape.assertValidOrder(order); return create(buffer, shape, stride, offset, order); }
Example 15
Source File: BaseNDArrayFactory.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Override public INDArray randn(char order, long[] shape) { Shape.assertValidOrder(order); return Nd4j.getRandom().nextGaussian(order, shape); }
Example 16
Source File: BaseNDArrayFactory.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Override public INDArray rand(char order, long[] shape) { Shape.assertValidOrder(order); return Nd4j.getRandom().nextDouble(order, shape); }
Example 17
Source File: BaseNDArrayFactory.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Override public INDArray create(int[] data, int[] shape, int[] stride, char order, long offset) { Shape.assertValidOrder(order); return create(Nd4j.createBuffer(data), shape, stride, order, offset); }
Example 18
Source File: BaseNDArrayFactory.java From deeplearning4j with Apache License 2.0 | 2 votes |
/** * Random normal using the current time stamp * as the seed * * @param shape the shape of the ndarray * @return */ @Override public INDArray randn(char order, int[] shape) { Shape.assertValidOrder(order); return Nd4j.getRandom().nextGaussian(order, shape); }
Example 19
Source File: BaseNDArrayFactory.java From deeplearning4j with Apache License 2.0 | 2 votes |
/** * Create a random ndarray with the given shape and order * * @param shape the shape of the ndarray * @return the random ndarray with the specified shape */ @Override public INDArray rand(char order, int[] shape) { Shape.assertValidOrder(order); return Nd4j.getRandom().nextDouble(order, shape); }
Example 20
Source File: BaseNDArrayFactory.java From deeplearning4j with Apache License 2.0 | 2 votes |
/** * Generate a random normal N(0,1) with the specified order and shape * @param order Order of the output array * @param rows the number of rows in the matrix * @param columns the number of columns in the matrix * @return */ @Override public INDArray randn(char order, long rows, long columns) { Shape.assertValidOrder(order); return Nd4j.getRandom().nextGaussian(order, new long[] {rows, columns}); }