Example usage for java.lang Double BYTES

List of usage examples for java.lang Double BYTES

Introduction

In this page you can find the example usage for java.lang Double BYTES.

Prototype

int BYTES

To view the source code for java.lang Double BYTES.

Click Source Link

Document

The number of bytes used to represent a double value.

Usage

From source file:com.px100systems.util.serialization.DataStream.java

public void writeDouble(Double data) {
    try {/*from  w  w  w.  ja va2s .  co  m*/
        if (data == null)
            dos.writeInt(NULL);
        else {
            dos.writeInt(Double.BYTES);
            dos.writeDouble(data);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.spotify.heroic.metric.bigtable.BigtableBackend.java

ByteString serializeValue(double value) {
    final ByteBuffer buffer = ByteBuffer.allocate(Double.BYTES).putLong(Double.doubleToLongBits(value));
    return ByteString.copyFrom(buffer.array());
}

From source file:com.act.lcms.v2.TraceIndexExtractor.java

private static byte[] serializeDoubleList(List<Double> vals) throws IOException {
    try (ByteArrayOutputStream bos = new ByteArrayOutputStream(vals.size() * Double.BYTES)) {
        byte[] bytes = new byte[Double.BYTES];
        for (Double val : vals) {
            bos.write(ByteBuffer.wrap(bytes).putDouble(val).array());
        }/*from  w  w w  . ja v  a  2s .co  m*/
        return bos.toByteArray();
    }
}

From source file:com.act.lcms.v2.TraceIndexExtractor.java

private static List<Double> deserializeDoubleList(byte[] byteStream) throws IOException {
    List<Double> results = new ArrayList<>(byteStream.length / Double.BYTES);
    try (ByteArrayInputStream is = new ByteArrayInputStream(byteStream)) {
        byte[] bytes = new byte[Double.BYTES];
        while (is.available() > 0) {
            int readBytes = is.read(bytes); // Same as read(bytes, 0, bytes.length)
            if (readBytes != bytes.length) {
                throw new RuntimeException(
                        String.format("Couldn't read a whole double at a time: %d", readBytes));
            }/*from  w w w  . jav  a2 s .c om*/
            results.add(ByteBuffer.wrap(bytes).getDouble());
        }
    }
    return results;
}

From source file:org.apache.sysml.runtime.matrix.data.DoublePrecisionCudaSupportFunctions.java

@Override
public void deviceToHost(GPUContext gCtx, Pointer src, double[] dest, String instName, boolean isEviction) {
    long t1 = DMLScript.FINEGRAINED_STATISTICS && instName != null ? System.nanoTime() : 0;
    if (src == null)
        throw new DMLRuntimeException("The source pointer in deviceToHost is null");
    if (dest == null)
        throw new DMLRuntimeException("The destination array in deviceToHost is null");
    if (LOG.isDebugEnabled()) {
        LOG.debug("deviceToHost: src of size " + gCtx.getMemoryManager().getSizeAllocatedGPUPointer(src)
                + " (in bytes) -> dest of size " + (dest.length * Double.BYTES) + " (in bytes).");
    }//from   www .jav  a  2  s. com
    cudaMemcpy(Pointer.to(dest), src, ((long) dest.length) * Sizeof.DOUBLE, cudaMemcpyDeviceToHost);
    if (DMLScript.FINEGRAINED_STATISTICS && instName != null)
        GPUStatistics.maintainCPMiscTimes(instName, GPUInstruction.MISC_TIMER_DEVICE_TO_HOST,
                System.nanoTime() - t1);
}

From source file:org.apache.sysml.utils.PersistentLRUCache.java

public ValueWrapper put(String key, double[] value) throws FileNotFoundException, IOException {
    return putImplm(key, new ValueWrapper(new DataWrapper(key, value, this), isInReadOnlyMode),
            value.length * Double.BYTES);
}

From source file:org.apache.sysml.utils.PersistentLRUCache.java

static DataWrapper loadDoubleArr(String key, PersistentLRUCache cache)
        throws FileNotFoundException, IOException {
    if (cache.isInReadOnlyMode)
        throw new DMLRuntimeException("Read-only mode is only supported for MatrixBlock.");
    if (!cache.persistedKeys.contains(key))
        throw new DMLRuntimeException("Cannot load the key that has not been persisted: " + key);
    if (PersistentLRUCache.LOG.isDebugEnabled())
        PersistentLRUCache.LOG.debug("Loading double array the key " + key + " from the disk.");
    double[] ret;
    try (ObjectInputStream is = new ObjectInputStream(new FileInputStream(cache.getFilePath(key)))) {
        int size = is.readInt();
        cache.ensureCapacity(size * Double.BYTES);
        ret = new double[size];
        for (int i = 0; i < size; i++) {
            ret[i] = is.readDouble();// www  .  j  ava  2  s  . c  o m
        }
    }
    return new DataWrapper(key, ret, cache);
}

From source file:org.apache.sysml.utils.PersistentLRUCache.java

long getSize() {
    if (_dArr != null)
        return _dArr.length * Double.BYTES;
    else if (_fArr != null)
        return _fArr.length * Float.BYTES;
    else if (_mb != null)
        return _mb.getInMemorySize();
    else/*  ww w . jav a2s . c o  m*/
        throw new DMLRuntimeException("Not implemented");
}