/** * Get blas stride for the * given array * @param arr the array * @return the blas stride */ public static int getBlasOffset(INDArray arr) { // FIXME: LONG return (int) arr.offset(); }
private INDArray copyIfNecessaryVector(INDArray vec) { if (vec.offset() != 0) return vec.dup(); return vec; }
private String shapeInfo(INDArray arr) { return Arrays.toString(arr.shape()) + " and stride " + Arrays.toString(arr.stride()) + " and offset " + arr.offset() + " and blas stride of " + BlasBufferUtil.getBlasStride(arr); }
public static void printNDArrayHeader(INDArray array) { System.out.println(array.data().dataType() + " - order=" + array.ordering() + ", offset=" + array.offset() + ", shape=" + Arrays.toString(array.shape()) + ", stride=" + Arrays.toString(array.stride()) + ", length=" + array.length() + ", data().length()=" + array.data().length()); }
/** Tensor1DStats, used to efficiently iterate through tensors on a matrix (2d NDArray) for element-wise ops * For example, the offset of each 1d tensor can be calculated using only a single tensorAlongDimension method call, * hence is potentially faster than approaches requiring multiple tensorAlongDimension calls.<br> * Note that this can only (generally) be used for 2d NDArrays. For certain 3+d NDArrays, the tensor starts may not * be in increasing order */ public static Tensor1DStats get1DTensorStats(INDArray array, int... dimension) { long tensorLength = array.size(dimension[0]); //As per tensorssAlongDimension: long numTensors = array.tensorssAlongDimension(dimension); //First tensor always starts with the first element in the NDArray, regardless of dimension long firstTensorOffset = array.offset(); //Next: Need to work out the separation between the start (first element) of each 1d tensor long tensorStartSeparation; int elementWiseStride; //Separation in buffer between elements in the tensor if (numTensors == 1) { tensorStartSeparation = -1; //Not applicable elementWiseStride = array.elementWiseStride(); } else { INDArray secondTensor = array.tensorAlongDimension(1, dimension); tensorStartSeparation = secondTensor.offset() - firstTensorOffset; elementWiseStride = secondTensor.elementWiseStride(); } return new Tensor1DStats(firstTensorOffset, tensorStartSeparation, numTensors, tensorLength, elementWiseStride); }
@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(); }
if (toSet.offset() == 0 && toSet.length() == data.length) System.arraycopy(data, 0, d, 0, d.length); else { int dIndex = (int) toSet.offset() + (i * toSet.majorStride()); d[dIndex] = data[count++]; if (data.length == toSet.length() && toSet.offset() == 0) { for (int i = 0; i < toSet.length(); i++) { underlyingData.put(i, data[i]); int dIndex = (int) toSet.offset() + (i * toSet.majorStride()); underlyingData.put(dIndex, data[count++]);
if (toSet.offset() == 0 && toSet.length() == data.length) System.arraycopy(data, 0, d, 0, d.length); else { int dIndex = (int) toSet.offset() + (i * toSet.majorStride()); d[dIndex] = data[count++]; if (data.length == toSet.length() && toSet.offset() == 0) { for (int i = 0; i < toSet.length(); i++) { underlyingData.put(i, data[i]); int dIndex = (int) toSet.offset() + (i * toSet.majorStride()); underlyingData.put(dIndex, data[count++]);
int test = (int) Math.floor(otherTest); INDArray vec = arr.vectorAlongDimension(test, -1); long otherDim = arr.vectorAlongDimension(test, -1).offset() + index; return otherDim; } else {
if (c.rows() != outRows || c.columns() != outCols) throw new IllegalArgumentException("C does not match outRows or outCols"); if (c.offset() != 0 || c.ordering() != 'f') throw new IllegalArgumentException("Invalid c");
INDArray ret = Nd4j.create(arr.data(), newShape, newStrides, arr.offset(), isFOrder ? 'f' : 'c');
if (arr.offset() < 1 && arr.data().length() == arr.length() || arr instanceof IComplexNDArray && arr.length() * 2 == arr.data().length()) if (arr.ordering() == 'f' && arr.stride(-1) != arr.elementStride()
jsonGenerator.writeEndArray(); jsonGenerator.writeNumberField("offsetField", indArray.offset()); jsonGenerator.writeStringField("typeField", indArray instanceof IComplexNDArray ? "complex" : "real"); jsonGenerator.writeNumberField("rankField", indArray.rank());
for (int i = 0; i < ret.length(); i++) { ret.data().put(i, toConcat[currBuffer].data() .getDouble(toConcat[currBuffer].offset() + currBufferOffset++)); if (currBufferOffset >= toConcat[currBuffer].length()) { currBuffer++;
/** * Get blas stride for the * given array * @param arr the array * @return the blas stride */ public static int getBlasOffset(INDArray arr) { // FIXME: LONG return (int) arr.offset(); }
private INDArray copyIfNecessaryVector(INDArray vec) { if (vec.offset() != 0) return vec.dup(); return vec; }
/** * copies the result to the host buffer */ public void copyToHost() { if(arr != null) buffer.copyToHost(arr.offset()); else { buffer.copyToHost(0); } }
public static void printNDArrayHeader(INDArray array) { System.out.println(array.data().dataType() + " - order=" + array.ordering() + ", offset=" + array.offset() + ", shape=" + Arrays.toString(array.shape()) + ", stride=" + Arrays.toString(array.stride()) + ", length=" + array.length() + ", data().length()=" + array.data().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(); }
/** * Prepares two arrays for * raw iteration linearly through the data. * It uses the same data for allocation * @param dst the first array */ public static RawArrayIterationInformation1 prepareRawArrayIter(INDArray dst) { return RawArrayIterationInformation1.builder().aOffset(dst.offset()).a(dst.data()).aStrides(dst.stride()) .nDim(dst.rank()).shape(dst.shape()).build().computeOut(); }