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

The following examples show how to use org.nd4j.linalg.api.shape.Shape#elementWiseStride() . 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: ElementWiseStrideTests.java    From nd4j with Apache License 2.0 6 votes vote down vote up
@Test
public void testEWS1() throws Exception {
    List<Pair<INDArray,String>> list = NDArrayCreationUtil.getAllTestMatricesWithShape(4,5,12345);
    list.addAll(NDArrayCreationUtil.getAll3dTestArraysWithShape(12345,4,5,6));
    list.addAll(NDArrayCreationUtil.getAll4dTestArraysWithShape(12345,4,5,6,7));
    list.addAll(NDArrayCreationUtil.getAll5dTestArraysWithShape(12345,4,5,6,7,8));
    list.addAll(NDArrayCreationUtil.getAll6dTestArraysWithShape(12345,4,5,6,7,8,9));


    for(Pair<INDArray,String> p : list){
        int ewsBefore = Shape.elementWiseStride(p.getFirst().shapeInfo());
        INDArray reshapeAttempt = Shape.newShapeNoCopy(p.getFirst(),new int[]{1,p.getFirst().length()}, Nd4j.order() == 'f');

        if (reshapeAttempt != null && ewsBefore == -1 && reshapeAttempt.elementWiseStride() != -1 ) {
            System.out.println("NDArrayCreationUtil." + p.getSecond());
            System.out.println("ews before: " + ewsBefore);
            System.out.println(p.getFirst().shapeInfoToString());
            System.out.println("ews returned by elementWiseStride(): " + p.getFirst().elementWiseStride());
            System.out.println("ews returned by reshape(): " + reshapeAttempt.elementWiseStride());
            System.out.println();
      //      assertTrue(false);
        } else {
      //      System.out.println("FAILED: " + p.getFirst().shapeInfoToString());
        }
    }
}
 
Example 2
Source File: BaseNDArray.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Override
public int elementWiseStride() {
    /*
    if(Shape.elementWiseStride(shapeInfo()) < 0 && !attemptedToFindElementWiseStride) {
        INDArray reshapeAttempt = Shape.newShapeNoCopy(this,new int[]{1,length()}, ordering() == 'f');
        if(reshapeAttempt != null && reshapeAttempt.elementWiseStride() > 0) {
           Shape.setElementWiseStride(shapeInfo(), reshapeAttempt.stride(-1));
           this.shapeInformation = Nd4j.getShapeInfoProvider().createShapeInformation(shape(), stride(), offset(),reshapeAttempt.stride(-1), ordering());
        }
        attemptedToFindElementWiseStride = true;
    
    }
    */
    return Shape.elementWiseStride(shapeInfoDataBuffer());
}
 
Example 3
Source File: TADTests.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testTADEWSStride(){
    INDArray orig = Nd4j.linspace(1, 600, 600).reshape('f', 10, 1, 60);

    for( int i=0; i<60; i++ ){
        INDArray tad = orig.tensorAlongDimension(i, 0, 1);
        //TAD: should be equivalent to get(all, all, point(i))
        INDArray get = orig.get(all(), all(), point(i));

        String str = String.valueOf(i);
        assertEquals(str, get, tad);
        assertEquals(str, get.data().offset(), tad.data().offset());
        assertEquals(str, get.elementWiseStride(), tad.elementWiseStride());

        char orderTad = Shape.getOrder(tad.shape(), tad.stride(), 1);
        char orderGet = Shape.getOrder(get.shape(), get.stride(), 1);

        assertEquals('f', orderTad);
        assertEquals('f', orderGet);

        long ewsTad = Shape.elementWiseStride(tad.shape(), tad.stride(), tad.ordering() == 'f');
        long ewsGet = Shape.elementWiseStride(get.shape(), get.stride(), get.ordering() == 'f');

        assertEquals(1, ewsTad);
        assertEquals(1, ewsGet);
    }
}
 
Example 4
Source File: JvmShapeInfo.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
public JvmShapeInfo(@NonNull long[] javaShapeInformation) {
    this.javaShapeInformation = javaShapeInformation;
    this.shape = Shape.shape(javaShapeInformation);
    this.stride = Shape.stride(javaShapeInformation);
    this.length = Shape.isEmpty(javaShapeInformation) ? 0 : Shape.length(javaShapeInformation);
    this.ews = Shape.elementWiseStride(javaShapeInformation);
    this.extras = Shape.extras(javaShapeInformation);
    this.order = Shape.order(javaShapeInformation);
    this.rank = Shape.rank(javaShapeInformation);
}
 
Example 5
Source File: BaseNDArray.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public BaseNDArray(DataBuffer buffer, long[] shape, long[] stride, long offset, char ordering) {
    this(buffer, shape, stride, offset, Shape.elementWiseStride(shape, stride, ordering == 'f'), ordering);
}
 
Example 6
Source File: BaseNDArray.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public BaseNDArray(DataBuffer buffer, long[] shape, long[] stride, long offset,  char ordering, DataType dataType) {
    this(buffer, shape, stride, offset, Shape.elementWiseStride(shape, stride, ordering == 'f'), ordering, dataType);
}
 
Example 7
Source File: BaseNDArray.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
@Override
public int elementWiseStride() {
    return Shape.elementWiseStride(shapeInfoDataBuffer());
}