/** * Return the minor pointers. (columns for CSR, rows for CSC,...) * */ public DataBuffer getVectorCoordinates() { return Nd4j.getDataBufferFactory().create(columnsPointers, 0, length()); }
@Override public DataBuffer data() { return Nd4j.getDataBufferFactory().create(values, 0, length()); }
public DataBuffer getPointerE() { return Nd4j.getDataBufferFactory().create(pointerE, 0, rows()); }
DataBuffer dataBuffer = Nd4j.getDataBufferFactory().createInt(result); return dataBuffer;
public DataBuffer getPointerB() { return Nd4j.getDataBufferFactory().create(pointerB, 0, rows()); }
public BaseSparseNDArrayCSR(DataBuffer data, int[] columnsPointers, int[] pointerB, int[] pointerE, int[] shape) { checkArgument(pointerB.length == pointerE.length); setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape)); init(shape); this.values = data; this.columnsPointers = Nd4j.getDataBufferFactory().createInt(data.length()); this.columnsPointers.setData(columnsPointers); this.length = columnsPointers.length; // The size of these pointers are constant int pointersSpace = rows; this.pointerB = Nd4j.getDataBufferFactory().createInt(pointersSpace); this.pointerB.setData(pointerB); this.pointerE = Nd4j.getDataBufferFactory().createInt(pointersSpace); this.pointerE.setData(pointerE); }
@Override public INDArray bitmapEncode(INDArray indArray, double threshold) { DataBuffer buffer = Nd4j.getDataBufferFactory().createInt(indArray.length() / 16 + 5); INDArray ret = Nd4j.createArrayFromShapeBuffer(buffer, indArray.shapeInfoDataBuffer()); bitmapEncode(indArray, ret, threshold); return ret; }
init(shape); int valuesSpace = (int) (data.length * THRESHOLD_MEMORY_ALLOCATION); this.values = Nd4j.getDataBufferFactory().createDouble(valuesSpace); this.values.setData(data); this.columnsPointers = Nd4j.getDataBufferFactory().createInt(valuesSpace); this.columnsPointers.setData(columnsPointers); this.length = columnsPointers.length; int pointersSpace = rows; this.pointerB = Nd4j.getDataBufferFactory().createInt(pointersSpace); this.pointerB.setData(pointerB); this.pointerE = Nd4j.getDataBufferFactory().createInt(pointersSpace); this.pointerE.setData(pointerE);
/** * Returns the underlying indices of the element of the given index * such as there really are in the original ndarray * * @param i the index of the element+ * @return a dataBuffer containing the indices of element * */ public DataBuffer getUnderlyingIndicesOf(int i) { int from = underlyingRank() * i; //int to = from + underlyingRank(); int[] res = new int[underlyingRank()]; for(int j = 0; j< underlyingRank(); j++){ res[j] = indices.getInt(from + j); } ///int[] arr = Arrays.copyOfRange(indices.asInt(), from, to); return Nd4j.getDataBufferFactory().createInt(res); }
/** * Returns the indices of the element of the given index in the array context * * @param i the index of the element * @return a dataBuffer containing the indices of element * */ public DataBuffer getIndicesOf(int i) { int from = underlyingRank() * i; int to = from + underlyingRank(); //not included int[] arr = new int[rank]; int j = 0; // iterator over underlying indices int k = 0; //iterator over hiddenIdx for (int dim = 0; dim < rank; dim++) { if (k < hiddenDimensions().length && hiddenDimensions()[k] == j) { arr[dim] = 0; k++; } else { arr[dim] = indices.getInt(j); j++; } } return Nd4j.getDataBufferFactory().createInt(arr); }
@Override public INDArray getrf(INDArray A) { // FIXME: int cast if (A.rows() > Integer.MAX_VALUE || A.columns() > Integer.MAX_VALUE) throw new ND4JArraySizeException(); int m = (int) A.rows(); int n = (int) A.columns(); INDArray INFO = Nd4j.createArrayFromShapeBuffer(Nd4j.getDataBufferFactory().createInt(1), Nd4j.getShapeInfoProvider().createShapeInformation(new int[] {1, 1}).getFirst()); int mn = Math.min(m, n); INDArray IPIV = Nd4j.createArrayFromShapeBuffer(Nd4j.getDataBufferFactory().createInt(mn), Nd4j.getShapeInfoProvider().createShapeInformation(new int[] {1, mn}).getFirst()); if (A.data().dataType() == DataBuffer.Type.DOUBLE) dgetrf(m, n, A, IPIV, INFO); else if (A.data().dataType() == DataBuffer.Type.FLOAT) sgetrf(m, n, A, IPIV, INFO); else throw new UnsupportedOperationException(); if (INFO.getInt(0) < 0) { throw new Error("Parameter #" + INFO.getInt(0) + " to getrf() was not valid"); } else if (INFO.getInt(0) > 0) { log.warn("The matrix is singular - cannot be used for inverse op. Check L matrix at row " + INFO.getInt(0)); } return IPIV; }
public NativeRandom(long seed, long numberOfElements) { this.amplifier = seed; this.generation = 1; this.seed = seed; this.numberOfElements = numberOfElements; nativeOps = NativeOpsHolder.getInstance().getDeviceNativeOps(); stateBuffer = Nd4j.getDataBufferFactory().createDouble(numberOfElements); init(); hostPointer = new LongPointer(stateBuffer.addressPointer()); deallocator = NativeRandomDeallocator.getInstance(); pack = new NativePack(statePointer.address(), statePointer); deallocator.trackStatePointer(pack); }
@Override public void potrf(INDArray A, boolean lower) { // FIXME: int cast if (A.columns() > Integer.MAX_VALUE) throw new ND4JArraySizeException(); byte uplo = (byte) (lower ? 'L' : 'U'); // upper or lower part of the factor desired ? int n = (int) A.columns(); INDArray INFO = Nd4j.createArrayFromShapeBuffer(Nd4j.getDataBufferFactory().createInt(1), Nd4j.getShapeInfoProvider().createShapeInformation(new int[] {1, 1}).getFirst()); if (A.data().dataType() == DataBuffer.Type.DOUBLE) dpotrf(uplo, n, A, INFO); else if (A.data().dataType() == DataBuffer.Type.FLOAT) spotrf(uplo, n, A, INFO); else throw new UnsupportedOperationException(); if (INFO.getInt(0) < 0) { throw new Error("Parameter #" + INFO.getInt(0) + " to potrf() was not valid"); } else if (INFO.getInt(0) > 0) { throw new Error("The matrix is not positive definite! (potrf fails @ order " + INFO.getInt(0) + ")"); } return; }
@Override public void gesvd(INDArray A, INDArray S, INDArray U, INDArray VT) { // FIXME: int cast if (A.rows() > Integer.MAX_VALUE || A.columns() > Integer.MAX_VALUE) throw new ND4JArraySizeException(); int m = (int) A.rows(); int n = (int) A.columns(); byte jobu = (byte) (U == null ? 'N' : 'A'); byte jobvt = (byte) (VT == null ? 'N' : 'A'); INDArray INFO = Nd4j.createArrayFromShapeBuffer(Nd4j.getDataBufferFactory().createInt(1), Nd4j.getShapeInfoProvider().createShapeInformation(new int[] {1, 1}).getFirst()); if (A.data().dataType() == DataBuffer.Type.DOUBLE) dgesvd(jobu, jobvt, m, n, A, S, U, VT, INFO); else if (A.data().dataType() == DataBuffer.Type.FLOAT) sgesvd(jobu, jobvt, m, n, A, S, U, VT, INFO); else throw new UnsupportedOperationException(); if (INFO.getInt(0) < 0) { throw new Error("Parameter #" + INFO.getInt(0) + " to gesvd() was not valid"); } else if (INFO.getInt(0) > 0) { log.warn("The matrix contains singular elements. Check S matrix at row " + INFO.getInt(0)); } }
@Override public void geqrf(INDArray A, INDArray R) { // FIXME: int cast if (A.rows() > Integer.MAX_VALUE || A.columns() > Integer.MAX_VALUE) throw new ND4JArraySizeException(); int m = (int) A.rows(); int n = (int) A.columns(); INDArray INFO = Nd4j.createArrayFromShapeBuffer(Nd4j.getDataBufferFactory().createInt(1), Nd4j.getShapeInfoProvider().createShapeInformation(new int[] {1, 1}).getFirst()); if (R.rows() != A.columns() || R.columns() != A.columns()) { throw new Error("geqrf: R must be N x N (n = columns in A)"); } if (A.data().dataType() == DataBuffer.Type.DOUBLE) { dgeqrf(m, n, A, R, INFO); } else if (A.data().dataType() == DataBuffer.Type.FLOAT) { sgeqrf(m, n, A, R, INFO); } else { throw new UnsupportedOperationException(); } if (INFO.getInt(0) < 0) { throw new Error("Parameter #" + INFO.getInt(0) + " to getrf() was not valid"); } }
public static Cloner newCloner() { Cloner cloner = new Cloner(); //Implement custom cloning for INDArrays (default can have problems with off-heap and pointers) //Sadly: the cloner library does NOT support interfaces here, hence we need to use the actual classes //cloner.registerFastCloner(INDArray.class, new INDArrayFastCloner()); //Does not work due to interface IFastCloner fc = new INDArrayFastCloner(); cloner.registerFastCloner(Nd4j.getBackend().getNDArrayClass(), fc); cloner.registerFastCloner(Nd4j.getBackend().getComplexNDArrayClass(), fc); //Same thing with DataBuffers: off heap -> cloner library chokes on them, but need to know the concrete // buffer classes, not just the interface IFastCloner fc2 = new DataBufferFastCloner(); DataBufferFactory d = Nd4j.getDataBufferFactory(); doReg(cloner, fc2, d.intBufferClass()); doReg(cloner, fc2, d.longBufferClass()); doReg(cloner, fc2, d.halfBufferClass()); doReg(cloner, fc2, d.floatBufferClass()); doReg(cloner, fc2, d.doubleBufferClass()); doReg(cloner, fc2, CompressedDataBuffer.class); return cloner; }
protected <T extends Aggregate> DataBuffer getBuffer(Batch<T> batch) { DataBuffer buffer = Nd4j.getDataBufferFactory().createInt(batch.getSample().getRequiredBatchMemorySize() * 4, false); batch.setParamsSurface(buffer); return buffer; }
protected <T extends Aggregate> DataBuffer getBuffer(Batch<T> batch) { DataBuffer buffer = Nd4j.getDataBufferFactory().createInt(batch.getSample().getRequiredBatchMemorySize() * 4, false); batch.setParamsSurface(buffer); return buffer; }
@Override public INDArray bitmapEncode(INDArray indArray, double threshold) { DataBuffer buffer = Nd4j.getDataBufferFactory().createInt(indArray.length() / 16 + 5); INDArray ret = Nd4j.createArrayFromShapeBuffer(buffer, indArray.shapeInfoDataBuffer()); bitmapEncode(indArray, ret, threshold); return ret; }
public NativeRandom(long seed, long numberOfElements) { this.amplifier = seed; this.generation = 1; this.seed = seed; this.numberOfElements = numberOfElements; nativeOps = NativeOpsHolder.getInstance().getDeviceNativeOps(); stateBuffer = Nd4j.getDataBufferFactory().createDouble(numberOfElements); init(); hostPointer = new LongPointer(stateBuffer.addressPointer()); deallocator = NativeRandomDeallocator.getInstance(); pack = new NativePack(statePointer.address(), statePointer); deallocator.trackStatePointer(pack); }