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

The following examples show how to use org.nd4j.linalg.factory.Nd4j#createSparseCSR() . 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: SparseNDArrayCSRTest.java    From nd4j with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReallocate() {
    INDArray sparseNDArray = Nd4j.createSparseCSR(values, columns, pointerB, pointerE, shape);
    if (sparseNDArray instanceof BaseSparseNDArrayCSR) {
        BaseSparseNDArrayCSR sparseCSRArray = (BaseSparseNDArrayCSR) sparseNDArray;
        int initialSize = sparseCSRArray.getDoubleValues().length;

        for (int i = 0; i < shape[0]; i++) {
            for (int j = 0; j < shape[1]; j++) {
                sparseCSRArray.putScalar(i, j, i + j);
            }
        }
        int finalSize = sparseCSRArray.getDoubleValues().length;
        assert (finalSize > initialSize);
    }

}
 
Example 2
Source File: SparseCOOLevel1Test.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldComputeRotWithFullVector() {

    // try with dense vectors to get the expected result
    /*
        INDArray temp1 = Nd4j.create( new double[] {1 ,2, 3, 4});
        INDArray temp2 = Nd4j.create( new double[] {1 ,2, 3, 4});
        System.out.println("before: " + temp1.data() + " " + temp2.data());
        Nd4j.getBlasWrapper().level1().rot(temp1.length(), temp1, temp2, 1, 2);
        System.out.println("after: " + temp1.data() + " " + temp2.data());
    */
    //before: [1.0,2.0,3.0,4.0]  [1.0,2.0,3.0,4.0]
    // after: [3.0,6.0,0.0,12.0] [-1.0,-2.0,-3.0,-4.0]

    int[] cols = {0, 1, 2, 3};
    double[] values = {1, 2, 3, 4};
    INDArray sparseVec = Nd4j.createSparseCOO(data, indexes, shape);
    INDArray vec = Nd4j.create(new double[] {1, 2, 3, 4});
    Nd4j.getBlasWrapper().level1().rot(vec.length(), sparseVec, vec, 1, 2);

    INDArray expectedSparseVec = Nd4j.createSparseCSR(new double[] {3, 6, 9, 12}, new int[] {0, 1, 2, 3},
                    new int[] {0}, new int[] {4}, new int[] {1, 4});
    INDArray expectedVec = Nd4j.create(new double[] {-1, -2, -3, -4});
    assertEquals(getFailureMessage(), expectedSparseVec.data(), sparseVec.data());
    assertEquals(getFailureMessage(), expectedVec, vec);
    if (expectedSparseVec.isSparse() && sparseVec.isSparse()) {
        BaseSparseNDArray vec2 = ((BaseSparseNDArray) expectedSparseVec);
        BaseSparseNDArray vecSparse2 = ((BaseSparseNDArray) sparseVec);
        assertEquals(getFailureMessage(), vec2.getVectorCoordinates(), vecSparse2);
    }
}
 
Example 3
Source File: SparseNDArrayCSRTest.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReplaceValueAtAGivenPosition() {
    /*
    * [[1 -1 0 -3 0]
    *  [-2 4 0 0 0 ]
    *  [ 0 0 10 6 4] = A'
    *  [-4 0 2 7 0 ]
    *  [ 0 8 0 0 -5]]
    * */
    INDArray sparseNDArray = Nd4j.createSparseCSR(values, columns, pointerB, pointerE, shape);
    if (sparseNDArray instanceof BaseSparseNDArrayCSR) {
        BaseSparseNDArrayCSR sparseCSRArray = (BaseSparseNDArrayCSR) sparseNDArray;
        sparseCSRArray.putScalar(2, 2, 10);

        double[] expectedValues = {1, -2, -3, -2, 5, 10, 6, 4, -4, 2, 7, 8, -5};
        double[] expectedColumns = {0, 1, 3, 0, 1, 2, 3, 4, 0, 2, 3, 1, 4};
        int[] expectedPointerB = {0, 3, 5, 8, 11};
        int[] expectedPointerE = {3, 5, 8, 11, 13};
        int[] expectedShape = {5, 5};

        assertArrayEquals(expectedValues, sparseCSRArray.getDoubleValues(), 0);
        assertArrayEquals(expectedColumns, sparseCSRArray.getColumns(), 0);
        assertArrayEquals(expectedPointerB, sparseCSRArray.getPointerBArray());
        assertArrayEquals(expectedPointerE, sparseCSRArray.getPointerEArray());
        assertArrayEquals(expectedShape, shape);
    }
}
 
