org.nd4j.linalg.factory.Nd4j.createBuffer()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(190)

本文整理了Java中org.nd4j.linalg.factory.Nd4j.createBuffer()方法的一些代码示例,展示了Nd4j.createBuffer()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Nd4j.createBuffer()方法的具体详情如下:
包路径:org.nd4j.linalg.factory.Nd4j
类名称:Nd4j
方法名:createBuffer

Nd4j.createBuffer介绍

[英]Creates a buffer of the specified length based on the data opType
[中]基于数据类型创建指定长度的缓冲区

代码示例

代码示例来源:origin: deeplearning4j/nd4j

  1. /**
  2. * Creates a buffer of the specified length based on the data opType
  3. *
  4. * @param length the length of te buffer
  5. * @return the buffer to create
  6. */
  7. public static DataBuffer createBuffer(long length) {
  8. return createBuffer(length, true);
  9. }

代码示例来源:origin: deeplearning4j/nd4j

  1. public BaseComplexNDArray(float[] data, long[] shape, long[] stride, long offset, Character order) {
  2. this.data = Nd4j.createBuffer(data);
  3. /* this.stride = ArrayUtil.copy(stride);
  4. this.offset = offset;
  5. this.ordering = order;
  6. init(shape);*/
  7. throw new UnsupportedOperationException();
  8. }

代码示例来源:origin: deeplearning4j/nd4j

  1. /**
  2. * @param data
  3. * @param shape
  4. * @param offset
  5. * @return
  6. */
  7. @Override
  8. public IComplexNDArray createComplex(double[] data, int[] shape, long offset) {
  9. return createComplex(Nd4j.createBuffer(data), shape, offset);
  10. }

代码示例来源:origin: deeplearning4j/nd4j

  1. /**
  2. * Construct an ndarray of the specified shape.
  3. *
  4. * @param shape the shape of the ndarray
  5. * @param stride the stride of the ndarray
  6. * @param offset the desired offset
  7. * @param ordering the ordering of the ndarray
  8. * @param initialize Whether to initialize the INDArray. If true: initialize. If false: don't.
  9. */
  10. public BaseNDArray(int[] shape, int[] stride, long offset, char ordering, boolean initialize) {
  11. this(Nd4j.createBuffer(ArrayUtil.prodLong(shape), initialize), shape, stride, offset, ordering);
  12. }

代码示例来源:origin: deeplearning4j/nd4j

  1. /**
  2. * @param data
  3. * @param shape
  4. * @param offset
  5. * @param ordering
  6. * @return
  7. */
  8. @Override
  9. public IComplexNDArray createComplex(double[] data, int[] shape, long offset, char ordering) {
  10. return createComplex(Nd4j.createBuffer(data), shape, offset, ordering);
  11. }

代码示例来源:origin: deeplearning4j/nd4j

  1. /**
  2. * Get the shape from
  3. * the given int buffer
  4. * @param buffer the buffer to get the shape information for
  5. * @return
  6. */
  7. public static DataBuffer stride(DataBuffer buffer) {
  8. int rank = rank(buffer);
  9. return Nd4j.createBuffer(buffer, 1 + rank, rank);
  10. }

代码示例来源:origin: deeplearning4j/nd4j

  1. private void setIndexes(BaseSparseNDArrayCOO coo, boolean oneBased) {
  2. int incr = oneBased ? 1 : 0;
  3. int[] idx = coo.getIncludedIndices().asInt();
  4. int[] rows = new int[nnz];
  5. int[] cols = new int[nnz];
  6. for (int i = 0; i < nnz; i++) {
  7. rows[i] = idx[i * 2] + incr;
  8. cols[i] = idx[(i * 2) + 1] + incr;
  9. }
  10. rowInd = Nd4j.createBuffer(rows);
  11. colInd = Nd4j.createBuffer(cols);
  12. }

代码示例来源:origin: deeplearning4j/nd4j

  1. /**
  2. * Get the shape from
  3. * the given int buffer
  4. * @param buffer the buffer to get the shape information for
  5. * @return
  6. */
  7. public static DataBuffer shapeOf(DataBuffer buffer) {
  8. int rank = (int) buffer.getLong(0);
  9. return Nd4j.createBuffer(buffer, 1, rank);
  10. }

代码示例来源:origin: deeplearning4j/nd4j

  1. /**
  2. * Construct an ndarray of the specified shape
  3. * with an empty data array
  4. *
  5. * @param shape the shape of the ndarray
  6. * @param stride the stride of the ndarray
  7. * @param offset the desired offset
  8. * @param ordering the ordering of the ndarray
  9. */
  10. public BaseNDArray(int[] shape, int[] stride, long offset, char ordering) {
  11. this(Nd4j.createBuffer(ArrayUtil.prodLong(shape)), shape, stride, offset, ordering);
  12. }

代码示例来源:origin: deeplearning4j/nd4j

  1. /**
  2. *
  3. * @param shape
  4. * @param offset
  5. * @param ordering
  6. */
  7. public BaseComplexNDArray(int[] shape, long offset, char ordering) {
  8. this(Nd4j.createBuffer(ArrayUtil.prodLong(shape) * 2), shape, Nd4j.getComplexStrides(shape, ordering), offset,
  9. ordering);
  10. }

