Example usage for java.lang Float SIZE

List of usage examples for java.lang Float SIZE

Introduction

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

Prototype

int SIZE

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

Click Source Link

Document

The number of bits used to represent a float value.

Usage

From source file:org.apache.pig.impl.util.avro.AvroTupleWrapper.java

@SuppressWarnings({ "rawtypes", "unchecked" })
private long getMemorySize(final IndexedRecord r) {
    int total = 0;
    final int bitsPerByte = 8;
    for (Field f : r.getSchema().getFields()) {
        switch (f.schema().getType()) {
        case BOOLEAN:
        case ENUM:
        case INT:
            total += Integer.SIZE << bitsPerByte;
            break;
        case DOUBLE:
            total += Double.SIZE << bitsPerByte;
            break;
        case FLOAT:
            total += Float.SIZE << bitsPerByte;
            break;
        case NULL:
            break;
        case STRING:
            total += ((String) r.get(f.pos())).length() * (Character.SIZE << bitsPerByte);
            break;
        case BYTES:
            total += ((Byte[]) r.get(f.pos())).length;
            break;
        case RECORD:
            total += new AvroTupleWrapper((IndexedRecord) r.get(f.pos())).getMemorySize();
            break;
        case ARRAY:
            total += new AvroBagWrapper((GenericArray) r.get(f.pos())).getMemorySize();
            break;
        }//from www  . ja  v  a 2 s .c  o  m
    }
    return total;
}

From source file:org.apache.sqoop.connector.idf.CSVIntermediateDataFormat.java

/**
 * {@inheritDoc}//from   www  . j  a  va  2 s . com
 */
@Override
public Object[] getObjectData() {
    if (schema.isEmpty()) {
        throw new SqoopException(IntermediateDataFormatError.INTERMEDIATE_DATA_FORMAT_0006);
    }

    String[] fields = getFields();

    if (fields == null) {
        return null;
    }

    if (fields.length != schema.getColumns().size()) {
        throw new SqoopException(IntermediateDataFormatError.INTERMEDIATE_DATA_FORMAT_0005,
                "The data " + getTextData() + " has the wrong number of fields.");
    }

    Object[] out = new Object[fields.length];
    Column[] cols = schema.getColumns().toArray(new Column[fields.length]);
    for (int i = 0; i < fields.length; i++) {
        Type colType = cols[i].getType();
        if (fields[i].equals("NULL")) {
            out[i] = null;
            continue;
        }

        Long byteSize;
        switch (colType) {
        case TEXT:
            out[i] = unescapeStrings(fields[i]);
            break;
        case BINARY:
            out[i] = unescapeByteArray(fields[i]);
            break;
        case FIXED_POINT:
            byteSize = ((FixedPoint) cols[i]).getByteSize();
            if (byteSize != null && byteSize <= Integer.SIZE) {
                out[i] = Integer.valueOf(fields[i]);
            } else {
                out[i] = Long.valueOf(fields[i]);
            }
            break;
        case FLOATING_POINT:
            byteSize = ((FloatingPoint) cols[i]).getByteSize();
            if (byteSize != null && byteSize <= Float.SIZE) {
                out[i] = Float.valueOf(fields[i]);
            } else {
                out[i] = Double.valueOf(fields[i]);
            }
            break;
        case DECIMAL:
            out[i] = new BigDecimal(fields[i]);
            break;
        case DATE:
            out[i] = LocalDate.parse(fields[i]);
            break;
        case DATE_TIME:
            // A datetime string with a space as date-time separator will not be
            // parsed expectedly. The expected separator is "T". See also:
            // https://github.com/JodaOrg/joda-time/issues/11
            String iso8601 = fields[i].replace(" ", "T");
            out[i] = LocalDateTime.parse(iso8601);
            break;
        case BIT:
            out[i] = Boolean.valueOf(fields[i].equals("1") || fields[i].toLowerCase().equals("true"));
            break;
        default:
            throw new SqoopException(IntermediateDataFormatError.INTERMEDIATE_DATA_FORMAT_0004,
                    "Column type from schema was not recognized for " + colType);
        }
    }
    return out;
}

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 w w .j a  v  a 2  s .com
        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/*from  w  w  w  .j  a v  a  2 s.c o  m*/
 * @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//from  w ww .ja v  a 2 s.  co  m
 * @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.nd4j.linalg.util.ArrayUtil.java