Example 4
Source File: SparseNDArrayCSRTest.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldAddValueAtAGivenPosition() {
    /*
    * [[1 -1 0 -3 0]
    *  [-2 4 0 0 0 ]
    *  [ 0 3 4 6 4 ] = A'
    *  [-4 0 2 7 0 ]
    *  [ 0 8 0 0 -5]]
    * */
    INDArray sparseNDArray = Nd4j.createSparseCSR(values, columns, pointerB, pointerE, shape);
    if (sparseNDArray instanceof BaseSparseNDArrayCSR) {
        BaseSparseNDArrayCSR sparseCSRArray = (BaseSparseNDArrayCSR) sparseNDArray;
        sparseCSRArray.putScalar(2, 1, 3);

        double[] expectedValues = {1, -2, -3, -2, 5, 3, 4, 6, 4, -4, 2, 7, 8, -5};
        double[] expectedColumns = {0, 1, 3, 0, 1, 1, 2, 3, 4, 0, 2, 3, 1, 4};
        int[] expectedPointerB = {0, 3, 5, 9, 12};
        int[] expectedPointerE = {3, 5, 9, 12, 14};
        int[] expectedShape = {5, 5};


        assertArrayEquals(expectedValues, sparseCSRArray.getDoubleValues(), 0);
        assertArrayEquals(expectedColumns, sparseCSRArray.getColumns(), 0);
        assertArrayEquals(expectedPointerB, sparseCSRArray.getPointerBArray());
        assertArrayEquals(expectedPointerE, sparseCSRArray.getPointerEArray());
        assertArrayEquals(expectedShape, shape);
    }
}
 
Example 5
Source File: SparseCSRLevel1Test.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldComputeRotWithFullVector() {

    // try with dense vectors to get the expected result
    /*
        INDArray temp1 = Nd4j.create( new double[] {1 ,2, 3, 4});
        INDArray temp2 = Nd4j.create( new double[] {1 ,2, 3, 4});
        System.out.println("before: " + temp1.data() + " " + temp2.data());
        Nd4j.getBlasWrapper().level1().rot(temp1.length(), temp1, temp2, 1, 2);
        System.out.println("after: " + temp1.data() + " " + temp2.data());
    */
    //before: [1.0,2.0,3.0,4.0]  [1.0,2.0,3.0,4.0]
    // after: [3.0,6.0,0.0,12.0] [-1.0,-2.0,-3.0,-4.0]

    int[] cols = {0, 1, 2, 3};
    double[] values = {1, 2, 3, 4};
    INDArray sparseVec = Nd4j.createSparseCSR(values, cols, pointerB, pointerE, shape);
    INDArray vec = Nd4j.create(new double[] {1, 2, 3, 4});
    Nd4j.getBlasWrapper().level1().rot(vec.length(), sparseVec, vec, 1, 2);

    INDArray expectedSparseVec = Nd4j.createSparseCSR(new double[] {3, 6, 9, 12}, new int[] {0, 1, 2, 3},
                    new int[] {0}, new int[] {4}, new int[] {1, 4});
    INDArray expectedVec = Nd4j.create(new double[] {-1, -2, -3, -4});
    assertEquals(getFailureMessage(), expectedSparseVec.data(), sparseVec.data());
    assertEquals(getFailureMessage(), expectedVec, vec);
    if (expectedSparseVec.isSparse() && sparseVec.isSparse()) {
        BaseSparseNDArray vec2 = ((BaseSparseNDArray) expectedSparseVec);
        BaseSparseNDArray vecSparse2 = ((BaseSparseNDArray) sparseVec);
        assertEquals(getFailureMessage(), vec2.getVectorCoordinates(), vecSparse2);
    }
}
 