代码示例来源:origin: deeplearning4j/nd4j

  1. /**
  2. *
  3. * @param shape
  4. */
  5. public BaseComplexNDArray(int[] shape) {
  6. this(Nd4j.createBuffer(ArrayUtil.prodLong(shape) * 2), shape, Nd4j.getComplexStrides(shape));
  7. }

代码示例来源:origin: deeplearning4j/nd4j

  1. @Override
  2. public INDArray create(long[] shape, long[] stride, long offset, char ordering) {
  3. if (shape.length == 1 && shape[0] == 0) {
  4. shape = new long[] {1, 1};
  5. }
  6. return create(Nd4j.createBuffer(ArrayUtil.prodLong(shape)), shape, stride, offset, ordering);
  7. }

代码示例来源:origin: deeplearning4j/nd4j

  1. @Override
  2. public INDArray create(float[] data, char order) {
  3. int[] shape = new int[] {1, data.length};
  4. return create(Nd4j.createBuffer(data), shape, Nd4j.getStrides(shape, order), order, 0);
  5. }

代码示例来源:origin: deeplearning4j/nd4j

  1. public BaseNDArray(double[] data, long[] shape, long[] stride, long offset, char ordering) {
  2. setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, offset,
  3. Shape.elementWiseStride(shape, stride, ordering == 'f'), ordering));
  4. if (data != null && data.length > 0) {
  5. this.data = Nd4j.createBuffer(data, offset);
  6. if (offset >= data.length)
  7. throw new IllegalArgumentException("invalid offset: must be < data.length");
  8. }
  9. init(shape, stride);
  10. }

代码示例来源:origin: deeplearning4j/nd4j

  1. public BaseNDArray(float[] data, long[] shape, long[] stride, long offset, char ordering) {
  2. setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, offset,
  3. Shape.elementWiseStride(shape, stride, ordering == 'f'), ordering));
  4. if (data != null && data.length > 0) {
  5. this.data = Nd4j.createBuffer(data, offset);
  6. if (offset >= data.length)
  7. throw new IllegalArgumentException("invalid offset: must be < data.length");
  8. }
  9. init(shape, stride);
  10. }

代码示例来源:origin: deeplearning4j/nd4j

  1. protected void read(ObjectInputStream s) {
  2. shapeInformation = Nd4j.createBuffer(new int[Shape.shapeInfoLength(rank())], 0);
  3. shapeInformation.read(s);
  4. setShapeInformation(Pair.create(shapeInformation, shapeInformation.asLong()));
  5. data = Nd4j.createBuffer(length(), false);
  6. data().read(s);
  7. }

代码示例来源:origin: deeplearning4j/nd4j

  1. protected static DataBuffer internalCreateBuffer(float[] data) {
  2. val perfX = PerformanceTracker.getInstance().helperStartTransaction();
  3. val buffer = Nd4j.createBuffer(data);
  4. PerformanceTracker.getInstance().helperRegisterTransaction(0, perfX, data.length * Nd4j.sizeOfDataType(), MemcpyDirection.HOST_TO_HOST);
  5. return buffer;
  6. }

代码示例来源:origin: deeplearning4j/nd4j

  1. protected static DataBuffer internalCreateBuffer(int[] data) {
  2. val perfX = PerformanceTracker.getInstance().helperStartTransaction();
  3. val buffer = Nd4j.createBuffer(data);
  4. PerformanceTracker.getInstance().helperRegisterTransaction(0, perfX, data.length * Nd4j.sizeOfDataType(), MemcpyDirection.HOST_TO_HOST);
  5. return buffer;
  6. }

代码示例来源:origin: deeplearning4j/nd4j

  1. public BaseNDArray(DataBuffer buffer, long[] shape, long[] stride, long offset, char ordering) {
  2. this.data = offset > 0 ? Nd4j.createBuffer(buffer, offset, ArrayUtil.prodLong(shape)) : buffer;
  3. setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, offset,
  4. Shape.elementWiseStride(shape, stride, ordering == 'f'), ordering));
  5. init(shape, stride);
  6. // Shape.setElementWiseStride(this.shapeInfo(),Shape.elementWiseStride(shape, stride, ordering == 'f'));
  7. }

代码示例来源:origin: deeplearning4j/nd4j

  1. @Override
  2. public INDArray convertToFloats() {
  3. if (data.dataType() == DataBuffer.Type.FLOAT)
  4. return this;
  5. val factory = Nd4j.getNDArrayFactory();
  6. val buffer = Nd4j.createBuffer(new long[]{this.length()}, DataBuffer.Type.FLOAT);
  7. factory.convertDataEx(convertType(data.dataType()), this.data().addressPointer(), DataBuffer.TypeEx.FLOAT, buffer.addressPointer(), buffer.length());
  8. return Nd4j.createArrayFromShapeBuffer(buffer, this.shapeInformation);
  9. }

相关文章