/**
 *
 * @param doubleArray/*  w w w .j  av a2  s.com*/
 * @return
 */
public static byte[] toByteArray(float[] doubleArray) {
    int times = Float.SIZE / Byte.SIZE;
    byte[] bytes = new byte[doubleArray.length * times];
    for (int i = 0; i < doubleArray.length; i++) {
        ByteBuffer.wrap(bytes, i * times, times).putFloat(doubleArray[i]);
    }
    return bytes;
}

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

/**
 *
 * @param byteArray/*from   ww  w.j  a  va2 s .  co m*/
 * @return
 */
public static float[] toFloatArray(byte[] byteArray) {
    int times = Float.SIZE / Byte.SIZE;
    float[] doubles = new float[byteArray.length / times];
    for (int i = 0; i < doubles.length; i++) {
        doubles[i] = ByteBuffer.wrap(byteArray, i * times, times).getFloat();
    }
    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 w  w. j a v a2s.  co  m
    } 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;
}

From source file:spectrogram.Spectrogram.java

/**
 * The controller of the process loop, init -> get data -> process -> make image
 * @return /*from w ww  . ja v  a  2s  .co  m*/
 * @throws viewerconfig.ViewConfigException 
 * @throws edu.fullerton.jspWebUtils.WebUtilException 
 * @throws edu.fullerton.ndsproxyclient.NDSException 
 */
public int doPlot() throws ViewConfigException, WebUtilException, NDSException {
    int ret = 0;
    long xfernt = 0;
    long procnt = 0;

    try {
        startMs = System.currentTimeMillis();
        initProgress();
        initChanInfo();
        initImage();
        initCache();
        if (debugLevel > 1) {
            System.out.format("\nChan: %1$s, sample rate: ", channelName);
            if (sampleRate >= 1) {
                System.out.format("%1$.0f", sampleRate);
            } else {
                System.out.format("%1$.3f", sampleRate);
            }
            System.out.format(", bytes/sample: %1$1d%n", bytesPerSample);
            System.out.format("Sec/fft: %1$.2f, overlap: %2$.2f%n", secPerFFT, overlap);
        }

        int stride = duration / 100;
        int maxStride = (int) (1000000 / sampleRate);
        stride = Math.max(stride, minStride);
        stride = Math.min(stride, duration);
        stride = Math.min(stride, maxStride);

        bufn = 0;
        boolean wantsToCancel = false;

        if (useAltData) {
            int stopSample = (int) (duration * sampleRate);

            if (!testDataFilename.isEmpty()) {
                readAddTestData(testDataFile);
            } else if (!rawDataFilename.isEmpty()) {
                readAddRawData();
            } else {
                noData(0, stopSample);
            }
        } else {
            int stride2 = duration;

            for (int curT = 0; curT < duration && !wantsToCancel; curT += stride2) {
                long xStrt = System.nanoTime();
                setProgress(String.format("Processing %1$,4d of %2$,4d seconds of data", curT, duration));
                setProgress(curT, duration);
                int curgps = startGPS + curT;
                int curDur = stride;
                if (curDur + curgps > startGPS + duration) {
                    curDur = startGPS + duration - curgps;
                }
                try {
                    ndsClient = new NDSProxyClient(server);
                    ndsClient.connect();

                    boolean reqStat = ndsClient.requestData(channelName, chanInfo.getcType(), curgps,
                            curgps + duration, stride);
                    if (reqStat) {
                        // for the first buffer we get channel information from NDS2 and 
                        // adjust accordingly
                        int dt = (int) (ndsClient.getStartGPS() - startGPS);
                        setProgress(String.format("Processing %1$,4d of %2$,4d seconds of data", dt, duration));
                        setProgress(dt, duration);
                        NDSBufferStatus bufferStatus = ndsClient.getBufferStatus();
                        if (sampleRate != bufferStatus.getFs()) {
                            sampleRate = bufferStatus.getFs();
                            initImage();
                            initCache();
                        }
                        if (fmax == 0) {
                            fmax = sampleRate / 2;
                        }

                        int startSample = (int) (dt * sampleRate);
                        int nsample = (int) (duration * sampleRate);
                        long pStrt = System.nanoTime();
                        xfernt += pStrt - xStrt;

                        addBuf(startSample, nsample);
                        procnt += System.nanoTime() - pStrt;

                        bufn++;
                        wantsToCancel = checkCancel();
                    } else {
                        String msg = ndsClient.getLastError();
                        wantsToCancel = true;
                        System.err.format("Transfer error: %s\n", msg);
                        ret = 2;
                    }
                    ndsClient.bye();
                    ndsClient = null;
                } catch (Exception ex) {
                    xferErrMsg = ex.getClass().getSimpleName() + ": " + ex.getMessage();
                    if (!checkNoData(curgps, curDur, xferErrMsg)) {
                        wantsToCancel = true;
                        System.err.format("Transfer error: %s\n", xferErrMsg);
                        ret = 2;
                    }
                    try {
                        //ndsClient.disconnect();
                        ndsClient.bye();
                        ndsClient = null;
                    } catch (Exception ex2) {
                        // Ignore error in error handler
                    }
                }
            }
        }
        if (wantsToCancel) {
            if (spectraCache.size() > nfft / 4) {
                status = "Shortened";
            } else {
                status = "Canceled";
            }
            status += " by user or because of error";
            if (xferErrMsg == null || xferErrMsg.isEmpty()) {
                xferErrMsg = status;
            } else {
                xferErrMsg += " - " + status;
            }

        } else {
            status = "Success";
        }
        long mkimgnt = 0;
        if (spectraCache.size() > nfft / 4) {
            long mkimgStrt = System.nanoTime();
            makeImage();
            mkimgnt = System.nanoTime() - mkimgStrt;
        } else if (spectraCache.size() == 0) {
            System.err.println("Unable to transfer data.  Last error received: " + xferErrMsg);
            ret = 3;
        } else {
            System.err.println("Some data transfered but not enough spectra to make an image ("
                    + Integer.toString(spectraCache.size()) + ")");
            System.err.println("Last error received: " + xferErrMsg);
            ret = 4;
        }
        // timing info
        double elapsedSec = (System.currentTimeMillis() - startMs) / 1000.;
        long bytes = (long) (duration * sampleRate * Float.SIZE / 8);
        double rateKBps = bytes / elapsedSec / 1000;
        System.out.format("Run time: %1$.2fs, total bytes xfer: %2$,d, process rate %3$.1f KBps%n", elapsedSec,
                bytes, rateKBps);
        double xfersec = xfernt / 1.0e9;
        double procsec = procnt / 1.0e9;
        double mkimgsec = mkimgnt / 1.0e9;
        double ovhdsec = elapsedSec - xfersec - procsec - mkimgsec;
        System.out.format("Transfer: %1$.2f, process: %2$.2f, image: %3$.2f, overhead: %4$.2f %n", xfersec,
                procsec, mkimgsec, ovhdsec);
    } catch (LdvTableException | SQLException | IOException | IllegalArgumentException ex) {
        status = "Error: " + ex.getClass().getSimpleName() + ": " + ex.getLocalizedMessage();
        System.err.println(ex.toString());
        ret = 5;
    }
    closeProgress();
    return ret;
}

