Java Code Examples for org.nd4j.linalg.api.shape.Shape#shapeOf()

The following examples show how to use org.nd4j.linalg.api.shape.Shape#shapeOf() . 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: ShapeBufferTests.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testShape() {
    long[] shape = {2, 4};
    long[] stride = {1, 2};
    val shapeInfoBuffer = Shape.createShapeInformation(shape, stride, 1, 'c', DataType.DOUBLE, false);
    val buff = shapeInfoBuffer.asNioLong();
    val shapeView = Shape.shapeOf(buff);
    assertTrue(Shape.contentEquals(shape, shapeView));
    val strideView = Shape.stride(buff);
    assertTrue(Shape.contentEquals(stride, strideView));
    assertEquals('c', Shape.order(buff));
    assertEquals(1, Shape.elementWiseStride(buff));
    assertFalse(Shape.isVector(buff));
    assertTrue(Shape.contentEquals(shape, Shape.shapeOf(buff)));
    assertTrue(Shape.contentEquals(stride, Shape.stride(buff)));
}
 
Example 2
Source File: ShapeBufferTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testShape() {
    int[] shape = {2, 4};
    int[] stride = {1, 2};
    IntBuffer buff = Shape.createShapeInformation(shape, stride, 0, 1, 'c').asNioInt();
    IntBuffer shapeView = Shape.shapeOf(buff);
    assertTrue(Shape.contentEquals(shape, shapeView));
    IntBuffer strideView = Shape.stride(buff);
    assertTrue(Shape.contentEquals(stride, strideView));
    assertEquals('c', Shape.order(buff));
    assertEquals(1, Shape.elementWiseStride(buff));
    assertFalse(Shape.isVector(buff));
    assertTrue(Shape.contentEquals(shape, Shape.shapeOf(buff)));
    assertTrue(Shape.contentEquals(stride, Shape.stride(buff)));
}
 
Example 3
Source File: ByteOrderTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testShapeStridesOf1() {
    val buffer = new int[]{2, 5, 5, 5, 1, 0, 1, 99};

    val shape = Shape.shapeOf(buffer);
    val strides = Shape.stridesOf(buffer);

    assertArrayEquals(new int[]{5, 5}, shape);
    assertArrayEquals(new int[]{5, 1}, strides);
}
 
Example 4
Source File: ByteOrderTests.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testShapeStridesOf2() {
    val buffer = new int[]{3, 5, 5, 5, 25, 5, 1, 0, 1, 99};

    val shape = Shape.shapeOf(buffer);
    val strides = Shape.stridesOf(buffer);

    assertArrayEquals(new int[]{5, 5, 5}, shape);
    assertArrayEquals(new int[]{25, 5, 1}, strides);
}
 
Example 5
Source File: BaseNDArray.java    From nd4j with Apache License 2.0 5 votes vote down vote up
protected DataBuffer shapeOf() {
    //        if (shape == null)
    //            shape = Shape.shapeOf(shapeInfoDataBuffer());
    //        return shape;

    return Shape.shapeOf(shapeInfoDataBuffer());
}
 
Example 6
Source File: ByteOrderTests.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testShapeStridesOf1() {
    val buffer = new int[]{2, 5, 5, 5, 1, 0, 1, 99};

    val shape = Shape.shapeOf(buffer);
    val strides = Shape.stridesOf(buffer);

    assertArrayEquals(new int[]{5, 5}, shape);
    assertArrayEquals(new int[]{5, 1}, strides);
}
 
Example 7
Source File: ByteOrderTests.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testShapeStridesOf2() {
    val buffer = new int[]{3, 5, 5, 5, 25, 5, 1, 0, 1, 99};

    val shape = Shape.shapeOf(buffer);
    val strides = Shape.stridesOf(buffer);

    assertArrayEquals(new int[]{5, 5, 5}, shape);
    assertArrayEquals(new int[]{25, 5, 1}, strides);
}
 
Example 8
Source File: BaseNDArray.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
protected DataBuffer shapeOf() {
    //        if (shape == null)
    //            shape = Shape.shapeOf(shapeInfoDataBuffer());
    //        return shape;

    return Shape.shapeOf(shapeInfoDataBuffer());
}
 
Example 9
Source File: BaseSparseNDArray.java    From nd4j with Apache License 2.0 4 votes vote down vote up
protected DataBuffer shapeOf() {
    if (shape == null)
        shape = Shape.shapeOf(shapeInfoDataBuffer());
    return shape;
}