Example 6
Source File: SparseCSRLevel1Test.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldComputeRot() {

    // try with dense vectors to get the expected result

    INDArray temp1 = Nd4j.create(new double[] {1, 2, 0, 4});
    INDArray temp2 = Nd4j.create(new double[] {1, 2, 3, 4});
    System.out.println("before: " + temp1.data() + " " + temp2.data());
    Nd4j.getBlasWrapper().level1().rot(temp1.length(), temp1, temp2, 1, 2);
    System.out.println("after: " + temp1.data() + " " + temp2.data());

    //before: [1.0,2.0,0.0,4.0]  [1.0,2.0,3.0,4.0]
    // after: [3.0,6.0,6.0,12.0] [-1.0,-2.0,3.0,-4.0]

    INDArray sparseVec = Nd4j.createSparseCSR(data, col, pointerB, pointerE, shape);
    INDArray vec = Nd4j.create(new double[] {1, 2, 3, 4});
    Nd4j.getBlasWrapper().level1().rot(vec.length(), sparseVec, vec, 1, 2);
    System.out.println(sparseVec.data() + " " + vec.data());

    //System.out.println("indexes: " + ((BaseSparseNDArray) sparseVec).getVectorCoordinates().toString());
    INDArray expectedSparseVec = Nd4j.createSparseCSR(new double[] {3, 6, 6, 12}, new int[] {0, 1, 2, 3},
                    new int[] {0}, new int[] {4}, new int[] {1, 4});
    INDArray expectedVec = Nd4j.create(new double[] {-1, -2, 3, -4});
    assertEquals(getFailureMessage(), expectedSparseVec.data(), sparseVec.data());

    assertEquals(getFailureMessage(), expectedVec, vec);
    // TODO fix it
}
 
Example 7
Source File: SparseCSRLevel1Test.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldComputeAxpy() {
    INDArray sparseVec = Nd4j.createSparseCSR(data, col, pointerB, pointerE, shape);
    INDArray vec = Nd4j.create(new double[] {1, 2, 3, 4});
    INDArray expected = Nd4j.create(new double[] {2, 4, 3, 8});
    Nd4j.getBlasWrapper().level1().axpy(vec.length(), 1, sparseVec, vec);
    assertEquals(getFailureMessage(), expected, vec);
}
 
Example 8
Source File: SparseCSRLevel1Test.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldComputeDot() {
    INDArray sparseVec = Nd4j.createSparseCSR(data, col, pointerB, pointerE, shape);
    //INDArray vec = Nd4j.create( new double[] {1 ,2, 3, 4});
    INDArray matrix = Nd4j.linspace(1, 4, 4).reshape(1, 4);
    INDArray vec = matrix.getRow(0);
    assertEquals(21, Nd4j.getBlasWrapper().dot(sparseVec, vec), 1e-1);
}
 
Example 9
Source File: SparseCOOLevel1Test.java    From nd4j with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldComputeRot() {

    // try with dense vectors to get the expected result

    INDArray temp1 = Nd4j.create(new double[] {1, 2, 0, 4});
    INDArray temp2 = Nd4j.create(new double[] {1, 2, 3, 4});
    System.out.println("before: " + temp1.data() + " " + temp2.data());
    Nd4j.getBlasWrapper().level1().rot(temp1.length(), temp1, temp2, 1, 2);
    System.out.println("after: " + temp1.data() + " " + temp2.data());

    //before: [1.0,2.0,0.0,4.0]  [1.0,2.0,3.0,4.0]
    // after: [3.0,6.0,6.0,12.0] [-1.0,-2.0,3.0,-4.0]

    INDArray sparseVec = Nd4j.createSparseCOO(data, indexes, shape);
    INDArray vec = Nd4j.create(new double[] {1, 2, 3, 4});
    Nd4j.getBlasWrapper().level1().rot(vec.length(), sparseVec, vec, 1, 2);
    System.out.println(sparseVec.data() + " " + vec.data());

    //System.out.println("indexes: " + ((BaseSparseNDArray) sparseVec).getVectorCoordinates().toString());
    INDArray expectedSparseVec = Nd4j.createSparseCSR(new double[] {3, 6, 6, 12}, new int[] {0, 1, 2, 3},
                    new int[] {0}, new int[] {4}, new int[] {1, 4});
    INDArray expectedVec = Nd4j.create(new double[] {-1, -2, 3, -4});
    assertEquals(getFailureMessage(), expectedSparseVec.data(), sparseVec.data());

    assertEquals(getFailureMessage(), expectedVec, vec);
    // TODO FIXME
}
 
