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

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

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

Nd4j.getStrides介绍

[英]Get the strides based on the shape and NDArrays.order()
[中]根据形状和路线获得步幅。订单()

代码示例

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

  1. /**
  2. * @param data the data to use
  3. * @param shape the shape of the ndarray
  4. * @param offset the desired offset
  5. * @param ordering the ordering of the ndarray
  6. */
  7. public BaseNDArray(float[] data, int[] shape, long offset, char ordering) {
  8. this(data, shape, Nd4j.getStrides(shape, ordering), offset);
  9. }

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

  1. /**
  2. * Constructor for stride and offset
  3. *
  4. * @param buffer
  5. * @param shape
  6. * @param offset
  7. * @param ordering
  8. */
  9. public BaseNDArray(DataBuffer buffer, int[] shape, long offset, char ordering) {
  10. this(buffer, shape, Nd4j.getStrides(shape, ordering), offset, ordering);
  11. }

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

  1. /**
  2. *
  3. * @param shape
  4. * @param offset
  5. * @param ordering
  6. */
  7. public BaseNDArray(int[] shape, long offset, char ordering) {
  8. this(shape, Nd4j.getStrides(shape, ordering), offset, ordering);
  9. }

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

  1. /**
  2. *
  3. * @param shape
  4. * @param offset
  5. */
  6. public BaseNDArray(int[] shape, long offset) {
  7. this(shape, Nd4j.getStrides(shape), offset);
  8. }

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

  1. /**
  2. * Create an ndarray from the specified slices.
  3. * This will go through and merge all of the
  4. * data from each slice in to one ndarray
  5. * which will then take the specified shape
  6. *
  7. * @param slices the slices to merge
  8. * @param shape the shape of the ndarray
  9. */
  10. public BaseNDArray(List<INDArray> slices, int[] shape, char ordering) {
  11. this(slices, shape, Nd4j.getStrides(shape, ordering), ordering);
  12. }

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

  1. /**
  2. * Create an ndrray with the specified shape
  3. *
  4. * @param data the data to use with tne ndarray
  5. * @param shape the shape of the ndarray
  6. * @return the created ndarray
  7. */
  8. @Override
  9. public INDArray create(double[] data, int[] shape) {
  10. return create(data, shape, Nd4j.getStrides(shape), 0);
  11. }

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

  1. @Override
  2. public INDArray create(float[] data, long[] shape) {
  3. //ensure shapes that wind up being scalar end up with the write shape
  4. if (shape.length == 1 && shape[0] == 0) {
  5. shape = new long[] {1, 1};
  6. }
  7. return create(data, shape, Nd4j.getStrides(shape), 0);
  8. }

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

  1. @Override
  2. public INDArray create(double[] data, long[] shape) {
  3. //ensure shapes that wind up being scalar end up with the write shape
  4. if (shape.length == 1 && shape[0] == 0) {
  5. shape = new long[] {1, 1};
  6. }
  7. return create(data, shape, Nd4j.getStrides(shape), 0);
  8. }

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

  1. /**
  2. * Create with the specified shape and buffer
  3. *
  4. * @param shape the shape
  5. * @param buffer the buffer
  6. */
  7. public BaseNDArray(int[] shape, DataBuffer buffer) {
  8. this.data = buffer;
  9. init(shape, Nd4j.getStrides(shape));
  10. }

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

  1. /**
  2. * Get the strides based on the shape
  3. * and NDArrays.order()
  4. *
  5. * @param shape the shape of the ndarray
  6. * @return the strides for the given shape
  7. * and order specified by NDArrays.order()
  8. */
  9. public static int[] getStrides(int[] shape) {
  10. return getStrides(shape, Nd4j.order());
  11. }

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

  1. /**
  2. * Get the strides based on the shape
  3. * and NDArrays.order()
  4. *
  5. * @param shape the shape of the ndarray
  6. * @return the strides for the given shape
  7. * and order specified by NDArrays.order()
  8. */
  9. public static long[] getStrides(long[] shape) {
  10. return getStrides(shape, Nd4j.order());
  11. }

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

  1. /**
  2. * Calculate the strides based on the given indices
  3. *
  4. * @param ordering the ordering to calculate strides for
  5. * @param indexes the indices to calculate stride for
  6. * @return the strides for the given indices
  7. */
  8. public static int[] strides(char ordering, NDArrayIndex... indexes) {
  9. return Nd4j.getStrides(shape(indexes), ordering);
  10. }

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

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

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

  1. /**
  2. * Creates an ndarray with the specified shape
  3. *
  4. * @param shape the shape of the ndarray
  5. * @return the instance
  6. */
  7. @Override
  8. public INDArray create(long[] shape) {
  9. //ensure shapes that wind up being scalar end up with the write shape
  10. return create(shape, Nd4j.getStrides(shape), 0L);
  11. }

代码示例来源: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. /**
  2. *
  3. * @param data
  4. * @param shape
  5. */
  6. public BaseNDArray(DataBuffer data, int[] shape) {
  7. this(data, shape, Nd4j.getStrides(shape, Nd4j.order()), 0, Nd4j.order());
  8. }

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

  1. @Override
  2. public INDArray create(float[] data, int[] shape, char ordering) {
  3. //ensure shapes that wind up being scalar end up with the write shape
  4. if (shape.length == 1 && shape[0] == 0) {
  5. shape = new int[] {1, 1};
  6. }
  7. return create(Nd4j.createBuffer(data), shape, Nd4j.getStrides(shape, ordering), 0, ordering);
  8. }

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

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

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

  1. /**
  2. *
  3. * @param buffer
  4. * @param shape
  5. * @param offset
  6. */
  7. public BaseNDArray(DataBuffer buffer, int[] shape, long offset) {
  8. this(Nd4j.createBuffer(buffer, offset, ArrayUtil.prodLong(shape)), shape, Nd4j.getStrides(shape), offset,
  9. Nd4j.order());
  10. }

代码示例来源: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. }

相关文章