private long [ ] createSparseOffsets ( long offset ) { // resolve the offsets in the view dimension int underlyingRank = sparseOffsets ( ) . length ; long [ ] newOffsets = new long [ rank ( ) ] ; List < Long > shapeList = Longs . asList ( shape ( ) ) ; int penultimate = rank ( ) - 1 ; for ( int i = 0 ; i < penultimate ; i ++ ) { long prod = ArrayUtil . prodLong ( shapeList . subList ( i + 1 , rank ( ) ) ) ; newOffsets [ i ] = offset / prod ; offset = offset - newOffsets [ i ] * prod ; } newOffsets [ rank ( ) - 1 ] = offset % shape ( ) [ rank ( ) - 1 ] ; // Merge the offsets with the original sparseOffsets long [ ] finalOffsets = new long [ underlyingRank ] ; int dimNotFixed = 0 ; for ( int dim = 0 ; dim < underlyingRank ; dim ++ ) { if ( flags ( ) [ dim ] == 1 ) { finalOffsets [ dim ] = sparseOffsets ( ) [ dim ] ; } else { finalOffsets [ dim ] = newOffsets [ dimNotFixed ] + sparseOffsets ( ) [ dim ] ; dimNotFixed ++ ; } } return finalOffsets ; }
Compute the sparse offsets of the view we are getting for each dimension according to the original ndarray