Example 10
Source File: SparseCSRLevel1Test.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldComputeIamin() {
    INDArray sparseVec = Nd4j.createSparseCSR(data, col, pointerB, pointerE, shape);
    assertEquals(0, Nd4j.getBlasWrapper().level1().iamin(sparseVec), 1e-1);
}
 
Example 11
Source File: SparseCSRLevel1Test.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldComputeIamax() {
    INDArray sparseVec = Nd4j.createSparseCSR(data, col, pointerB, pointerE, shape);
    assertEquals(2, Nd4j.getBlasWrapper().iamax(sparseVec), 1e-1);
}
 
Example 12
Source File: SparseCSRLevel1Test.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldComputeAsum() {
    INDArray sparseVec = Nd4j.createSparseCSR(data, col, pointerB, pointerE, shape);
    assertEquals(7, Nd4j.getBlasWrapper().asum(sparseVec), 1e-1);
}
 
Example 13
Source File: SparseNDArrayCSRTest.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldCreateSparseMatrix() {
    INDArray matrix = Nd4j.createSparseCSR(values, columns, pointerB, pointerE, shape);
    //TODO
}
 
Example 14
Source File: SparseCSRLevel1Test.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldComputeNrm2() {
    INDArray sparseVec = Nd4j.createSparseCSR(data, col, pointerB, pointerE, shape);
    assertEquals(Math.sqrt(21), Nd4j.getBlasWrapper().nrm2(sparseVec), 1e-1);
}
 
