Example usage for java.lang Double SIZE

List of usage examples for java.lang Double SIZE

Introduction

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

Prototype

int SIZE

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

Click Source Link

Document

The number of bits used to represent a double value.

Usage

From source file:org.bdval.cache.TableCache.java

/**
 * Retrieve a cached table from the cache. isTableCached should be called
 * before calling this to verify that the table is cached. Null will
 * be returned if the table wasn't in the cache or there was a problem
 * reading the table.//  w  w  w . jav  a  2 s. co m
 *
 * @param splitId        The split id
 * @param splitType      The Split type
 * @param datasetName    The dataset name
 * @param geneListFilter A gene list. If not null, the gene list is queried with each double
 * column identifier to determine if the identifier is contained in the gene list. Columns
 * that do not match the gene list are not loaded.
 * @return the table read from the cache (or null if it could not be read)
 */
public Table getCachedTable(final int splitId, final String splitType, final String datasetName,
        final GeneList geneListFilter) {
    final File cachedTableFile = getCachedTableFile(splitId, splitType, datasetName);

    if (geneListFilter != null && !(geneListFilter instanceof FullGeneList)) {
        final ObjectSet<CharSequence> tableColumnIds = getTableColumnIds(splitId, splitType, datasetName);
        geneListFilter.calculateProbeSetSelection(tableColumnIds);
    }
    DataInputStream dataInput = null;
    try {
        dataInput = new DataInputStream(new FastBufferedInputStream(new FileInputStream(cachedTableFile)));
        final ArrayTable result = new ArrayTable();
        final int numberOfColumns = dataInput.readInt();
        LOG.info("Reading cached table with " + numberOfColumns + " columns");
        for (int i = 0; i < numberOfColumns; i++) {
            final String colType = dataInput.readUTF();
            final String colId = dataInput.readUTF();

            if ("s".equals(colType)) {
                final int numStrings = dataInput.readInt();
                resize(result, numStrings);
                final int columnIndex = result.addColumn(colId, String.class);
                for (int j = 0; j < numStrings; j++) {
                    result.appendObject(columnIndex, dataInput.readUTF());
                }
            } else if ("d".equals(colType)) {
                final int numDoubles = dataInput.readInt();
                resize(result, numDoubles);
                if (geneListFilter != null && !geneListFilter.isProbesetInList(colId)) {
                    // the column does not match the gene list. Skip this column
                    // we don't need to read these doubles, just skip them;
                    final int numBytes = Double.SIZE * numDoubles / 8;
                    final int actualBytes = dataInput.skipBytes(numBytes);
                    if (actualBytes != numBytes) {
                        LOG.warn("actual bytes skipped (" + actualBytes + ") does" + "not equal expected of "
                                + numBytes);
                    }
                    continue;
                }

                final int columnIndex = result.addColumn(colId, double.class);
                for (int j = 0; j < numDoubles; j++) {
                    result.appendDoubleValue(columnIndex, dataInput.readDouble());
                }

            } else {
                LOG.error("UNKNOWN COLUMN TYPE " + colType + " cannot read cached table from file "
                        + filenameOf(cachedTableFile));
                return null;
            }
        }
        return result;
    } catch (IOException e) {
        LOG.error(e);
        return null;
    } catch (TypeMismatchException e) {
        LOG.error("TypeMismatchException adding data to Table " + filenameOf(cachedTableFile), e);
        return null;
    } finally {
        IOUtils.closeQuietly(dataInput);
    }
}

From source file:org.bdval.cache.TableCache.java

public ObjectSet<CharSequence> getTableColumnIds(final int splitId, final String splitType,
        final String datasetName) {
    final File cachedTableFile = getCachedTableFile(splitId, splitType, datasetName);
    final ObjectSet<CharSequence> result = new ObjectOpenHashSet<CharSequence>();
    DataInputStream dataInput = null;
    try {/*w w  w.  j av a 2  s .  com*/
        dataInput = new DataInputStream(new FastBufferedInputStream(new FileInputStream(cachedTableFile)));
        final int numberOfColumns = dataInput.readInt();
        LOG.info("Reading cached table with " + numberOfColumns + " columns");
        for (int i = 0; i < numberOfColumns; i++) {
            final String colType = dataInput.readUTF();
            final String colId = dataInput.readUTF();

            result.add(colId);

            if ("s".equals(colType)) {
                final int numStrings = dataInput.readInt();

                for (int j = 0; j < numStrings; j++) {
                    dataInput.readUTF();
                }
            } else if ("d".equals(colType)) {
                final int numDoubles = dataInput.readInt();
                // we don't need to read these doubles, just skip them;
                final int numBytes = Double.SIZE * numDoubles / 8;
                final int actualBytes = dataInput.skipBytes(numBytes);
                if (actualBytes != numBytes) {
                    LOG.warn("actual bytes skipped (" + actualBytes + ") does " + "not equal expected of "
                            + numBytes);
                }
            } else {
                LOG.error("UNKNOWN COLUMN TYPE " + colType + " cannot read cached table from file "
                        + filenameOf(cachedTableFile));
                return null;
            }
        }
        return result;
    } catch (IOException e) {
        LOG.error("Error getting column ids", e);
        return null;
    } finally {
        IOUtils.closeQuietly(dataInput);
    }
}

