List of usage examples for java.lang Float SIZE
int SIZE
To view the source code for java.lang Float SIZE.
Click Source Link
From source file:Main.java
public static void main(String[] args) { System.out.println("SIZE:" + Float.SIZE); }
From source file:Main.java
/** * create a Floatbuffer for a given Array * @param array/*from w w w.j a va2s . c o m*/ * @return */ public static FloatBuffer createFloatBuffer(float[] array) { final int floatSize = Float.SIZE / 8; ByteBuffer byteBuffer = ByteBuffer.allocateDirect(array.length * floatSize); byteBuffer.order(ByteOrder.nativeOrder()); FloatBuffer floatBuffer = byteBuffer.asFloatBuffer(); floatBuffer.put(array); floatBuffer.position(0); return floatBuffer; }
From source file:Main.java
public static FloatBuffer makeFloatBuffer(int length) { final int floatSize = Float.SIZE / 8; ByteBuffer byteBuffer = ByteBuffer.allocateDirect(length * floatSize); byteBuffer.order(ByteOrder.nativeOrder()); FloatBuffer floatBuffer = byteBuffer.asFloatBuffer(); floatBuffer.position(0);//from w ww .j av a2 s . c o m return floatBuffer; }
From source file:Main.java
public static FloatBuffer makeFloatBuffer(float[] array) { final int floatSize = Float.SIZE / 8; ByteBuffer byteBuffer = ByteBuffer.allocateDirect(array.length * floatSize); byteBuffer.order(ByteOrder.nativeOrder()); FloatBuffer floatBuffer = byteBuffer.asFloatBuffer(); floatBuffer.put(array);/*from w w w .j a va 2 s . c o m*/ floatBuffer.position(0); return floatBuffer; }
From source file:com.linkedin.pinot.core.segment.memory.PinotDataBufferTest.java
private static void loadVerifyFloat(PinotDataBuffer buffer) { final int fieldSize = Float.SIZE / 8; int maxElementCount = (int) (buffer.size() / fieldSize); int elemCount = Math.min(100_000, maxElementCount); Map<Integer, Float> positionValues = new HashMap<>(); for (long i = 0; i < elemCount; i++) { int pos = random.nextInt(elemCount); float val = random.nextFloat(); positionValues.put(pos, val); buffer.putFloat(pos * fieldSize, val); }//from ww w. j a va2 s. c o m for (Map.Entry<Integer, Float> entry : positionValues.entrySet()) { Assert.assertEquals(buffer.getFloat(entry.getKey() * fieldSize), (float) entry.getValue(), "Failure at index: " + entry.getKey()); } }
From source file:com.moscona.dataSpace.Numeric.java
@Override public long sizeInBytes() { if (value == null) { return 2L; }/*from w ww . ja v a2 s . com*/ if (value.getClass() == Double.class) { return 2L + Double.SIZE / 8; } if (value.getClass() == Float.class) { return 2L + Float.SIZE / 8; } if (value.getClass() == Long.class) { return 2L + Long.SIZE / 8; } if (value.getClass() == Integer.class) { return 2L + Integer.SIZE / 8; } if (value.getClass() == Short.class) { return 2L + Short.SIZE / 8; } if (value.getClass() == Byte.class) { return 2L + Byte.SIZE / 8; } return 2L; }
From source file:indexer.DocVector.java
byte[] getVecBytes(float[] x) { ByteBuffer buff = ByteBuffer.allocate(Float.SIZE * x.length); for (float xval : x) buff.putFloat(xval);/*from w ww. j a v a 2s. co m*/ byte[] bytes = buff.array(); return bytes; }
From source file:it.unimi.dsi.webgraph.algo.HyperBall.java
private long usedMemory() { long bytes = 0; for (long[] a : bits) bytes += a.length * ((long) Long.SIZE / Byte.SIZE); if (!external) bytes *= 2;/*from w w w.j av a2 s . c o m*/ if (sumOfDistances != null) bytes += sumOfDistances.length * ((long) Float.SIZE / Byte.SIZE); if (sumOfInverseDistances != null) bytes += sumOfInverseDistances.length * ((long) Float.SIZE / Byte.SIZE); for (int i = discountFunction.length; i-- != 0;) bytes += discountedCentrality[i].length * ((long) Float.SIZE / Byte.SIZE); // We use bits, so usedMemory() can be called before allocation. if (modifiedCounter != null) bytes += modifiedCounter.length; if (modifiedResultCounter != null) bytes += modifiedResultCounter.length; if (nextMustBeChecked != null) bytes += nextMustBeChecked.length; if (mustBeChecked != null) bytes += mustBeChecked.length; return bytes; }
From source file:odcplot.OdcPlot.java
/** * Create specified plots/*from www .j a v a 2s. c o m*/ * @throws edu.fullerton.jspWebUtils.WebUtilException * @throws viewerconfig.ViewConfigException */ public void doPlot() throws WebUtilException, ViewConfigException { try { startMs = System.currentTimeMillis(); initProgress(); setProgress("Getting Channel info."); getDbTables(); setProgress("Getting Channel info."); if (!getChanInfo()) { System.exit(1); } setProgress("Starting transfer."); getBitNames(channelName); long nSamples = 0; if (!infilename.isEmpty()) { nSamples = setupFileReads(); } initImage(); long singleBufMs = 0; long multipleBufMs = 0; long nBytes = 0; long strtMs = System.currentTimeMillis(); bufn = 0; boolean wantsToCancel = false; boolean ret; if (useTestData) { int stopSample = (int) (duration * sampleRate); noData(data, 0, stopSample, (byte) 3); } else if (!infilename.isEmpty()) { try { addBuf(data, 0, nSamples); } catch (NDSException ex) { throw new WebUtilException("Reading from file", ex); } } else { try { ndsClient = new NDSProxyClient(server); ndsClient.connect(); int fullStride = duration; nBytes = (long) (chanInfo.getRate() * chanInfo.getBytesPerSample() * duration); while (fullStride * chanInfo.getRate() * chanInfo.getBytesPerSample() > 512 * 1024) { fullStride /= 2; } fullStride = Math.max(fullStride, minStride); fullStride = Math.min(fullStride, duration); ret = ndsClient.requestData(channelName, chanInfo.getcType(), startGPS, startGPS + duration, fullStride); NDSBufferStatus bufferStatus = ndsClient.getBufferStatus(); chanInfo.setdType(bufferStatus.getType()); chanInfo.setRate(bufferStatus.getFs()); sampleRate = bufferStatus.getFs(); if (ret) { int nsample = (int) (duration * sampleRate); addBuf(data, 0, nsample); } singleBufMs = ndsClient.getTotalTimeMs(); ndsClient.bye(); ndsClient = null; } catch (NDSException | IOException ex) { System.err.format("Error trying to transfer data all at once: %1$s - %2$s%n", ex.getClass().getSimpleName(), ex.getLocalizedMessage()); ret = false; try { ndsClient.bye(); } catch (NDSException ex1) { // we can ignore that one } ndsClient = null; } // we tried getting all data at once (the fast way) if that failed try harder if (!ret) { int stride = duration / 100; stride = Math.max(stride, minStride); stride = Math.min(stride, duration); for (int curT = 0; curT < duration && !wantsToCancel; curT += stride) { 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 { if (ndsClient == null) { ndsClient = new NDSProxyClient(server); ndsClient.connect(); } ret = ndsClient.requestData(channelName, chanInfo.getcType(), curgps, curgps + curDur, curDur); if (ret) { int t = curgps; while (t < curgps + curDur && !wantsToCancel) { int dt = (int) (ndsClient.getStartGPS() - startGPS); setProgress(String.format("Processing %1$,4d of %2$,4d seconds of data", dt, duration)); setProgress(dt, duration); int startSample = (int) (dt * sampleRate); int nsample = (int) (curDur * sampleRate); addBuf(data, startSample, nsample); int buflsec = curDur; t = (int) (ndsClient.getStartGPS() + buflsec); bufn++; wantsToCancel = checkCancel(); } } else { String msg = ndsClient.getLastError(); if (!checkNoData(curgps, curDur, msg)) { wantsToCancel = true; System.err.format("Transfer error: %s\n", msg); } } multipleBufMs = ndsClient.getTotalTimeMs(); ndsClient.disconnect(); ndsClient.bye(); ndsClient = null; } catch (Exception ex) { String msg = ex.getClass().getSimpleName() + ": " + ex.getMessage(); if (!checkNoData(curgps, curDur, msg)) { wantsToCancel = true; System.err.format("Transfer error: %s\n", msg); } if (ndsClient != null) { try { ndsClient.disconnect(); ndsClient.bye(); ndsClient = null; } catch (Exception ex2) { // we ignore errors in the error handlers, // because I don't know what else to do } } } } } } if (wantsToCancel) { status = "Canceled by user"; } else { makeImage(); status = "Success"; } // 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); System.out.format("Single transfer time: %1$.1fs, multi: %2$.1fs rate %3$.0fKb/s%n", singleBufMs / 1000., multipleBufMs / 1000., bytes / (double) (singleBufMs + multipleBufMs)); System.out.format("#imgPos ODC (x0,y0, w,h, strt, dur): %1$d, %2$d, %3$d, %4$d, %5$d, %6$d,%n", imgX0, imgY0, dimX, dimY, startGPS, duration); } catch (LdvTableException | SQLException | IOException ex) { status = "Error: " + ex.getLocalizedMessage(); System.err.println(ex.getLocalizedMessage()); ex.printStackTrace(); } closeProgress(); }
From source file:odcplot.OdcPlot.java
/** * For binary input files from our frame reader set up the input stream * @return number of entries to read/* ww w . jav a2 s . c o m*/ * @throws WebUtilException */ private long setupFileReads() throws WebUtilException { setProgress("Scan input file for min/max GPS times."); File inFile = new File(infilename); long siz = inFile.length() / (Float.SIZE / 8) / 2; // convert bytes to # entries (time, val) if (!inFile.canRead()) { throw new WebUtilException("Can't open " + infilename + " for reading"); } try { inStream = new SwappedDataInputStream(new FileInputStream(inFile)); float minTime = Float.MAX_VALUE; float maxTime = -Float.MAX_VALUE; setProgress("Searhing for min/max time in input file."); int opct = 0; for (int i = 0; i < siz; i++) { int pct = (int) (100 * i / siz); if (pct > opct) { setProgress(pct, 100); opct = pct; } Float t = inStream.readFloat(); Float d = inStream.readFloat(); minTime = Math.min(minTime, t); maxTime = Math.max(maxTime, t); } startGPS = (int) (minTime * 24 * 3600); duration = (int) ((maxTime - minTime) * 24 * 3600); inStream.close(); inStream = new SwappedDataInputStream(new FileInputStream(inFile)); } catch (IOException ex) { throw new WebUtilException("Can't open " + infilename + " for reading"); } return siz; }