本文整理了Java中org.nd4j.linalg.factory.Nd4j.createBuffer()
方法的一些代码示例,展示了Nd4j.createBuffer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Nd4j.createBuffer()
方法的具体详情如下:
包路径:org.nd4j.linalg.factory.Nd4j
类名称:Nd4j
方法名:createBuffer
[英]Creates a buffer of the specified length based on the data opType
[中]基于数据类型创建指定长度的缓冲区
代码示例来源:origin: deeplearning4j/nd4j
/**
* Creates a buffer of the specified length based on the data opType
*
* @param length the length of te buffer
* @return the buffer to create
*/
public static DataBuffer createBuffer(long length) {
return createBuffer(length, true);
}
代码示例来源:origin: deeplearning4j/nd4j
public BaseComplexNDArray(float[] data, long[] shape, long[] stride, long offset, Character order) {
this.data = Nd4j.createBuffer(data);
/* this.stride = ArrayUtil.copy(stride);
this.offset = offset;
this.ordering = order;
init(shape);*/
throw new UnsupportedOperationException();
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* @param data
* @param shape
* @param offset
* @return
*/
@Override
public IComplexNDArray createComplex(double[] data, int[] shape, long offset) {
return createComplex(Nd4j.createBuffer(data), shape, offset);
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* Construct an ndarray of the specified shape.
*
* @param shape the shape of the ndarray
* @param stride the stride of the ndarray
* @param offset the desired offset
* @param ordering the ordering of the ndarray
* @param initialize Whether to initialize the INDArray. If true: initialize. If false: don't.
*/
public BaseNDArray(int[] shape, int[] stride, long offset, char ordering, boolean initialize) {
this(Nd4j.createBuffer(ArrayUtil.prodLong(shape), initialize), shape, stride, offset, ordering);
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* @param data
* @param shape
* @param offset
* @param ordering
* @return
*/
@Override
public IComplexNDArray createComplex(double[] data, int[] shape, long offset, char ordering) {
return createComplex(Nd4j.createBuffer(data), shape, offset, ordering);
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* Get the shape from
* the given int buffer
* @param buffer the buffer to get the shape information for
* @return
*/
public static DataBuffer stride(DataBuffer buffer) {
int rank = rank(buffer);
return Nd4j.createBuffer(buffer, 1 + rank, rank);
}
代码示例来源:origin: deeplearning4j/nd4j
private void setIndexes(BaseSparseNDArrayCOO coo, boolean oneBased) {
int incr = oneBased ? 1 : 0;
int[] idx = coo.getIncludedIndices().asInt();
int[] rows = new int[nnz];
int[] cols = new int[nnz];
for (int i = 0; i < nnz; i++) {
rows[i] = idx[i * 2] + incr;
cols[i] = idx[(i * 2) + 1] + incr;
}
rowInd = Nd4j.createBuffer(rows);
colInd = Nd4j.createBuffer(cols);
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* Get the shape from
* the given int buffer
* @param buffer the buffer to get the shape information for
* @return
*/
public static DataBuffer shapeOf(DataBuffer buffer) {
int rank = (int) buffer.getLong(0);
return Nd4j.createBuffer(buffer, 1, rank);
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* Construct an ndarray of the specified shape
* with an empty data array
*
* @param shape the shape of the ndarray
* @param stride the stride of the ndarray
* @param offset the desired offset
* @param ordering the ordering of the ndarray
*/
public BaseNDArray(int[] shape, int[] stride, long offset, char ordering) {
this(Nd4j.createBuffer(ArrayUtil.prodLong(shape)), shape, stride, offset, ordering);
}
代码示例来源:origin: deeplearning4j/nd4j
/**
*
* @param shape
* @param offset
* @param ordering
*/
public BaseComplexNDArray(int[] shape, long offset, char ordering) {
this(Nd4j.createBuffer(ArrayUtil.prodLong(shape) * 2), shape, Nd4j.getComplexStrides(shape, ordering), offset,
ordering);
}
代码示例来源:origin: deeplearning4j/nd4j
/**
*
* @param shape
*/
public BaseComplexNDArray(int[] shape) {
this(Nd4j.createBuffer(ArrayUtil.prodLong(shape) * 2), shape, Nd4j.getComplexStrides(shape));
}
代码示例来源:origin: deeplearning4j/nd4j
@Override
public INDArray create(long[] shape, long[] stride, long offset, char ordering) {
if (shape.length == 1 && shape[0] == 0) {
shape = new long[] {1, 1};
}
return create(Nd4j.createBuffer(ArrayUtil.prodLong(shape)), shape, stride, offset, ordering);
}
代码示例来源:origin: deeplearning4j/nd4j
@Override
public INDArray create(float[] data, char order) {
int[] shape = new int[] {1, data.length};
return create(Nd4j.createBuffer(data), shape, Nd4j.getStrides(shape, order), order, 0);
}
代码示例来源:origin: deeplearning4j/nd4j
public BaseNDArray(double[] data, long[] shape, long[] stride, long offset, char ordering) {
setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, offset,
Shape.elementWiseStride(shape, stride, ordering == 'f'), ordering));
if (data != null && data.length > 0) {
this.data = Nd4j.createBuffer(data, offset);
if (offset >= data.length)
throw new IllegalArgumentException("invalid offset: must be < data.length");
}
init(shape, stride);
}
代码示例来源:origin: deeplearning4j/nd4j
public BaseNDArray(float[] data, long[] shape, long[] stride, long offset, char ordering) {
setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, offset,
Shape.elementWiseStride(shape, stride, ordering == 'f'), ordering));
if (data != null && data.length > 0) {
this.data = Nd4j.createBuffer(data, offset);
if (offset >= data.length)
throw new IllegalArgumentException("invalid offset: must be < data.length");
}
init(shape, stride);
}
代码示例来源:origin: deeplearning4j/nd4j
protected void read(ObjectInputStream s) {
shapeInformation = Nd4j.createBuffer(new int[Shape.shapeInfoLength(rank())], 0);
shapeInformation.read(s);
setShapeInformation(Pair.create(shapeInformation, shapeInformation.asLong()));
data = Nd4j.createBuffer(length(), false);
data().read(s);
}
代码示例来源:origin: deeplearning4j/nd4j
protected static DataBuffer internalCreateBuffer(float[] data) {
val perfX = PerformanceTracker.getInstance().helperStartTransaction();
val buffer = Nd4j.createBuffer(data);
PerformanceTracker.getInstance().helperRegisterTransaction(0, perfX, data.length * Nd4j.sizeOfDataType(), MemcpyDirection.HOST_TO_HOST);
return buffer;
}
代码示例来源:origin: deeplearning4j/nd4j
protected static DataBuffer internalCreateBuffer(int[] data) {
val perfX = PerformanceTracker.getInstance().helperStartTransaction();
val buffer = Nd4j.createBuffer(data);
PerformanceTracker.getInstance().helperRegisterTransaction(0, perfX, data.length * Nd4j.sizeOfDataType(), MemcpyDirection.HOST_TO_HOST);
return buffer;
}
代码示例来源:origin: deeplearning4j/nd4j
public BaseNDArray(DataBuffer buffer, long[] shape, long[] stride, long offset, char ordering) {
this.data = offset > 0 ? Nd4j.createBuffer(buffer, offset, ArrayUtil.prodLong(shape)) : buffer;
setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, offset,
Shape.elementWiseStride(shape, stride, ordering == 'f'), ordering));
init(shape, stride);
// Shape.setElementWiseStride(this.shapeInfo(),Shape.elementWiseStride(shape, stride, ordering == 'f'));
}
代码示例来源:origin: deeplearning4j/nd4j
@Override
public INDArray convertToFloats() {
if (data.dataType() == DataBuffer.Type.FLOAT)
return this;
val factory = Nd4j.getNDArrayFactory();
val buffer = Nd4j.createBuffer(new long[]{this.length()}, DataBuffer.Type.FLOAT);
factory.convertDataEx(convertType(data.dataType()), this.data().addressPointer(), DataBuffer.TypeEx.FLOAT, buffer.addressPointer(), buffer.length());
return Nd4j.createArrayFromShapeBuffer(buffer, this.shapeInformation);
}
内容来源于网络,如有侵权,请联系作者删除!