/** * Compute the offset given an array of offsets. * The offset is computed(for both fortran an d c ordering) as: * sum from i to n - 1 o[i] * s[i] * where i is the index o is the offset and s is the stride * Notice the -1 at the end. * @param arr the array to compute the offset for * @param offsets the offsets for each dimension * @return the offset that should be used for indexing */ public static long offset(INDArray arr, long... offsets) { return offset(arr.stride(), offsets); }
/** * Compute the offset given an array of offsets. * The offset is computed(for both fortran an d c ordering) as: * sum from i to n - 1 o[i] * s[i] * where i is the index o is the offset and s is the stride * Notice the -1 at the end. * @param arr the array to compute the offset for * @param indices the offsets for each dimension * @return the offset that should be used for indexing */ public static long offset(INDArray arr, INDArrayIndex... indices) { return offset(arr.stride(), Indices.offsets(arr.shape(), indices)); }
@Override public INDArray subArray(long[] offsets, int[] shape, int[] stride) { Nd4j.getCompressor().autoDecompress(this); int n = shape.length; // FIXME: shapeInfo should be used here if (shape.length < 1) return create(Nd4j.createBufferDetached(shape)); if (offsets.length != n) throw new IllegalArgumentException("Invalid offset " + Arrays.toString(offsets)); if (stride.length != n) throw new IllegalArgumentException("Invalid stride " + Arrays.toString(stride)); if (Shape.contentEquals(shape, shapeOf())) { if (ArrayUtil.isZero(offsets)) { return this; } else { throw new IllegalArgumentException("Invalid subArray offsets"); } } long[] dotProductOffsets = offsets; int[] dotProductStride = stride; long offset = Shape.offset(javaShapeInformation) + NDArrayIndex.offset(dotProductStride, dotProductOffsets); if (offset >= data().length()) offset = ArrayUtil.sumLong(offsets); return create(data, Arrays.copyOf(shape, shape.length), stride, offset, ordering()); }
/** * Compute the offset given an array of offsets. * The offset is computed(for both fortran an d c ordering) as: * sum from i to n - 1 o[i] * s[i] * where i is the index o is the offset and s is the stride * Notice the -1 at the end. * @param arr the array to compute the offset for * @param offsets the offsets for each dimension * @return the offset that should be used for indexing */ public static int offset(INDArray arr, int... offsets) { return offset(arr.stride(), offsets); }
/** * Compute the offset given an array of offsets. * The offset is computed(for both fortran an d c ordering) as: * sum from i to n - 1 o[i] * s[i] * where i is the index o is the offset and s is the stride * Notice the -1 at the end. * @param arr the array to compute the offset for * @param indices the offsets for each dimension * @return the offset that should be used for indexing */ public static long offset(INDArray arr, INDArrayIndex... indices) { return offset(arr.stride(), Indices.offsets(arr.shape(), indices)); }
@Override public INDArray subArray(long[] offsets, int[] shape, int[] stride) { Nd4j.getCompressor().autoDecompress(this); int n = shape.length; // FIXME: shapeInfo should be used here if (shape.length < 1) return create(Nd4j.createBufferDetached(shape)); if (offsets.length != n) throw new IllegalArgumentException("Invalid offset " + Arrays.toString(offsets)); if (stride.length != n) throw new IllegalArgumentException("Invalid stride " + Arrays.toString(stride)); if (Shape.contentEquals(shape, shapeOf())) { if (ArrayUtil.isZero(offsets)) { return this; } else { throw new IllegalArgumentException("Invalid subArray offsets"); } } long[] dotProductOffsets = offsets; int[] dotProductStride = stride; long offset = Shape.offset(javaShapeInformation) + NDArrayIndex.offset(dotProductStride, dotProductOffsets); if (offset >= data().length()) offset = ArrayUtil.sumLong(offsets); return create(data, Arrays.copyOf(shape, shape.length), stride, offset, ordering()); }