@Override public void checkDimensions(INDArray other) { assert Shape.contentEquals(other.shape(), Shape.shapeOf(shapeInformation)) : " Other array should have been shape: " + Shape.toString(Shape.shapeOf(shapeInformation)) + " but was " + Arrays.toString(other.shape()); assert Shape.contentEquals(other.stride(), Shape.stride(shapeInformation)) : " Other array should have been stride: " + Shape.toString(Shape.stride(shapeInformation)) + " but was " + Arrays.toString(other.stride()); assert Shape.offset(javaShapeInformation) == other.offset() : "Offset of this array is " + Shape.offset(javaShapeInformation) + " but other was " + other.offset(); }
@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()); }
@Override public INDArray subArray(ShapeOffsetResolution resolution) { Nd4j.getCompressor().autoDecompress(this); long[] offsets = resolution.getOffsets(); int[] shape = LongUtils.toInts(resolution.getShapes()); int[] stride = LongUtils.toInts(resolution.getStrides()); // if (offset() + resolution.getOffset() >= Integer.MAX_VALUE) // throw new IllegalArgumentException("Offset of array can not be >= Integer.MAX_VALUE"); long offset = (offset() + resolution.getOffset()); 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.length == rank() && Shape.contentEquals(shape, shapeOf())) { if (ArrayUtil.isZero(offsets)) { return this; } else { throw new IllegalArgumentException("Invalid subArray offsets"); } } char newOrder = Shape.getOrder(shape, stride, 1); return create(data, Arrays.copyOf(shape, shape.length), stride, offset, newOrder); }
@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)); }
@Override public void checkDimensions(INDArray other) { assert Shape.contentEquals(other.shape(), Shape.shapeOf(shapeInformation)) : " Other array should have been shape: " + Shape.toString(Shape.shapeOf(shapeInformation)) + " but was " + Arrays.toString(other.shape()); assert Shape.contentEquals(other.stride(), Shape.stride(shapeInformation)) : " Other array should have been stride: " + Shape.toString(Shape.stride(shapeInformation)) + " but was " + Arrays.toString(other.stride()); assert Shape.offset(javaShapeInformation) == other.offset() : "Offset of this array is " + Shape.offset(javaShapeInformation) + " but other was " + other.offset(); }
@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()); }
throw new IllegalArgumentException("Invalid stride " + Arrays.toString(stride)); if (shape.length == rank() && Shape.contentEquals(shape, shapeOf())) { if (ArrayUtil.isZero(offsets)) { return this;