From source file:org.cellprofiler.subimager.ImageWriterHandler.java

private byte[] convertImage(NDImage ndimage, PixelType pixelType, boolean toBigEndian) {
    double[] inputDouble = ndimage.getBuffer();
    switch (pixelType) {
    case INT8://from w ww .  j  a  v  a  2  s. c o m
        return convertToIntegerType(inputDouble, Byte.MIN_VALUE, Byte.MAX_VALUE, Byte.SIZE / 8, toBigEndian);
    case UINT8:
        return convertToIntegerType(inputDouble, 0, (1L << Byte.SIZE) - 1, Byte.SIZE / 8, toBigEndian);
    case INT16:
        return convertToIntegerType(inputDouble, Short.MIN_VALUE, Short.MAX_VALUE, Short.SIZE / 8, toBigEndian);
    case UINT16:
        return convertToIntegerType(inputDouble, 0, (1L << Short.SIZE) - 1, Short.SIZE / 8, toBigEndian);
    case INT32:
        return convertToIntegerType(inputDouble, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.SIZE / 8,
                toBigEndian);
    case UINT32:
        return convertToIntegerType(inputDouble, 0, (1L << Integer.SIZE) - 1, Integer.SIZE / 8, toBigEndian);
    case FLOAT: {
        int bpp = Float.SIZE / 8;
        byte[] buffer = new byte[inputDouble.length * bpp];
        for (int i = 0; i < inputDouble.length; i++) {
            DataTools.unpackBytes(Float.floatToIntBits((float) inputDouble[i]), buffer, i * bpp, bpp,
                    !toBigEndian);
        }
        return buffer;
    }
    case DOUBLE: {
        int bpp = Double.SIZE / 8;
        byte[] buffer = new byte[inputDouble.length * bpp];
        for (int i = 0; i < inputDouble.length; i++) {
            DataTools.unpackBytes(Double.doubleToLongBits(inputDouble[i]), buffer, i * bpp, bpp, !toBigEndian);
        }
        return buffer;
    }
    default:
        throw new UnsupportedOperationException("The pixel type, " + pixelType.getValue()
                + ", should have been explicitly handled by the caller and an error should have been reported to the web client.");
    }
}

From source file:org.eclipse.dataset.AbstractDataset.java

/**
 * @param dtype/*w  w w.ja v  a2 s  .  c  om*/
 * @param isize
 *            number of elements in an item
 * @return length of single item in bytes
 */
public static int getItemsize(final int dtype, final int isize) {
    int size;

    switch (dtype) {
    case BOOL:
        size = 1; // How is this defined?
        break;
    case INT8:
    case ARRAYINT8:
        size = Byte.SIZE / 8;
        break;
    case INT16:
    case ARRAYINT16:
    case RGB:
        size = Short.SIZE / 8;
        break;
    case INT32:
    case ARRAYINT32:
        size = Integer.SIZE / 8;
        break;
    case INT64:
    case ARRAYINT64:
        size = Long.SIZE / 8;
        break;
    case FLOAT32:
    case ARRAYFLOAT32:
    case COMPLEX64:
        size = Float.SIZE / 8;
        break;
    case FLOAT64:
    case ARRAYFLOAT64:
    case COMPLEX128:
        size = Double.SIZE / 8;
        break;
    default:
        size = 0;
        break;
    }

    return size * isize;
}

From source file:org.eclipse.january.dataset.DTypeUtils.java

/**
 * @param dtype//w w  w  . j  ava  2s. c  om
 * @param isize
 *            number of elements in an item
 * @return length of single item in bytes
 */
public static int getItemBytes(final int dtype, final int isize) {
    int size;

    switch (dtype) {
    case Dataset.BOOL:
        size = 1; // How is this defined?
        break;
    case Dataset.INT8:
    case Dataset.ARRAYINT8:
        size = Byte.SIZE / 8;
        break;
    case Dataset.INT16:
    case Dataset.ARRAYINT16:
    case Dataset.RGB:
        size = Short.SIZE / 8;
        break;
    case Dataset.INT32:
    case Dataset.ARRAYINT32:
        size = Integer.SIZE / 8;
        break;
    case Dataset.INT64:
    case Dataset.ARRAYINT64:
        size = Long.SIZE / 8;
        break;
    case Dataset.FLOAT32:
    case Dataset.ARRAYFLOAT32:
    case Dataset.COMPLEX64:
        size = Float.SIZE / 8;
        break;
    case Dataset.FLOAT64:
    case Dataset.ARRAYFLOAT64:
    case Dataset.COMPLEX128:
        size = Double.SIZE / 8;
        break;
    default:
        size = 0;
        break;
    }

    return size * isize;
}