Example 15
Source File: SparseNDArrayCSRTest.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldGetAView() {

    double[] values = {1, -1, -3, -2, 5, 4, 6, 4, -4, 2, 7, 8, 5};
    int[] columns = {0, 1, 3, 0, 1, 2, 3, 4, 0, 2, 3, 1, 4};
    int[] pointerB = {0, 3, 5, 8, 11};
    int[] pointerE = {3, 5, 8, 11, 13};

    // Test with dense ndarray
    double[] data = {1, -1, 0, -3, 0, -2, 5, 0, 0, 0, 0, 0, 4, 6, 4, -4, 0, 2, 7, 0, 0, 8, 0, 0, 5};
    INDArray array = Nd4j.create(data, new int[] {5, 5}, 0, 'c');
    INDArray denseView = array.get(NDArrayIndex.interval(1, 3), NDArrayIndex.interval(1, 3));

    // test with sparse :
    INDArray sparseNDArray = Nd4j.createSparseCSR(values, columns, pointerB, pointerE, shape);

    // subarray in the top right corner
    BaseSparseNDArrayCSR sparseView = (BaseSparseNDArrayCSR) sparseNDArray.get(NDArrayIndex.interval(0, 3),
                    NDArrayIndex.interval(3, 5));
    assertArrayEquals(new int[] {0, 0, 1}, sparseView.getVectorCoordinates().asInt());
    assertArrayEquals(new int[] {2, 3, 6}, sparseView.getPointerBArray());
    assertArrayEquals(new int[] {3, 3, 8}, sparseView.getPointerEArray());

    // subarray in the middle
    sparseView = (BaseSparseNDArrayCSR) sparseNDArray.get(NDArrayIndex.interval(1, 3), NDArrayIndex.interval(1, 3));
    assertArrayEquals(new int[] {0, 1}, sparseView.getVectorCoordinates().asInt());
    assertArrayEquals(new int[] {4, 5}, sparseView.getPointerBArray());
    assertArrayEquals(new int[] {5, 6}, sparseView.getPointerEArray());

    // get the first row
    sparseView = (BaseSparseNDArrayCSR) sparseNDArray.get(NDArrayIndex.all(), NDArrayIndex.point(0));
    assertArrayEquals(new int[] {0, 0, 0}, sparseView.getVectorCoordinates().asInt());
    assertArrayEquals(new int[] {0, 3, 4, 8, 9}, sparseView.getPointerBArray());
    assertArrayEquals(new int[] {1, 4, 4, 9, 9}, sparseView.getPointerEArray());

    // get several rows
    sparseView = (BaseSparseNDArrayCSR) sparseNDArray.get(NDArrayIndex.interval(0, 2), NDArrayIndex.all());
    assertArrayEquals(new int[] {0, 1, 3, 0, 1}, sparseView.getVectorCoordinates().asInt());
    assertArrayEquals(new int[] {0, 3}, sparseView.getPointerBArray());
    assertArrayEquals(new int[] {3, 5}, sparseView.getPointerEArray());

    // get a row in the middle
    sparseView = (BaseSparseNDArrayCSR) sparseNDArray.get(NDArrayIndex.point(2), NDArrayIndex.all());
    assertArrayEquals(new int[] {2, 3, 4}, sparseView.getVectorCoordinates().asInt());
    assertArrayEquals(new int[] {5}, sparseView.getPointerBArray());
    assertArrayEquals(new int[] {8}, sparseView.getPointerEArray());

    // get the first column
    sparseView = (BaseSparseNDArrayCSR) sparseNDArray.get(NDArrayIndex.all(), NDArrayIndex.point(0));
    assertArrayEquals(new int[] {0, 0, 0}, sparseView.getVectorCoordinates().asInt());
    assertArrayEquals(new int[] {0, 3, 4, 8, 9}, sparseView.getPointerBArray());
    assertArrayEquals(new int[] {1, 4, 4, 9, 9}, sparseView.getPointerEArray());

    // get a column in the middle
    sparseView = (BaseSparseNDArrayCSR) sparseNDArray.get(NDArrayIndex.all(), NDArrayIndex.point(2));
    assertArrayEquals(new int[] {0, 0}, sparseView.getVectorCoordinates().asInt());
    assertArrayEquals(new int[] {0, 0, 5, 9, 10}, sparseView.getPointerBArray());
    assertArrayEquals(new int[] {0, 0, 6, 10, 10}, sparseView.getPointerEArray());

    // get a part of the column in the middle
    sparseView = (BaseSparseNDArrayCSR) sparseNDArray.get(NDArrayIndex.interval(1, 4), NDArrayIndex.point(2));
    assertArrayEquals(new int[] {0, 0}, sparseView.getVectorCoordinates().asInt());
    assertArrayEquals(new int[] {0, 5, 9}, sparseView.getPointerBArray());
    assertArrayEquals(new int[] {0, 6, 10}, sparseView.getPointerEArray());


}
 
Example 16
Source File: SparseNDArrayCSRTest.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldGetAViewFromView() {
    double[] values = {1, -1, -3, -2, 5, 4, 6, 4, -4, 2, 7, 8, 5};
    int[] columns = {0, 1, 3, 0, 1, 2, 3, 4, 0, 2, 3, 1, 4};
    int[] pointerB = {0, 3, 5, 8, 11};

    INDArray sparseNDArray = Nd4j.createSparseCSR(values, columns, pointerB, pointerE, shape);
    /*             [0, -3, 0]
    * sparseView = [0,  0, 0] subview = [[0,0], [4,6]]
    *              [4,  6, 4]
    */
    BaseSparseNDArrayCSR sparseView = (BaseSparseNDArrayCSR) sparseNDArray.get(NDArrayIndex.interval(0, 3),
                    NDArrayIndex.interval(2, 5));
    BaseSparseNDArrayCSR subview =
                    (BaseSparseNDArrayCSR) sparseView.get(NDArrayIndex.interval(1, 3), NDArrayIndex.interval(0, 2));
    assertArrayEquals(new int[] {0, 1}, subview.getVectorCoordinates().asInt());
    assertArrayEquals(new int[] {0, 5}, subview.getPointerBArray());
    assertArrayEquals(new int[] {0, 7}, subview.getPointerEArray());

    // get the first column
    subview = (BaseSparseNDArrayCSR) sparseView.get(NDArrayIndex.all(), NDArrayIndex.point(0));
    assertArrayEquals(new int[] {0}, subview.getVectorCoordinates().asInt());
    assertArrayEquals(new int[] {0, 0, 5}, subview.getPointerBArray());
    assertArrayEquals(new int[] {0, 0, 6}, subview.getPointerEArray());

    // get a column in the middle
    subview = (BaseSparseNDArrayCSR) sparseView.get(NDArrayIndex.all(), NDArrayIndex.point(1));
    assertArrayEquals(new int[] {0, 0}, subview.getVectorCoordinates().asInt());
    assertArrayEquals(new int[] {2, 3, 6}, subview.getPointerBArray());
    assertArrayEquals(new int[] {3, 3, 7}, subview.getPointerEArray());

    // get the first row
    subview = (BaseSparseNDArrayCSR) sparseView.get(NDArrayIndex.point(0), NDArrayIndex.all());
    assertArrayEquals(new int[] {1}, subview.getVectorCoordinates().asInt());
    assertArrayEquals(new int[] {2}, subview.getPointerBArray());
    assertArrayEquals(new int[] {3}, subview.getPointerEArray());

    // get a row in the middle
    subview = (BaseSparseNDArrayCSR) sparseView.get(NDArrayIndex.point(1), NDArrayIndex.all());
    assertArrayEquals(new int[] {}, subview.getVectorCoordinates().asInt());
    assertArrayEquals(new int[] {0}, subview.getPointerBArray());
    assertArrayEquals(new int[] {0}, subview.getPointerEArray());
}
 
