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

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

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

Nd4j.createUninitialized介绍

[英]This method creates an uninitialized ndarray of specified length and default ordering. PLEASE NOTE: Do not use this method unless you're 100% sure why you use it.
[中]此方法创建指定长度和默认顺序的未初始化数据数组。请注意:除非你100%确定为什么要使用这种方法,否则不要使用这种方法。

代码示例

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

  1. @Override
  2. public INDArray nextGaussian(char order, int[] shape) {
  3. INDArray array = Nd4j.createUninitialized(shape, order);
  4. GaussianDistribution op = new GaussianDistribution(array, 0.0, 1.0);
  5. Nd4j.getExecutioner().exec(op, this);
  6. return array;
  7. }

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

  1. @Override
  2. public INDArray nextGaussian(char order, long[] shape) {
  3. INDArray array = Nd4j.createUninitialized(shape, order);
  4. GaussianDistribution op = new GaussianDistribution(array, 0.0, 1.0);
  5. Nd4j.getExecutioner().exec(op, this);
  6. return array;
  7. }

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

  1. @Override
  2. public INDArray nextDouble(char order, int[] shape) {
  3. INDArray array = Nd4j.createUninitialized(shape, order);
  4. UniformDistribution op = new UniformDistribution(array, 0.0, 1.0);
  5. Nd4j.getExecutioner().exec(op, this);
  6. return array;
  7. }

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

  1. @Override
  2. public INDArray nextFloat(char order, long[] shape) {
  3. INDArray array = Nd4j.createUninitialized(shape, order);
  4. UniformDistribution op = new UniformDistribution(array, 0.0, 1.0);
  5. Nd4j.getExecutioner().exec(op, this);
  6. return array;
  7. }

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

  1. @Override
  2. public INDArray nextFloat(char order, int[] shape) {
  3. INDArray array = Nd4j.createUninitialized(shape, order);
  4. UniformDistribution op = new UniformDistribution(array, 0.0, 1.0);
  5. Nd4j.getExecutioner().exec(op, this);
  6. return array;
  7. }

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

  1. @Override
  2. public INDArray nextDouble(char order, long[] shape) {
  3. INDArray array = Nd4j.createUninitialized(shape, order);
  4. UniformDistribution op = new UniformDistribution(array, 0.0, 1.0);
  5. Nd4j.getExecutioner().exec(op, this);
  6. return array;
  7. }

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

  1. /**
  2. * Atan2 operation, new INDArray instance will be returned
  3. * Note the order of x and y parameters is opposite to that of java.lang.Math.atan2
  4. *
  5. * @param x the abscissa coordinate
  6. * @param y the ordinate coordinate
  7. * @return the theta from point (r, theta) when converting (x,y) from to cartesian to polar coordinates
  8. */
  9. public static INDArray atan2(@NonNull INDArray x, @NonNull INDArray y) {
  10. return Nd4j.getExecutioner()
  11. .execAndReturn(new OldAtan2Op(x, y, Nd4j.createUninitialized(x.shape(), x.ordering())));
  12. }

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

  1. public static INDArray and(INDArray x, INDArray y) {
  2. INDArray z = Nd4j.createUninitialized(x.shape(), x.ordering());
  3. Nd4j.getExecutioner().exec(new And(x, y, z, 0.0));
  4. return z;
  5. }

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

  1. public static INDArray not(INDArray x) {
  2. INDArray z = Nd4j.createUninitialized(x.shape(), x.ordering());
  3. Nd4j.getExecutioner().exec(new Not(x, z, 0.0));
  4. return z;
  5. }

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

  1. public static INDArray xor(INDArray x, INDArray y) {
  2. INDArray z = Nd4j.createUninitialized(x.shape(), x.ordering());
  3. Nd4j.getExecutioner().exec(new Xor(x, y, z, 0.0));
  4. return z;
  5. }

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

  1. public static INDArray or(INDArray x, INDArray y) {
  2. INDArray z = Nd4j.createUninitialized(x.shape(), x.ordering());
  3. Nd4j.getExecutioner().exec(new Or(x, y, z, 0.0));
  4. return z;
  5. }

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

  1. /**
  2. * Negate each element.
  3. */
  4. @Override
  5. public INDArray neg() {
  6. return Nd4j.getExecutioner().exec(new Negative(this, Nd4j.createUninitialized(this.shape(), this.ordering())))
  7. .z();
  8. }

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

  1. public static INDArray reverse(INDArray x, boolean dup) {
  2. return Nd4j.getExecutioner().exec(new OldReverse(x, dup ? Nd4j.createUninitialized(x.shape(), x.ordering()) : x))
  3. .z();
  4. }

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

  1. /**
  2. * Like the scipy function tri.
  3. * From the scipy documentation:
  4. * An array with ones at and below the given diagonal and zeros elsewhere.
  5. * @param n number of rows in the array
  6. * @param m number of columns in the array ( can be just equal to n)
  7. * @param k The sub-diagonal at and below which the array is filled.
  8. `k` = 0 is the main diagonal, while `k` < 0 is below it,
  9. and `k` > 0 is above. The default is 0.
  10. * @return
  11. */
  12. public static INDArray tri(int n,int m,int k) {
  13. /*
  14. INDArray mRet = Transforms.greaterThanOrEqual(arange(n),arange(-k,m - k));
  15. return mRet;
  16. */
  17. INDArray ret = Nd4j.createUninitialized(n, m);
  18. val op = DynamicCustomOp.builder("tri")
  19. .addIntegerArguments(n, m, k)
  20. .addOutputs(ret)
  21. .build();
  22. Nd4j.getExecutioner().exec(op);
  23. return ret;
  24. }

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

  1. /**
  2. * Meshgrid op. Returns a pair of arrays where values are broadcast on a 2d grid.<br>
  3. * For example, if x = [1,2,3,4] and y = [5,6,7], then:<br>
  4. * out[0] =<br>
  5. * [1,2,3,4]<br>
  6. * [1,2,3,4]<br>
  7. * [1,2,3,4]<br>
  8. * <br>
  9. * out[1] =<br>
  10. * [5,5,5,5]<br>
  11. * [6,6,6,6]<br>
  12. * [7,7,7,7]<br>
  13. * <br>
  14. *
  15. * @param x X array input
  16. * @param y Y array input
  17. * @return INDArray[] of length 2, shape [y.length, x.length]
  18. */
  19. public static INDArray[] meshgrid(@NonNull INDArray x, @NonNull INDArray y){
  20. Preconditions.checkArgument(x.isVectorOrScalar(), "X must be a vector");
  21. Preconditions.checkArgument(y.isVectorOrScalar(), "Y must be a vector");
  22. INDArray xOut = Nd4j.createUninitialized(y.length(), x.length());
  23. INDArray yOut = Nd4j.createUninitialized(y.length(), x.length());
  24. CustomOp op = DynamicCustomOp.builder("meshgrid")
  25. .addInputs(x, y)
  26. .addOutputs(xOut, yOut)
  27. .build();
  28. Nd4j.getExecutioner().exec(op);
  29. return new INDArray[]{xOut, yOut};
  30. }

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

  1. INDArray result = Nd4j.createUninitialized(m.shape());
  2. .build();
  3. Nd4j.getExecutioner().exec(op);

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

  1. return Nd4j.createUninitialized(shape).assign(this.getDouble(0));
  2. Nd4j.getExecutioner().exec(new Tile(new INDArray[]{this.dup(this.ordering())},new INDArray[]{result},repeat));
  3. } else
  4. Nd4j.getExecutioner().exec(new Tile(new INDArray[]{this},new INDArray[]{result},repeat));

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

  1. int oW = (int) Math.ceil(img.size(3) * 1.f / sx);
  2. output = Nd4j.createUninitialized(new long[] {img.size(0), img.size(1), kh, kw, oH, oW}, 'c');
  3. int oW = ((int) img.size(3) - (kw + (kw-1)*(1-1)) + 2*pw)/sx + 1;
  4. output = Nd4j.createUninitialized(new long[] {img.size(0), img.size(1), kh, kw, oH, oW}, 'c');
  5. .build()).build();
  6. Nd4j.getExecutioner().exec(im2col);
  7. return im2col.outputArguments()[0];

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

  1. Nd4j.getExecutioner().commit();
  2. Nd4j.getExecutioner().commit();
  3. DataBuffer buffer = Nd4j.createBuffer(this.lengthLong(), false);
  4. INDArray copy = Nd4j.createUninitialized(this.shape(), this.ordering());
  5. copy.assign(this);
  6. Nd4j.getExecutioner().commit();
  7. copy = Nd4j.createUninitialized(this.shape(), this.ordering());
  8. copy.assign(this);
  9. Nd4j.getExecutioner().commit();

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

  1. /**
  2. * in place addition of two matrices
  3. *
  4. * @param other the second ndarray to add
  5. * @param result the result ndarray
  6. * @return the result of the addition
  7. */
  8. @Override
  9. public INDArray addi(INDArray other, INDArray result) {
  10. if (other.isScalar()) {
  11. return result.addi(other.getDouble(0), result);
  12. }
  13. if (isScalar()) {
  14. return other.addi(getDouble(0), result);
  15. }
  16. if(!Shape.shapeEquals(this.shape(),other.shape())) {
  17. int[] broadcastDimensions = Shape.getBroadcastDimensions(this.shape(),other.shape());
  18. result = Nd4j.createUninitialized(Shape.broadcastOutputShape(this.shape(),other.shape()));
  19. Nd4j.getExecutioner().exec(new BroadcastAddOp(this,other,result,broadcastDimensions),broadcastDimensions);
  20. return result;
  21. }
  22. LinAlgExceptions.assertSameShape(other, result);
  23. Nd4j.getExecutioner().exec(new OldAddOp(this, other, result, length()));
  24. if (Nd4j.ENFORCE_NUMERICAL_STABILITY)
  25. Nd4j.clearNans(result);
  26. return result;
  27. }

相关文章