From source file:org.mitre.math.linear.BufferRealMatrix.java

/**
 * Create a new matrix with the supplied row and column dimensions.
 *
 * @param rows      the number of rows in the new matrix
 * @param columns   the number of columns in the new matrix
 * @param file      the file to use to store the mapped matrix (<code>null</code> allowed and a tempFile will be created)
 * @throws IllegalArgumentException//w ww  .j  ava 2s.c o  m
 * @throws IOException
 */
public BufferRealMatrix(final int rows, final int columns, File file)
        throws IllegalArgumentException, IOException {
    super(rows, columns);
    this.rows = rows;
    this.columns = columns;

    // number of blocks
    this.blockRows = (rows + BLOCK_SIZE - 1) / BLOCK_SIZE;
    this.blockColumns = (columns + BLOCK_SIZE - 1) / BLOCK_SIZE;

    if (file == null) {
        file = File.createTempFile(TEMP_FILE_PREFIX, null);
        LOG.debug(String.format("Created tempFile '%s'", file.getAbsolutePath()));
    }
    RandomAccessFile raf = new RandomAccessFile(file, "rw");
    this.dataFileChannel = raf.getChannel();

    long mbbSize = (long) (Double.SIZE / Byte.SIZE) * (long) rows * (long) columns + BUFFER_HEADER_SIZE;
    LOG.debug(String.format("Matrix size will be %d bytes and %d by %d blocks", mbbSize, this.blockRows,
            this.blockColumns));

    MappedByteBuffer bb = this.dataFileChannel.map(FileChannel.MapMode.READ_WRITE, 0, BUFFER_HEADER_SIZE);
    bb.clear();
    bb.putInt(BLOCK_BYTE_SIZE);
    bb.putInt(rows);
    bb.putInt(columns);
    // note: we don't create the layout like BlockedRealMatrix
    // Is this set to zeros? It would be a pain/slow to init it if it is realy big
}

From source file:org.nd4j.linalg.util.ArrayUtil.java

/**
 *
 * @param doubleArray/* w w  w .j  av a2 s .c  o  m*/
 * @return
 */
public static byte[] toByteArray(double[] doubleArray) {
    int times = Double.SIZE / Byte.SIZE;
    byte[] bytes = new byte[doubleArray.length * times];
    for (int i = 0; i < doubleArray.length; i++) {
        ByteBuffer.wrap(bytes, i * times, times).putDouble(doubleArray[i]);
    }
    return bytes;
}

From source file:org.nd4j.linalg.util.ArrayUtil.java

/**
 *
 * @param byteArray//from   ww  w  .j a va 2 s.c o m
 * @return
 */
public static double[] toDoubleArray(byte[] byteArray) {
    int times = Double.SIZE / Byte.SIZE;
    double[] doubles = new double[byteArray.length / times];
    for (int i = 0; i < doubles.length; i++) {
        doubles[i] = ByteBuffer.wrap(byteArray, i * times, times).getDouble();
    }
    return doubles;
}

From source file:org.wso2.carbon.analytics.datasource.core.util.GenericUtils.java

private static int calculateBufferSizePerElement(String name, Object value) throws AnalyticsException {
    int count = 0;
    /* column name length value + data type (including null) */
    count += Integer.SIZE / 8 + 1;
    /* column name */
    count += name.getBytes(StandardCharsets.UTF_8).length;
    if (value instanceof String) {
        /* string length + value */
        count += Integer.SIZE / 8;
        count += ((String) value).getBytes(StandardCharsets.UTF_8).length;
    } else if (value instanceof Long) {
        count += Long.SIZE / 8;//from   w  ww. j  av a 2  s .c om
    } else if (value instanceof Double) {
        count += Double.SIZE / 8;
    } else if (value instanceof Boolean) {
        count += Byte.SIZE / 8;
    } else if (value instanceof Integer) {
        count += Integer.SIZE / 8;
    } else if (value instanceof Float) {
        count += Float.SIZE / 8;
    } else if (value instanceof byte[]) {
        count += Integer.SIZE / 8;
        count += ((byte[]) value).length;
    } else if (value != null) {
        count += Integer.SIZE / 8;
        count += GenericUtils.serializeObject(value).length;
    }
    return count;
}