Java Code Examples for org.nd4j.linalg.factory.Nd4j#getStrides()

The following examples show how to use org.nd4j.linalg.factory.Nd4j#getStrides() . 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: CpuNDArrayFactory.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Override
public INDArray createUninitializedDetached(DataType dataType, char ordering, long... shape){
    MemoryWorkspace workspace = Nd4j.getMemoryManager().getCurrentWorkspace();
    Nd4j.getMemoryManager().setCurrentWorkspace(null);
    INDArray ret = new NDArray(dataType, shape, Nd4j.getStrides(shape, ordering), 0, ordering, false);
    Nd4j.getMemoryManager().setCurrentWorkspace(workspace);
    return ret;
}
 
Example 2
Source File: BaseNDArray.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param data
 * @param ordering
 */
public BaseNDArray(float[][] data, char ordering) {
    this(internalCreateBuffer(ordering == 'c' ? ArrayUtil.flatten(data) : ArrayUtil.flattenF(data)),
            new int[] {data.length, data[0].length},
            Nd4j.getStrides(new int[] {data.length, data[0].length}, ordering), 0, ordering);

    int c = columns();
    for (int r = 0; r < rows(); r++) {
        Preconditions.checkState(data[r].length == c, "data[%s].length=%s must be equal to number of columns %s", r, data[r].length, c );
    }
}
 
Example 3
Source File: BaseNDArray.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @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");
    long[] shape = {1, (int) buffer.length()};
    long[] stride = Nd4j.getStrides(shape);
    setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride,  1, Nd4j.order(), buffer.dataType(), false));
    init(shape, stride);
}
 
Example 4
Source File: BaseNDArray.java    From nd4j with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @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");
}
 
Example 5
Source File: BaseNDArray.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param data
 * @param ordering
 */
public BaseNDArray(double[][] data, char ordering) {
    this(internalCreateBuffer(ordering == 'c' ? ArrayUtil.flatten(data) : ArrayUtil.flattenF(data)),
            new int[] {data.length, data[0].length},
            Nd4j.getStrides(new int[] {data.length, data[0].length}, ordering), 0, ordering);

    int c = columns();
    for (int r = 0; r < rows(); r++) {
        Preconditions.checkState(data[r].length == c, "data[%s].length=%s must be equal to number of columns %s", r, data[r].length, c );
    }
}
 
Example 6
Source File: CpuNDArrayFactory.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Override
public INDArray createUninitializedDetached(long[] shape, char ordering) {
    MemoryWorkspace workspace = Nd4j.getMemoryManager().getCurrentWorkspace();
    Nd4j.getMemoryManager().setCurrentWorkspace(null);
    INDArray ret = new NDArray(shape, Nd4j.getStrides(shape, ordering), 0, ordering, false);
    Nd4j.getMemoryManager().setCurrentWorkspace(workspace);
    return ret;
}
 
Example 7
Source File: BaseNDArray.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public BaseNDArray(List<INDArray> slices, long[] shape, char ordering) {
    this(slices, shape, Nd4j.getStrides(shape, ordering), ordering);
}
 
Example 8
Source File: BaseNDArray.java    From nd4j with Apache License 2.0 4 votes vote down vote up
public BaseNDArray(DataBuffer buffer, long[] shape, char ordering) {
    this(buffer, shape, Nd4j.getStrides(shape, ordering), 0, ordering);
}
 
Example 9
Source File: BaseNDArray.java    From nd4j with Apache License 2.0 4 votes vote down vote up
protected int[] getStrides(int[] shape, char ordering) {
    return Nd4j.getStrides(shape, ordering);
}
 
Example 10
Source File: CpuNDArrayFactory.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
public INDArray createUninitialized(long[] shape, char ordering) {
    return new NDArray(shape, Nd4j.getStrides(shape, ordering), 0, ordering, false);
}
 
Example 11
Source File: BaseNDArray.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public BaseNDArray(DataBuffer buffer, long[] shape, char ordering) {
    this(buffer, shape, Nd4j.getStrides(shape, ordering), 0, ordering);
}
 
Example 12
Source File: CpuNDArrayFactory.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Override
public INDArray createUninitialized(int[] shape, char ordering) {
    return new NDArray(shape, Nd4j.getStrides(shape, ordering), 0, ordering, false);
}
 
Example 13
Source File: CpuNDArrayFactory.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Override
public INDArray create(DataType dataType, long[] shape, char ordering, MemoryWorkspace workspace) {
    return new NDArray(dataType, shape, Nd4j.getStrides(shape, ordering), 0, ordering, workspace);
}
 
Example 14
Source File: JCublasNDArrayFactory.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
public INDArray create(double[] data, long[] shape, long offset, Character order) {
    return new JCublasNDArray(data, shape, Nd4j.getStrides(shape, order), offset, order);
}
 
Example 15
Source File: BaseNDArray.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public BaseNDArray(DataBuffer data, long[] shape) {
    this(data, shape, Nd4j.getStrides(shape, Nd4j.order()), 0, Nd4j.order());
}
 
Example 16
Source File: BaseNDArray.java    From nd4j with Apache License 2.0 2 votes vote down vote up
/**
 *
 * @param shape
 * @param offset
 * @param ordering
 */
public BaseNDArray(int[] shape, long offset, char ordering) {
    this(shape, Nd4j.getStrides(shape, ordering), offset, ordering);
}
 
Example 17
Source File: BaseNDArray.java    From deeplearning4j with Apache License 2.0 2 votes vote down vote up
/**
 *
 * @param data
 * @param shape
 */
public BaseNDArray(DataBuffer data, int[] shape) {
    this(data, shape, Nd4j.getStrides(shape, Nd4j.order()), 0, Nd4j.order());
}
 
Example 18
Source File: CpuNDArrayFactory.java    From nd4j with Apache License 2.0 2 votes vote down vote up
/**
 * Creates an ndarray with the specified shape
 *
 * @param list
 * @param shape the shape of the ndarray
 * @return the instance
 */
@Override
public INDArray create(List<INDArray> list, int[] shape) {
    return new NDArray(list, shape, Nd4j.getStrides(shape));
}
 
Example 19
Source File: BaseNDArray.java    From nd4j with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}
 
Example 20
Source File: Indices.java    From nd4j with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}