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

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

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

Nd4j.createArrayFromShapeBuffer介绍

暂无

代码示例

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

public abstract DataBuffer decompress(DataBuffer buffer);

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

/**
 * Read in an ndarray from a data input stream
 *
 * @param dis the data input stream to read from
 * @return the ndarray
 * @throws IOException
 */
public static INDArray read(DataInputStream dis) throws IOException {
  DataBuffer shapeInformation = Nd4j.createBufferDetached(new long[1], DataBuffer.Type.LONG);
  shapeInformation.read(dis);
  int length = Shape.length(shapeInformation);
  DataBuffer data = CompressedDataBuffer.readUnknown(dis, length);
  return createArrayFromShapeBuffer(data, shapeInformation);
}

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

INDArray arr = Nd4j.createArrayFromShapeBuffer(buff.dup(), shapeBuff.dup());
  return Pair.of(arr, byteBuffer);
} else {
      new CompressedDataBuffer(byteBufferPointer, compressionDescriptor);
  INDArray arr = Nd4j.createArrayFromShapeBuffer(compressedDataBuffer.dup(), shapeBuff.dup());

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

@Override
public INDArray bitmapEncode(INDArray indArray, double threshold) {
  DataBuffer buffer = Nd4j.getDataBufferFactory().createInt(indArray.length() / 16 + 5);
  INDArray ret = Nd4j.createArrayFromShapeBuffer(buffer, indArray.shapeInfoDataBuffer());
  bitmapEncode(indArray, ret, threshold);
  return ret;
}

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

/**
 * This method creates compressed INDArray from Java float array, skipping usual INDArray instantiation routines
 *
 * @param data
 * @param shape
 * @param order
 * @return
 */
@Override
public INDArray compress(float[] data, int[] shape, char order) {
  FloatPointer pointer = new FloatPointer(data);
  DataBuffer shapeInfo = Nd4j.getShapeInfoProvider().createShapeInformation(shape, order).getFirst();
  DataBuffer buffer = compressPointer(DataBuffer.TypeEx.FLOAT, pointer, data.length, 4);
  return Nd4j.createArrayFromShapeBuffer(buffer, shapeInfo);
}

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

/**
 * This method creates compressed INDArray from Java double array, skipping usual INDArray instantiation routines
 *
 * @param data
 * @param shape
 * @param order
 * @return
 */
@Override
public INDArray compress(double[] data, int[] shape, char order) {
  DoublePointer pointer = new DoublePointer(data);
  DataBuffer shapeInfo = Nd4j.getShapeInfoProvider().createShapeInformation(shape, order).getFirst();
  DataBuffer buffer = compressPointer(DataBuffer.TypeEx.DOUBLE, pointer, data.length, 8);
  return Nd4j.createArrayFromShapeBuffer(buffer, shapeInfo);
}

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

@Override
public INDArray dup() {
  WorkspaceUtils.assertValidArray(this, "Cannot duplicate INDArray");
  if (this.isCompressed() && this.ordering() == Nd4j.order().charValue()) {
    INDArray ret = Nd4j.createArrayFromShapeBuffer(data().dup(), this.shapeInfoDataBuffer());
    ret.markAsCompressed(true);
    return ret;
  }
  Nd4j.getCompressor().autoDecompress(this);
  INDArray ret = Shape.toOffsetZeroCopy(this);
  return ret;
}

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

@Override
public INDArray getrf(INDArray A) {
  // FIXME: int cast
  if (A.rows() > Integer.MAX_VALUE || A.columns() > Integer.MAX_VALUE)
    throw new ND4JArraySizeException();
  int m = (int) A.rows();
  int n = (int) A.columns();
  INDArray INFO = Nd4j.createArrayFromShapeBuffer(Nd4j.getDataBufferFactory().createInt(1),
          Nd4j.getShapeInfoProvider().createShapeInformation(new int[] {1, 1}).getFirst());
  int mn = Math.min(m, n);
  INDArray IPIV = Nd4j.createArrayFromShapeBuffer(Nd4j.getDataBufferFactory().createInt(mn),
          Nd4j.getShapeInfoProvider().createShapeInformation(new int[] {1, mn}).getFirst());
  if (A.data().dataType() == DataBuffer.Type.DOUBLE)
    dgetrf(m, n, A, IPIV, INFO);
  else if (A.data().dataType() == DataBuffer.Type.FLOAT)
    sgetrf(m, n, A, IPIV, INFO);
  else
    throw new UnsupportedOperationException();
  if (INFO.getInt(0) < 0) {
    throw new Error("Parameter #" + INFO.getInt(0) + " to getrf() was not valid");
  } else if (INFO.getInt(0) > 0) {
    log.warn("The matrix is singular - cannot be used for inverse op. Check L matrix at row " + INFO.getInt(0));
  }
  return IPIV;
}

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

@Override
public INDArray dup(char order) {
  WorkspaceUtils.assertValidArray(this, "Cannot duplicate INDArray");
  if (this.isCompressed() && this.ordering() == order) {
    INDArray ret = Nd4j.createArrayFromShapeBuffer(data().dup(), this.shapeInfoDataBuffer());
    ret.markAsCompressed(true);
    return ret;
  }
  Nd4j.getCompressor().autoDecompress(this);
  return Shape.toOffsetZeroCopy(this, order);
}

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

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

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

@Override
public void potrf(INDArray A, boolean lower) {
  // FIXME: int cast
  if (A.columns() > Integer.MAX_VALUE)
    throw new ND4JArraySizeException();
  byte uplo = (byte) (lower ? 'L' : 'U'); // upper or lower part of the factor desired ?
  int n = (int) A.columns();
  INDArray INFO = Nd4j.createArrayFromShapeBuffer(Nd4j.getDataBufferFactory().createInt(1),
          Nd4j.getShapeInfoProvider().createShapeInformation(new int[] {1, 1}).getFirst());
  if (A.data().dataType() == DataBuffer.Type.DOUBLE)
    dpotrf(uplo, n, A, INFO);
  else if (A.data().dataType() == DataBuffer.Type.FLOAT)
    spotrf(uplo, n, A, INFO);
  else
    throw new UnsupportedOperationException();
  if (INFO.getInt(0) < 0) {
    throw new Error("Parameter #" + INFO.getInt(0) + " to potrf() was not valid");
  } else if (INFO.getInt(0) > 0) {
    throw new Error("The matrix is not positive definite! (potrf fails @ order " + INFO.getInt(0) + ")");
  }
  return;
}

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

@Override
public INDArray convertToDoubles() {
  if (data.dataType() == DataBuffer.Type.DOUBLE)
    return this;
  val factory = Nd4j.getNDArrayFactory();
  val buffer = Nd4j.createBuffer(new long[]{this.length()}, DataBuffer.Type.DOUBLE);
  factory.convertDataEx(convertType(data.dataType()), this.data().addressPointer(), DataBuffer.TypeEx.DOUBLE, buffer.addressPointer(), buffer.length());
  return Nd4j.createArrayFromShapeBuffer(buffer, this.shapeInformation);
}

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

@Override
public void gesvd(INDArray A, INDArray S, INDArray U, INDArray VT) {
  // FIXME: int cast
  if (A.rows() > Integer.MAX_VALUE || A.columns() > Integer.MAX_VALUE)
    throw new ND4JArraySizeException();
  int m = (int) A.rows();
  int n = (int) A.columns();
  byte jobu = (byte) (U == null ? 'N' : 'A');
  byte jobvt = (byte) (VT == null ? 'N' : 'A');
  INDArray INFO = Nd4j.createArrayFromShapeBuffer(Nd4j.getDataBufferFactory().createInt(1),
          Nd4j.getShapeInfoProvider().createShapeInformation(new int[] {1, 1}).getFirst());
  if (A.data().dataType() == DataBuffer.Type.DOUBLE)
    dgesvd(jobu, jobvt, m, n, A, S, U, VT, INFO);
  else if (A.data().dataType() == DataBuffer.Type.FLOAT)
    sgesvd(jobu, jobvt, m, n, A, S, U, VT, INFO);
  else
    throw new UnsupportedOperationException();
  if (INFO.getInt(0) < 0) {
    throw new Error("Parameter #" + INFO.getInt(0) + " to gesvd() was not valid");
  } else if (INFO.getInt(0) > 0) {
    log.warn("The matrix contains singular elements. Check S matrix at row " + INFO.getInt(0));
  }
}

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

@Override
public void geqrf(INDArray A, INDArray R) {
  // FIXME: int cast
  if (A.rows() > Integer.MAX_VALUE || A.columns() > Integer.MAX_VALUE)
    throw new ND4JArraySizeException();
  int m = (int) A.rows();
  int n = (int) A.columns();
  INDArray INFO = Nd4j.createArrayFromShapeBuffer(Nd4j.getDataBufferFactory().createInt(1),
          Nd4j.getShapeInfoProvider().createShapeInformation(new int[] {1, 1}).getFirst());
  if (R.rows() != A.columns() || R.columns() != A.columns()) {
    throw new Error("geqrf: R must be N x N (n = columns in A)");
  }
  if (A.data().dataType() == DataBuffer.Type.DOUBLE) {
    dgeqrf(m, n, A, R, INFO);
  } else if (A.data().dataType() == DataBuffer.Type.FLOAT) {
    sgeqrf(m, n, A, R, INFO);
  } else {
    throw new UnsupportedOperationException();
  }
  if (INFO.getInt(0) < 0) {
    throw new Error("Parameter #" + INFO.getInt(0) + " to getrf() was not valid");
  }
}

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

Nd4j.getMemoryManager().memcpy(buffer, this.data());
  copy = Nd4j.createArrayFromShapeBuffer(buffer, this.shapeInfoDataBuffer());
} else {
  copy = this.dup(this.ordering());

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

return Nd4j.createArrayFromShapeBuffer(buffer, this.shapeInfoDataBuffer());
} else {
  INDArray copy = Nd4j.createUninitialized(this.shape(), this.ordering());
  copy = Nd4j.createArrayFromShapeBuffer(buffer, this.shapeInfoDataBuffer()); //this.dup(this.ordering());

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

Nd4j.getMemoryManager().memcpy(buffer, this.data());
  copy = Nd4j.createArrayFromShapeBuffer(buffer, this.shapeInfoDataBuffer());
} else {
  copy = this.dup(this.ordering());

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

Nd4j.getMemoryManager().memcpy(buffer, this.data());
  copy = Nd4j.createArrayFromShapeBuffer(buffer, this.shapeInfoDataBuffer());
} else {
  copy = this.dup(this.ordering());

代码示例来源:origin: org.nd4j/nd4j-api

@Override
public INDArray bitmapEncode(INDArray indArray, double threshold) {
  DataBuffer buffer = Nd4j.getDataBufferFactory().createInt(indArray.length() / 16 + 5);
  INDArray ret = Nd4j.createArrayFromShapeBuffer(buffer, indArray.shapeInfoDataBuffer());
  bitmapEncode(indArray, ret, threshold);
  return ret;
}

代码示例来源:origin: org.nd4j/nd4j-cuda-10.0

@Override
public INDArray compress(INDArray array) {
  //logger.info("Threshold [{}] compression", threshold);
  Nd4j.getExecutioner().commit();
  //Nd4j.getAffinityManager().ensureLocation(array, AffinityManager.Location.HOST);
  DataBuffer buffer = compress(array.data());
  if (buffer == null)
    return null;
  INDArray dup = Nd4j.createArrayFromShapeBuffer(buffer, array.shapeInfoDataBuffer());
  dup.markAsCompressed(true);
  return dup;
}

相关文章