Example 17
Source File: BaseSparseNDArrayCSR.java    From nd4j with Apache License 2.0 4 votes vote down vote up
@Override
public INDArray subArray(ShapeOffsetResolution resolution) {

    long[] offsets = resolution.getOffsets();
    int[] shape = LongUtils.toInts(resolution.getShapes());


    List<Integer> accuColumns = new ArrayList<>();
    List<Integer> accuPointerB = new ArrayList<>();
    List<Integer> accuPointerE = new ArrayList<>();

    if (shape.length == 2) {

        if (resolution.getOffset() != 0) {
            offsets[0] = (int) resolution.getOffset() / shape()[1];
            offsets[1] = (int) resolution.getOffset() % shape()[1];
        }
        long firstRow = offsets[0];
        long lastRow = firstRow + shape[0];
        long firstElement = offsets[1];
        long lastElement = firstElement + shape[1];

        int count = 0;
        int i = 0;
        for (int rowIdx = 0; rowIdx < lastRow; rowIdx++) {

            boolean isFirstInRow = true;
            for (int idx = pointerB.getInt(rowIdx); idx < pointerE.getInt(rowIdx); idx++) {

                int colIdx = columnsPointers.getInt(count);

                // add the element in the subarray it it belongs to the view
                if (colIdx >= firstElement && colIdx < lastElement && rowIdx >= firstRow && rowIdx < lastRow) {

                    // add the new column pointer for this element
                    accuColumns.add((int) (colIdx - firstElement));

                    if (isFirstInRow) {
                        // Add the index of the first element of the row in the pointer array
                        accuPointerB.add(idx);
                        accuPointerE.add(idx + 1);
                        isFirstInRow = false;
                    } else {
                        // update the last element pointer array
                        accuPointerE.set((int) (rowIdx - firstRow), idx + 1);
                    }
                }
                count++;
            }

            // If the row doesn't contain any element and is included in the selected rows
            if (isFirstInRow && rowIdx >= firstRow && rowIdx < lastRow) {
                int lastIdx = i == 0 ? 0 : accuPointerE.get(i - 1);
                accuPointerB.add(lastIdx);
                accuPointerE.add(lastIdx);
            }
            if (rowIdx >= firstRow && rowIdx <= lastRow) {
                i++;
            }
        }

        int[] newColumns = Ints.toArray(accuColumns);
        int[] newPointerB = Ints.toArray(accuPointerB);
        int[] newPointerE = Ints.toArray(accuPointerE);

        INDArray subarray = Nd4j.createSparseCSR(values, newColumns, newPointerB, newPointerE, shape);

        return subarray;

    } else {
        throw new UnsupportedOperationException();
    }
}