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

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

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

Nd4j.getShapeInfoProvider介绍

暂无

代码示例

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

  1. @Override
  2. public void setShapeAndStride(int[] shape, int[] stride) {
  3. setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, 0, -1, ordering()));
  4. }

代码示例来源: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. 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. private static DataBuffer getIm2ColShape(INDArray img, int kernelHeight, int kernelWidth, int outHeight, int outWidth) {
  2. //number of images
  3. long n = img.size(0);
  4. //number of channels (depth)
  5. long c = img.size(1);
  6. return Nd4j.getShapeInfoProvider().createShapeInformation(new long[] {n, c, kernelHeight, kernelWidth, outHeight, outWidth}, 'c').getFirst();
  7. }

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

  1. @Override
  2. public void setShape(long[] shape) {
  3. setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride(), 0, elementWiseStride(), ordering()));
  4. }

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

  1. @Override
  2. public void setOrder(char order) {
  3. setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape(), stride(), 0,
  4. elementWiseStride(), order));
  5. }

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

  1. /**
  2. *
  3. * @param buffer
  4. */
  5. public BaseNDArray(DataBuffer buffer) {
  6. this.data = buffer;
  7. if (buffer.length() >= Integer.MAX_VALUE)
  8. throw new IllegalArgumentException("Length of buffer can not be >= Integer.MAX_VALUE");
  9. int[] shape = {1, (int) buffer.length()};
  10. int[] stride = Nd4j.getStrides(shape);
  11. setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, 0, 1, Nd4j.order()));
  12. init(shape, stride);
  13. }

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

  1. @Override
  2. public void setStride(long[] stride) {
  3. setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape(), stride, 0, elementWiseStride(), ordering()));
  4. }

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

  1. public BaseNDArray(long newRows, long newColumns, char ordering) {
  2. this.data = Nd4j.createBuffer((long) newRows * newColumns);
  3. long[] shape = new long[] {newRows, newColumns};
  4. long[] stride = Nd4j.getStrides(shape, ordering);
  5. setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, 0,
  6. Shape.elementWiseStride(shape, stride, ordering == 'f'), ordering));
  7. init(shape, stride);
  8. }

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

  1. /**
  2. * This method creates compressed INDArray from Java double array, skipping usual INDArray instantiation routines
  3. *
  4. * @param data
  5. * @param shape
  6. * @param order
  7. * @return
  8. */
  9. @Override
  10. public INDArray compress(double[] data, int[] shape, char order) {
  11. DoublePointer pointer = new DoublePointer(data);
  12. DataBuffer shapeInfo = Nd4j.getShapeInfoProvider().createShapeInformation(shape, order).getFirst();
  13. DataBuffer buffer = compressPointer(DataBuffer.TypeEx.DOUBLE, pointer, data.length, 8);
  14. return Nd4j.createArrayFromShapeBuffer(buffer, shapeInfo);
  15. }

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

  1. public BaseSparseNDArrayCOO(DataBuffer values, DataBuffer indices, DataBuffer sparseInformation, int[] shape) {
  2. this.values = Nd4j.createBuffer(values, 0, values.length());
  3. this.indices = indices;
  4. setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape));
  5. init(shape);
  6. this.sparseInformation = sparseInformation;
  7. this.length = countNNZ();
  8. }

代码示例来源: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 void setStride(int[] stride) {
  3. setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape(), ArrayUtil.toLongArray(stride), 0, elementWiseStride(), ordering()));
  4. }

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

  1. @Override
  2. public void setShape(int[] shape) {
  3. setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(ArrayUtil.toLongArray(shape), stride(), 0, elementWiseStride(), ordering()));
  4. }

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

  1. /**
  2. * Creates a new <i>n</i> times <i>m</i> <tt>DoubleMatrix</tt>.
  3. *
  4. * @param newRows the number of rows (<i>n</i>) of the new matrix.
  5. * @param newColumns the number of columns (<i>m</i>) of the new matrix.
  6. */
  7. public BaseNDArray(int newRows, int newColumns, char ordering) {
  8. this.data = Nd4j.createBuffer((long) newRows * newColumns);
  9. int[] shape = new int[] {newRows, newColumns};
  10. int[] stride = Nd4j.getStrides(shape, ordering);
  11. setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, 0,
  12. Shape.elementWiseStride(shape, stride, ordering == 'f'), ordering));
  13. init(shape, stride);
  14. }

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

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

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

  1. /**
  2. *
  3. * @param data
  4. * @param shape
  5. * @param stride
  6. * @param offset
  7. */
  8. public BaseNDArray(DataBuffer data, int[] shape, int[] stride, long offset) {
  9. this.data = Nd4j.createBuffer(data, offset, ArrayUtil.prodLong(shape));
  10. setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape, stride, offset, Shape.elementWiseStride(shape, stride, Nd4j.order() == 'f'), Nd4j.order()));
  11. init(shape, stride);
  12. // Shape.setElementWiseStride(this.shapeInfo(),Shape.elementWiseStride(shape, stride, Nd4j.order() == 'f'));
  13. }

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

  1. public BaseSparseNDArrayCOO(float[] values, int[][] indices, int[] shape) {
  2. checkArgument(values.length == indices.length);
  3. checkArgument(values.length == 0 || indices[0].length == shape.length);
  4. this.values = Nd4j.createBuffer(values);
  5. this.indices = Nd4j.createBuffer(ArrayUtil.flatten(indices));
  6. setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape));
  7. init(shape);
  8. this.length = values.length;
  9. int[] flags = new int[rank()];
  10. long[] sparseOffsets = new long[rank()];
  11. int[] hiddenDimension = new int[] {-1};
  12. this.sparseInformation = Nd4j.getSparseInfoProvider().createSparseInformation(flags, sparseOffsets,
  13. hiddenDimension, rank());
  14. }

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

  1. public BaseSparseNDArrayCOO(DataBuffer values, DataBuffer indices, int[] shape) {
  2. checkArgument(values.length() * shape.length == indices.length());
  3. this.values = Nd4j.createBuffer(values, 0, values.length());
  4. this.indices = indices;
  5. setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape));
  6. init(shape);
  7. this.length = values.length();
  8. int[] flags = new int[rank()];
  9. long[] sparseOffsets = new long[rank()];
  10. int[] hiddenDimension = new int[] {-1};
  11. this.sparseInformation = Nd4j.getSparseInfoProvider().createSparseInformation(flags, sparseOffsets,
  12. hiddenDimension, rank());
  13. }

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

  1. public BaseSparseNDArrayCSR(DataBuffer data, int[] columnsPointers, int[] pointerB, int[] pointerE, int[] shape) {
  2. checkArgument(pointerB.length == pointerE.length);
  3. setShapeInformation(Nd4j.getShapeInfoProvider().createShapeInformation(shape));
  4. init(shape);
  5. this.values = data;
  6. this.columnsPointers = Nd4j.getDataBufferFactory().createInt(data.length());
  7. this.columnsPointers.setData(columnsPointers);
  8. this.length = columnsPointers.length;
  9. // The size of these pointers are constant
  10. int pointersSpace = rows;
  11. this.pointerB = Nd4j.getDataBufferFactory().createInt(pointersSpace);
  12. this.pointerB.setData(pointerB);
  13. this.pointerE = Nd4j.getDataBufferFactory().createInt(pointersSpace);
  14. this.pointerE.setData(pointerE);
  15. }

相关文章