本文整理了Java中org.nd4j.linalg.factory.Nd4j.getDataBufferFactory()
方法的一些代码示例,展示了Nd4j.getDataBufferFactory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Nd4j.getDataBufferFactory()
方法的具体详情如下:
包路径:org.nd4j.linalg.factory.Nd4j
类名称:Nd4j
方法名:getDataBufferFactory
暂无
代码示例来源:origin: deeplearning4j/nd4j
/**
* Return the minor pointers. (columns for CSR, rows for CSC,...)
* */
public DataBuffer getVectorCoordinates() {
return Nd4j.getDataBufferFactory().create(columnsPointers, 0, length());
}
代码示例来源:origin: deeplearning4j/nd4j
@Override
public DataBuffer data() {
return Nd4j.getDataBufferFactory().create(values, 0, length());
}
代码示例来源:origin: deeplearning4j/nd4j
public DataBuffer getPointerE() {
return Nd4j.getDataBufferFactory().create(pointerE, 0, rows());
}
代码示例来源:origin: deeplearning4j/nd4j
DataBuffer dataBuffer = Nd4j.getDataBufferFactory().createInt(result);
return dataBuffer;
代码示例来源:origin: deeplearning4j/nd4j
public DataBuffer getPointerB() {
return Nd4j.getDataBufferFactory().create(pointerB, 0, rows());
}
代码示例来源:origin: deeplearning4j/nd4j
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);
}
代码示例来源:origin: deeplearning4j/nd4j
@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;
}
代码示例来源:origin: deeplearning4j/nd4j
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);
代码示例来源:origin: deeplearning4j/nd4j
/**
* 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);
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* 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);
}
代码示例来源:origin: deeplearning4j/nd4j
@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;
}
代码示例来源:origin: deeplearning4j/nd4j
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);
}
代码示例来源:origin: deeplearning4j/nd4j
@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;
}
代码示例来源:origin: deeplearning4j/nd4j
@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));
}
}
代码示例来源:origin: deeplearning4j/nd4j
@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");
}
}
代码示例来源:origin: deeplearning4j/nd4j
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;
}
代码示例来源:origin: org.nd4j/nd4j-cuda-7.5
protected <T extends Aggregate> DataBuffer getBuffer(Batch<T> batch) {
DataBuffer buffer = Nd4j.getDataBufferFactory().createInt(batch.getSample().getRequiredBatchMemorySize() * 4,
false);
batch.setParamsSurface(buffer);
return buffer;
}
代码示例来源:origin: org.nd4j/nd4j-cuda-10.0
protected <T extends Aggregate> DataBuffer getBuffer(Batch<T> batch) {
DataBuffer buffer = Nd4j.getDataBufferFactory().createInt(batch.getSample().getRequiredBatchMemorySize() * 4,
false);
batch.setParamsSurface(buffer);
return buffer;
}
代码示例来源:origin: org.nd4j/nd4j-api
@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;
}
代码示例来源:origin: org.nd4j/nd4j-native-api
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);
}
内容来源于网络,如有侵权,请联系作者删除!