java.nio.DoubleBuffer#array ( )源码实例Demo

下面列出了java.nio.DoubleBuffer#array ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: libcommon   文件: ChannelHelper.java
/**
 * ByteChannelからdouble配列を読み込む
 * @param channel
 * @return
 * @throws IOException
 */
public static double[] readDoubleArray(@NonNull final ByteChannel channel)
	throws IOException {
	
	final int n = readInt(channel);
	final ByteBuffer buf = ByteBuffer.allocate(n * 8).order(ByteOrder.BIG_ENDIAN);
	final int readBytes = channel.read(buf);
	if (readBytes != n * 8) throw new IOException();
	buf.clear();
	final DoubleBuffer result = buf.asDoubleBuffer();
	if (result.hasArray()) {
		return result.array();
	}  else {
		final double[] b = new double[n];
		result.get(b);
		return b;
	}
}
 
源代码2 项目: OpenDA   文件: ThriftBmiBridge.java
private static double[] bufferToDoubleArray(ByteBuffer buffer) {
	buffer.order(ByteOrder.nativeOrder());
	DoubleBuffer doubles = buffer.asDoubleBuffer();

	if (doubles.hasArray()) {
		return doubles.array();
	} else {
		double[] resultArray = new double[doubles.capacity()];
		doubles.get(resultArray);
		return resultArray;
	}
}
 
源代码3 项目: powsybl-core   文件: StoredDoubleTimeSeries.java
@Override
public double[] toArray() {
    DoubleBuffer buffer = DoubleBuffer.allocate(metadata.getIndex().getPointCount());
    for (int i = 0; i < metadata.getIndex().getPointCount(); i++) {
        buffer.put(i, Double.NaN);
    }
    fillBuffer(buffer, 0);
    return buffer.array();
}
 
源代码4 项目: jpmml-tensorflow   文件: TensorUtil.java
static
public double[] toDoubleArray(Tensor tensor){
	DoubleBuffer doubleBuffer = DoubleBuffer.allocate(tensor.numElements());

	tensor.writeTo(doubleBuffer);

	return doubleBuffer.array();
}
 
源代码5 项目: tapir   文件: DoublePointer.java
/**
 * For direct buffers, calls {@link Pointer#Pointer(Buffer)}, while for buffers
 * backed with an array, allocates enough memory for the array and copies it.
 *
 * @param buffer the Buffer to reference or copy
 * @see #put(double[])
 */
public DoublePointer(DoubleBuffer buffer) {
    super(buffer);
    if (buffer != null && buffer.hasArray()) {
        double[] array = buffer.array();
        allocateArray(array.length);
        put(array);
        position(buffer.position());
        limit(buffer.limit());
    }
}
 
源代码6 项目: datacollector   文件: DoubleTensorTypeSupport.java
@Override
public List<Field> createListField(Tensor<Double> tensor, DoubleBuffer doubleBuffer) {
  List<Field> fields = new ArrayList<>();
  tensor.writeTo(doubleBuffer);
  double[] doubles = doubleBuffer.array();
  for (double aDouble : doubles) {
    fields.add(Field.create(aDouble));
  }
  return fields;
}
 
源代码7 项目: zoltar   文件: JTensor.java
/**
 * Create a new {@link JTensor} instance by extracting data from the underlying {@link Tensor} and
 * closing it afterwards.
 */
public static JTensor create(final Tensor<?> tensor) {
  final JTensor jt;
  try {
    switch (tensor.dataType()) {
      case STRING:
        if (tensor.numDimensions() == 0) {
          final String value = new String(tensor.bytesValue(), UTF_8);
          jt =
              new AutoValue_JTensor(
                  tensor.dataType(), tensor.numDimensions(), tensor.shape(), value);
        } else {
          final int[] dimensions = toIntExact(tensor.shape());
          final Object byteArray =
              tensor.copyTo(Array.newInstance(byte[].class, toIntExact(tensor.shape())));
          jt =
              new AutoValue_JTensor(
                  tensor.dataType(),
                  tensor.numDimensions(),
                  tensor.shape(),
                  toStringArray(byteArray, tensor.numElements(), dimensions));
        }
        break;
      case INT32:
        final IntBuffer intBuf = IntBuffer.allocate(tensor.numElements());
        tensor.writeTo(intBuf);
        jt =
            new AutoValue_JTensor(
                tensor.dataType(), tensor.numDimensions(), tensor.shape(), intBuf.array());
        break;
      case INT64:
        final LongBuffer longBuf = LongBuffer.allocate(tensor.numElements());
        tensor.writeTo(longBuf);
        jt =
            new AutoValue_JTensor(
                tensor.dataType(), tensor.numDimensions(), tensor.shape(), longBuf.array());
        break;
      case FLOAT:
        final FloatBuffer floatBuf = FloatBuffer.allocate(tensor.numElements());
        tensor.writeTo(floatBuf);
        jt =
            new AutoValue_JTensor(
                tensor.dataType(), tensor.numDimensions(), tensor.shape(), floatBuf.array());
        break;
      case DOUBLE:
        final DoubleBuffer doubleBuf = DoubleBuffer.allocate(tensor.numElements());
        tensor.writeTo(doubleBuf);
        jt =
            new AutoValue_JTensor(
                tensor.dataType(), tensor.numDimensions(), tensor.shape(), doubleBuf.array());
        break;
      case BOOL:
        final boolean[] array = new boolean[tensor.numElements()];
        tensor.copyTo(array);
        jt =
            new AutoValue_JTensor(
                tensor.dataType(), tensor.numDimensions(), tensor.shape(), array);
        break;
      default:
        throw new IllegalStateException("Unsupported data type " + tensor.dataType());
    }
  } finally {
    tensor.close();
  }

  return jt;
}
 
源代码8 项目: powsybl-core   文件: CalculatedTimeSeries.java
@Override
public double[] toArray() {
    DoubleBuffer buffer = DoubleBuffer.allocate(metadata.getIndex().getPointCount());
    fillBuffer(buffer, 0);
    return buffer.array();
}