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

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

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

Nd4j.getCompressor介绍

[英]This method returns BasicNDArrayCompressor instance, suitable for NDArray compression/decompression at runtime
[中]此方法返回BasicNDArrayCompressor实例,适用于运行时的NDArray压缩/解压缩

代码示例

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

  1. /**
  2. *
  3. * @param img
  4. * @param kernel
  5. * @param stride
  6. * @param padding
  7. * @return
  8. */
  9. public static INDArray im2col(INDArray img, int[] kernel, int[] stride, int[] padding) {
  10. Nd4j.getCompressor().autoDecompress(img);
  11. return im2col(img, kernel[0], kernel[1], stride[0], stride[1], padding[0], padding[1], 0, false);
  12. }

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

  1. /**
  2. * Replaces all elements in this ndarray that are matching give condition, with corresponding elements from given array
  3. *
  4. * @param arr
  5. * @param condition
  6. * @return
  7. */
  8. @Override
  9. public INDArray replaceWhere(INDArray arr, Condition condition) {
  10. Nd4j.getCompressor().autoDecompress(this);
  11. BooleanIndexing.replaceWhere(this, arr, condition);
  12. return this;
  13. }

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

  1. @Override
  2. public INDArray put(INDArrayIndex[] indices, Number element) {
  3. Nd4j.getCompressor().autoDecompress(this);
  4. INDArray get = get(indices);
  5. for (int i = 0; i < get.length(); i++)
  6. get.putScalar(i, element.doubleValue());
  7. return this;
  8. }

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

  1. /**
  2. * Returns the (euclidean) distance.
  3. */
  4. @Override
  5. public double distance2(INDArray other) {
  6. Nd4j.getCompressor().autoDecompress(this);
  7. return Nd4j.getExecutioner().execAndReturn(new EuclideanDistance(this, other)).getFinalResult().doubleValue();
  8. }

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

  1. /**
  2. * Returns the (1-norm) distance.
  3. */
  4. @Override
  5. public double distance1(INDArray other) {
  6. Nd4j.getCompressor().autoDecompress(this);
  7. return Nd4j.getExecutioner().execAndReturn(new ManhattanDistance(this, other)).getFinalResult().doubleValue();
  8. }

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

  1. @Override
  2. public INDArray putScalar(long row, long col, double value) {
  3. Nd4j.getCompressor().autoDecompress(this);
  4. autoProcessScalarCall();
  5. if (rank() > 2)
  6. throw new IllegalStateException("Cannot use putScalar(int,int,double) on a rank " + rank() + " INDArray");
  7. long offset = Shape.getOffsetUnsafe(javaShapeInformation, row, col);
  8. data.put(offset, value);
  9. return this;
  10. }

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

  1. @Override
  2. public INDArray putScalar(long dim0, long dim1, long dim2, long dim3, double value) {
  3. Nd4j.getCompressor().autoDecompress(this);
  4. autoProcessScalarCall();
  5. if (rank() != 4)
  6. throw new IllegalStateException(
  7. "Cannot use putScalar(int,int,int,int,double) on a rank " + rank() + " INDArray");
  8. long offset = Shape.getOffsetUnsafe(javaShapeInformation, dim0, dim1, dim2, dim3);
  9. data.put(offset, value);
  10. return this;
  11. }

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

  1. @Override
  2. public INDArray putScalar(long dim0, long dim1, long dim2, double value) {
  3. Nd4j.getCompressor().autoDecompress(this);
  4. autoProcessScalarCall();
  5. if (rank() != 3)
  6. throw new IllegalStateException(
  7. "Cannot use putScalar(int,int,int,double) on a rank " + rank() + " INDArray");
  8. long offset = 0; // Shape.getOffsetUnsafe(javaShapeInformation, dim0, dim1, dim2);
  9. long size_0 = javaShapeInformation[1];
  10. long size_1 = javaShapeInformation[1 + 1];
  11. long size_2 = javaShapeInformation[1 + 2];
  12. if (size_0 != 1)
  13. offset += dim0 * javaShapeInformation[1 + 0 + 3];
  14. if (size_1 != 1)
  15. offset += dim1 * javaShapeInformation[1 + 1 + 3];
  16. if (size_2 != 1)
  17. offset += dim2 * javaShapeInformation[1 + 2 + 3];
  18. data.put(offset, value);
  19. return this;
  20. }

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

  1. @Override
  2. public INDArray condi(Condition condition) {
  3. Nd4j.getCompressor().autoDecompress(this);
  4. INDArray linear = this;
  5. for (int i = 0; i < length(); i++) {
  6. boolean met = condition.apply(linear.getDouble(i));
  7. linear.putScalar(i, met ? 1 : 0);
  8. }
  9. return this;
  10. }

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

  1. protected void checkForCompression(Op op) {
  2. // check for INT datatype arrays
  3. interceptIntDataType(op);
  4. if (op.x() != null && op.x().isCompressed())
  5. Nd4j.getCompressor().decompressi(op.x());
  6. if (op.y() != null && op.y().isCompressed())
  7. Nd4j.getCompressor().decompressi(op.y());
  8. if (op.z() != null && op.z().isCompressed())
  9. Nd4j.getCompressor().decompressi(op.z());
  10. }

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

  1. @Override
  2. public INDArray putWhere(INDArray comp, INDArray put, Condition condition) {
  3. Nd4j.getCompressor().autoDecompress(this);
  4. MatchConditionTransform matchCondition = new MatchConditionTransform(this,comp,condition);
  5. Nd4j.getExecutioner().exec(matchCondition);
  6. return putWhereWithMask(matchCondition.z(),put);
  7. }

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

  1. /**
  2. * Get the specified column
  3. *
  4. * @param c
  5. */
  6. @Override
  7. public INDArray getColumn(long c) {
  8. Nd4j.getCompressor().autoDecompress(this);
  9. if (isColumnVector() && c == 0)
  10. return this;
  11. else if (isColumnVector() && c > 0)
  12. throw new IllegalArgumentException("Illegal index for row");
  13. else if(isRowVector()) {
  14. return Nd4j.scalar(getDouble(c));
  15. }
  16. return get(NDArrayIndex.all(), NDArrayIndex.point(c));
  17. }

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

  1. @Override
  2. public INDArray dup() {
  3. WorkspaceUtils.assertValidArray(this, "Cannot duplicate INDArray");
  4. if (this.isCompressed() && this.ordering() == Nd4j.order().charValue()) {
  5. INDArray ret = Nd4j.createArrayFromShapeBuffer(data().dup(), this.shapeInfoDataBuffer());
  6. ret.markAsCompressed(true);
  7. return ret;
  8. }
  9. Nd4j.getCompressor().autoDecompress(this);
  10. INDArray ret = Shape.toOffsetZeroCopy(this);
  11. return ret;
  12. }

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

  1. /**
  2. * Insert a column in to this array
  3. * Will throw an exception if this
  4. * ndarray is not a matrix
  5. *
  6. * @param column the column to insert
  7. * @param toPut the array to put
  8. * @return this
  9. */
  10. @Override
  11. public INDArray putColumn(int column, INDArray toPut) {
  12. Nd4j.getCompressor().autoDecompress(this);
  13. if (isColumnVector() && toPut.isVector()) {
  14. return assign(toPut);
  15. }
  16. return put(new INDArrayIndex[] {NDArrayIndex.all(), NDArrayIndex.point(column)}, toPut);
  17. }

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

  1. @Override
  2. public double getDouble(long i) {
  3. Nd4j.getCompressor().autoDecompress(this);
  4. if (i >= length()) {
  5. throw new IllegalArgumentException("Unable to get linear index >= " + length());
  6. }
  7. autoProcessScalarCall();
  8. if (i == 0)
  9. return data().getDouble(i);
  10. long[] dimensions = ordering() == 'c' ? Shape.ind2subC(this, i) : Shape.ind2sub(this, i);
  11. Shape.assertShapeLessThan(dimensions, shape());
  12. return getDouble(dimensions);
  13. }

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

  1. public static INDArray im2col(INDArray img, int kh, int kw, int sy, int sx, int ph, int pw, int dh, int dw, boolean isSameMode) {
  2. Nd4j.getCompressor().autoDecompress(img);
  3. //Input: NCHW format
  4. // FIXME: int cast
  5. int outH = outputSize((int) img.size(2), kh, sy, ph, dh, isSameMode);
  6. int outW = outputSize((int) img.size(3), kw, sx, pw, dw, isSameMode);
  7. //[miniBatch,depth,kH,kW,outH,outW]
  8. INDArray out = Nd4j.create(new long[]{img.size(0), img.size(1), kh, kw, outH, outW}, 'c');
  9. return im2col(img, kh, kw, sy, sx, ph, pw, dh, dw, isSameMode, out);
  10. }

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

  1. /**
  2. * Flattens the array for linear indexing
  3. *
  4. * @return the flattened version of this array
  5. */
  6. @Override
  7. public INDArray ravel(char ordering) {
  8. Nd4j.getCompressor().autoDecompress(this);
  9. if (length() >= Integer.MAX_VALUE)
  10. throw new IllegalArgumentException("Length can not be >= Integer.MAX_VALUE");
  11. INDArray ret = create(new int[] {1, (int) length()}, ordering);
  12. NDArrayIndex index = new NDArrayIndex(this.shape());
  13. for (int i = 0; i < length(); i++) {
  14. // FIXME: LONG
  15. double val = getDouble((int) index.next());
  16. ret.putScalar(new int[] {0, i}, val);
  17. }
  18. return ret;
  19. }

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

  1. @Override
  2. public INDArray dup(char order) {
  3. WorkspaceUtils.assertValidArray(this, "Cannot duplicate INDArray");
  4. if (this.isCompressed() && this.ordering() == order) {
  5. INDArray ret = Nd4j.createArrayFromShapeBuffer(data().dup(), this.shapeInfoDataBuffer());
  6. ret.markAsCompressed(true);
  7. return ret;
  8. }
  9. Nd4j.getCompressor().autoDecompress(this);
  10. return Shape.toOffsetZeroCopy(this, order);
  11. }

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

  1. @Override
  2. public INDArray put(INDArrayIndex[] indices, INDArray element) {
  3. Nd4j.getCompressor().autoDecompress(this);
  4. if (indices[0] instanceof SpecifiedIndex && element.isVector()) {
  5. indices[0].reset();
  6. int cnt = 0;
  7. while (indices[0].hasNext()) {
  8. long idx = indices[0].next();
  9. // FIXME: LONG
  10. putScalar((int) idx, element.getDouble(cnt));
  11. cnt++;
  12. }
  13. return this;
  14. } else {
  15. return get(indices).assign(element);
  16. }
  17. }

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

  1. /**
  2. * Replicate and tile array to fill out to the given shape
  3. * See:
  4. * https://github.com/numpy/numpy/blob/master/numpy/matlib.py#L310-L358
  5. * @param shape the new shape of this ndarray
  6. * @return the shape to fill out to
  7. */
  8. @Override
  9. public INDArray repmat(int[] shape) {
  10. Nd4j.getCompressor().autoDecompress(this);
  11. long rows = rows() * shape[0];
  12. long cols = columns() * shape[1];
  13. INDArray ret = reshape(1, length()).repeat(0, shape[0]).reshape(rows, columns()).repeat(0, shape[1]);
  14. return ret.reshape(rows, cols);
  15. }

相关文章