From source file:spectrogram.Spectrogram.java

private void initChanInfo() throws LdvTableException, SQLException, ViewConfigException, WebUtilException {
    if (!useAltData) {
        setProgress("Getting Channel info.");

        getDbTables();/*w  w w.  jav  a 2 s  .co  m*/

        setProgress("Getting Channel info.");
        if (!getChanInfo()) {
            System.exit(1);
        }
    } else {
        // test data can either be no data or input from a csv file
        testDataFile = null;
        rawDataFile = null;
        if (rawDataFilename.isEmpty() && testDataFilename.isEmpty()) {
            channelName = "No data (labels only)";
        } else if (!testDataFilename.isEmpty()) {
            testDataFile = new File(testDataFilename);
            channelName = testDataFile.getName();
            bytesPerSample = Float.SIZE / 8;
        } else if (!rawDataFilename.isEmpty()) {
            Pattern fnPat = Pattern.compile("(.*/)?(.+)-(\\d+)-(\\d+).dat");
            Matcher fnMat = fnPat.matcher(rawDataFilename);
            if (!fnMat.find()) {
                throw new WebUtilException("Raw data file not named corrrectly.");
            }
            channelName = fnMat.group(2);
            startGPS = Integer.parseInt(fnMat.group(3));
            duration = Integer.parseInt(fnMat.group(4));
            bytesPerSample = Float.SIZE / 8;
        }

    }
    setProgress("Starting transfer.");
}