/** * Returns the underlying indices of the element of the given index * such as there really are in the original ndarray * * @param i the index of the element+ * @return a dataBuffer containing the indices of element * */ public DataBuffer getUnderlyingIndicesOf(int i) { int from = underlyingRank() * i; //int to = from + underlyingRank(); int[] res = new int[underlyingRank()]; for(int j = 0; j< underlyingRank(); j++){ res[j] = indices.getInt(from + j); } ///int[] arr = Arrays.copyOfRange(indices.asInt(), from, to); return Nd4j.getDataBufferFactory().createInt(res); }
int[] extendedFlags = new int[underlyingRank()]; int notFixedDim = 0; for (int dim = 0; dim < underlyingRank(); dim++) { int[] temp = flags(); if (flags()[dim] == 0) {
public int[] translateToPhysical(int[] virtualIndexes) { int[] physicalIndexes = new int[underlyingRank()]; int idxPhy = 0; int hidden = 0; for (int idxVir = 0; idxVir < virtualIndexes.length; idxVir++) { if (hidden < getNumHiddenDimension() && hiddenDimensions()[hidden] == idxVir) { hidden++; } else { while (idxPhy < underlyingRank() && isDimensionFixed(idxPhy)) { physicalIndexes[idxPhy] = sparseOffsets()[idxPhy]; idxPhy++; } if (idxPhy < underlyingRank() && !isDimensionFixed(idxPhy)) { physicalIndexes[idxPhy] = sparseOffsets()[idxPhy] + virtualIndexes[idxVir]; idxPhy++; } } } return physicalIndexes; }
/** * Translate the view index to the corresponding index of the original ndarray * @param virtualIndexes the view indexes * @return the original indexes * */ public long[] translateToPhysical(long[] virtualIndexes) { long[] physicalIndexes = new long[underlyingRank()]; int idxPhy = 0; int hidden = 0; for (int idxVir = 0; idxVir < virtualIndexes.length; idxVir++) { if (hidden < getNumHiddenDimension() && hiddenDimensions()[hidden] == idxVir) { hidden++; } else { while (idxPhy < underlyingRank() && isDimensionFixed(idxPhy)) { physicalIndexes[idxPhy] = sparseOffsets()[idxPhy]; idxPhy++; } if (idxPhy < underlyingRank() && !isDimensionFixed(idxPhy)) { physicalIndexes[idxPhy] = sparseOffsets()[idxPhy] + virtualIndexes[idxVir]; idxPhy++; } } } return physicalIndexes; }
/** * Returns the indices of the element of the given index in the array context * * @param i the index of the element * @return a dataBuffer containing the indices of element * */ public DataBuffer getIndicesOf(int i) { int from = underlyingRank() * i; int to = from + underlyingRank(); //not included int[] arr = new int[rank]; int j = 0; // iterator over underlying indices int k = 0; //iterator over hiddenIdx for (int dim = 0; dim < rank; dim++) { if (k < hiddenDimensions().length && hiddenDimensions()[k] == j) { arr[dim] = 0; k++; } else { arr[dim] = indices.getInt(j); j++; } } return Nd4j.getDataBufferFactory().createInt(arr); }
@Override public INDArray subArray(ShapeOffsetResolution resolution) { long[] offsets = resolution.getOffsets(); int[] shape = LongUtils.toInts(resolution.getShapes()); int[] stride = LongUtils.toInts(resolution.getStrides()); int[] flags = resolution.getFixed(); flags = updateFlags(flags, shape); long offset = (int) (offset() + resolution.getOffset()); int newRank = shape.length; long[] sparseOffsets = createSparseOffsets(offset); int[] newAxis = createHiddenDimensions(resolution.getPrependAxis()); if (offset() + resolution.getOffset() >= Integer.MAX_VALUE) throw new IllegalArgumentException("Offset of array can not be >= Integer.MAX_VALUE"); if (offsets.length != newRank) throw new IllegalArgumentException("Invalid offset " + Arrays.toString(offsets)); if (stride.length != newRank) throw new IllegalArgumentException("Invalid stride " + Arrays.toString(stride)); if (shape.length == rank() && Shape.contentEquals(shape, shapeOf())) { if (ArrayUtil.isZero(offsets)) { return this; } else { throw new IllegalArgumentException("Invalid subArray offsets"); } } DataBuffer newSparseInformation = Nd4j.getSparseInfoProvider().createSparseInformation(flags, sparseOffsets, newAxis, underlyingRank()); return create(values, indices, newSparseInformation, Arrays.copyOf(shape, shape.length)); }