Java Code Examples for org.nd4j.linalg.api.shape.Shape#offset()
The following examples show how to use
org.nd4j.linalg.api.shape.Shape#offset() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseNDArray.java From nd4j with Apache License 2.0 | 5 votes |
@Override public boolean isView() { /* We don't really use Shape offset value anywhere And it's possible to be not a view, and have non-empty originalBuffer */ // length/data.length can be different in case of Threshold conversion return Shape.offset(javaShapeInformation) > 0 || (length() < data().length() && data.dataType() != DataBuffer.Type.INT) || data().originalDataBuffer() != null; }
Example 2
Source File: BaseNDArray.java From nd4j with Apache License 2.0 | 5 votes |
@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()); }
Example 3
Source File: BaseNDArray.java From nd4j with Apache License 2.0 | 5 votes |
@Override @Deprecated public long linearIndex(long i) { long idx = i; for (int j = 0; j < Shape.rank(javaShapeInformation) - 1; j++) { if (size((int) i) == 1) continue; idx += i * stride(j); } return Shape.offset(javaShapeInformation) + (idx); }
Example 4
Source File: BaseNDArray.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override @Deprecated //TODO: Investigate. Not deprecated in the base interface. public long linearIndex(long i) { long idx = i; for (int j = 0; j < jvmShapeInfo.rank - 1; j++) { if (size((int) i) == 1) continue; idx += i * stride(j); } return Shape.offset(jvmShapeInfo.javaShapeInformation) + (idx); }
Example 5
Source File: BaseSparseNDArrayCOO.java From nd4j with Apache License 2.0 | 4 votes |
@Override public boolean isView() { return Shape.offset(shapeInformation) > 0 || data().originalDataBuffer() != null; // TODO or if sparseOffset/flags != [0, ..,0] }