/** * Return if the dimension in argument is a fixed dimension. * */ public boolean isDimensionFixed(int i) { return flags()[i] == 1; }
int[] idx = getUnderlyingIndicesOf(i).asInt(); for (int dim = 0; dim < idx.length; dim++) { if (flags()[dim] == 1) { if (sparseOffsets()[dim] != idx[dim]) { isIn = false;
/** * Count the number of value that are included in the ndarray (view) according to the sparse offsets and the shape * @return nnz * */ public long countNNZ() { long count = 0; for (int i = 0; i < values.length(); i++) { int[] idx = getUnderlyingIndicesOf(i).asInt(); boolean isIn = true; int idxNotFixed = 0; for (int dim = 0; dim < idx.length; dim++) { if (flags()[dim] == 1) { if (sparseOffsets()[dim] != idx[dim]) { isIn = false; break; } } else { int lowerBound = sparseOffsets()[dim]; long upperBound = sparseOffsets()[dim] + shape()[idxNotFixed]; if (!(idx[dim] >= lowerBound && idx[dim] < upperBound)) { isIn = false; break; } idxNotFixed++; } } count = isIn ? count + 1 : count; } return count; }
/** * Compute the sparse offsets of the view we are getting, for each dimension according to the original ndarray * @param offset the offset of the view * @return an int array containing the sparse offsets * */ 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; }