@Override public INDArray putScalarUnsafe(long offset, double value) { autoProcessScalarCall(); data().put(offset, value); return this; }
@Override public INDArray putScalar(long row, long col, double value) { Nd4j.getCompressor().autoDecompress(this); autoProcessScalarCall(); if (rank() > 2) throw new IllegalStateException("Cannot use putScalar(int,int,double) on a rank " + rank() + " INDArray"); long offset = Shape.getOffsetUnsafe(javaShapeInformation, row, col); data.put(offset, value); return this; }
@Override public INDArray putScalar(long dim0, long dim1, long dim2, long dim3, double value) { Nd4j.getCompressor().autoDecompress(this); autoProcessScalarCall(); if (rank() != 4) throw new IllegalStateException( "Cannot use putScalar(int,int,int,int,double) on a rank " + rank() + " INDArray"); long offset = Shape.getOffsetUnsafe(javaShapeInformation, dim0, dim1, dim2, dim3); data.put(offset, value); return this; }
@Override public INDArray putScalar(long dim0, long dim1, long dim2, double value) { Nd4j.getCompressor().autoDecompress(this); autoProcessScalarCall(); if (rank() != 3) throw new IllegalStateException( "Cannot use putScalar(int,int,int,double) on a rank " + rank() + " INDArray"); long offset = 0; // Shape.getOffsetUnsafe(javaShapeInformation, dim0, dim1, dim2); long size_0 = javaShapeInformation[1]; long size_1 = javaShapeInformation[1 + 1]; long size_2 = javaShapeInformation[1 + 2]; if (size_0 != 1) offset += dim0 * javaShapeInformation[1 + 0 + 3]; if (size_1 != 1) offset += dim1 * javaShapeInformation[1 + 1 + 3]; if (size_2 != 1) offset += dim2 * javaShapeInformation[1 + 2 + 3]; data.put(offset, value); return this; }
@Override public double getDouble(long i) { Nd4j.getCompressor().autoDecompress(this); if (i >= length()) { throw new IllegalArgumentException("Unable to get linear index >= " + length()); } autoProcessScalarCall(); if (i == 0) return data().getDouble(i); long[] dimensions = ordering() == 'c' ? Shape.ind2subC(this, i) : Shape.ind2sub(this, i); Shape.assertShapeLessThan(dimensions, shape()); return getDouble(dimensions); }
@Override public double getDouble(long... indices) { autoProcessScalarCall(); Nd4j.getCompressor().autoDecompress(this); for (int i = 0; i < indices.length; i++) { if (indices[i] < 0) indices[i] += rank(); } if (indices.length == 1) { if (rank() == 1) return Shape.getDouble(this, indices[0]); else if (isRowVector()) return Shape.getDouble(this, 0, indices[0]); else if (isColumnVector()) return Shape.getDouble(this, indices[0], 0); else if (isScalar() && indices[0] == 0) return data().getDouble(0); else throw new IllegalStateException("Indexes length must be > 1 for non vectors and scalars"); } return Shape.getDouble(this, indices); }
@Override public INDArray putScalar(int[] indexes, double value) { Nd4j.getCompressor().autoDecompress(this); for (int i = 0; i < indexes.length; i++) { if (indexes[i] < 0) indexes[i] += rank(); } if (indexes.length == 1) { return putScalar(indexes[0], value); } else if (indexes.length == 2) { return putScalar(indexes[0], indexes[1], value); } else if (indexes.length == 3) { return putScalar(indexes[0], indexes[1], indexes[2], value); } else if (indexes.length == 4) { return putScalar(indexes[0], indexes[1], indexes[2], indexes[3], value); } else { autoProcessScalarCall(); long offset = Shape.getOffset(javaShapeInformation, indexes); data.put(offset, value); } return this; }
@Override public INDArray putScalar(long[] indexes, double value) { Nd4j.getCompressor().autoDecompress(this); for (int i = 0; i < indexes.length; i++) { if (indexes[i] < 0) indexes[i] += rank(); } if (indexes.length == 1) { return putScalar(indexes[0], value); } else if (indexes.length == 2) { return putScalar(indexes[0], indexes[1], value); } else if (indexes.length == 3) { return putScalar(indexes[0], indexes[1], indexes[2], value); } else if (indexes.length == 4) { return putScalar(indexes[0], indexes[1], indexes[2], indexes[3], value); } else { autoProcessScalarCall(); long offset = Shape.getOffset(javaShapeInformation, indexes); data.put(offset, value); } return this; }
/** * Returns the elements at the the specified indices * * @param indices the indices to get * @return the array with the specified elements */ @Override public double getDouble(int... indices) { autoProcessScalarCall(); Nd4j.getCompressor().autoDecompress(this); for (int i = 0; i < indices.length; i++) { if (indices[i] < 0) indices[i] += rank(); } if (indices.length == 1) { if (rank() == 1) return Shape.getDouble(this, indices[0]); else if (isRowVector()) return Shape.getDouble(this, 0, indices[0]); else if (isColumnVector()) return Shape.getDouble(this, indices[0], 0); else if (isScalar() && indices[0] == 0) return data().getDouble(0); else throw new IllegalStateException("Indexes length must be > 1 for non vectors and scalars"); } return Shape.getDouble(this, indices); }
@Override public INDArray putScalar(long i, double value) { if (i < 0) i += rank(); // TODO: i'm not sure that rank == 1 has fair shortcut here if (isScalar() || rank() == 1) { autoProcessScalarCall(); data.put(i, value); return this; } // we cant raise rank here, if original rank is 1 if (isRowVector() && rank() == 2) { return putScalar(0, i, value); } else if (isColumnVector() && rank() == 2) { return putScalar(i, 0, value); } long[] indexes = ordering() == 'c' ? Shape.ind2subC(this, i) : Shape.ind2sub(this, i); return putScalar(indexes, value); }