Example usage for java.lang Float NaN

List of usage examples for java.lang Float NaN

Introduction

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

Prototype

float NaN

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

Click Source Link

Document

A constant holding a Not-a-Number (NaN) value of type float .

Usage

From source file:org.broad.igv.data.ProcessingUtils.java

public static float computeStat(float[] data, WindowFunction function) {

    if (nullDataCheck(data)) {
        return Float.NaN;
    } else {//from w w  w .  j a va 2  s  . c  om
        switch (function) {
        case mean:
            return computeMean(data);
        case median:
            return computeQuantile(data, 50);
        case min:
            return computeMin(data);
        case max:
            return computeMax(data);
        case percentile2:
            return computeQuantile(data, 2);
        case percentile10:
            return computeQuantile(data, 10);
        case percentile90:
            return computeQuantile(data, 90);
        case percentile98:
            return computeQuantile(data, 98);
        case count:
            return data.length;

        }
        return Float.NaN;
    }

}

From source file:com.taobao.weex.utils.WXUtils.java

public static Float getFloat(Object value, @Nullable Float df) {
    if (value == null) {
        return df;
    }//from  www . ja  v a 2  s  .  c  o  m

    String temp = value.toString().trim();
    if (Constants.Name.AUTO.equals(temp) || Constants.Name.UNDEFINED.equals(temp) || TextUtils.isEmpty(temp)) {
        WXLogUtils.e("Argument Warning ! value is " + temp + "And default Value:" + Float.NaN);
        return df;
    }
    if (temp.endsWith("wx")) {
        try {
            return transferWx(temp, 750);
        } catch (NumberFormatException e) {
            WXLogUtils.e("Argument format error! value is " + value, e);
        } catch (Exception e) {
            WXLogUtils.e("Argument error! value is " + value, e);
        }
    } else if (temp.endsWith("px")) {
        try {
            temp = temp.substring(0, temp.indexOf("px"));
            return Float.parseFloat(temp);
        } catch (NumberFormatException nfe) {
            WXLogUtils.e("Argument format error! value is " + value, nfe);
        } catch (Exception e) {
            WXLogUtils.e("Argument error! value is " + value, e);
        }
    } else {
        try {
            return Float.parseFloat(temp);
        } catch (NumberFormatException nfe) {
            WXLogUtils.e("Argument format error! value is " + value, nfe);
        } catch (Exception e) {
            WXLogUtils.e("Argument error! value is " + value, e);
        }
    }
    return df;
}

From source file:savant.data.sources.BigWigDataSource.java

@Override
public List<GenericContinuousRecord> getRecords(String ref, RangeAdapter range, Resolution resolution,
        RecordFilterAdapter filt) throws IOException, InterruptedException {
    List<GenericContinuousRecord> result = new ArrayList<GenericContinuousRecord>();
    try {//  w  ww .jav  a 2  s.  co  m
        BigWigIterator wigIterator = bbReader.getBigWigIterator(ref, range.getFrom(), ref, range.getTo(),
                false);
        int nextPos = range.getFrom();
        int rangeEnd = range.getTo();
        while (wigIterator.hasNext()) {
            WigItem wig = wigIterator.next();

            int datumStart = wig.getStartBase();
            int datumEnd = wig.getEndBase();
            float value = wig.getWigValue();

            while (nextPos < datumStart && nextPos <= rangeEnd) {
                result.add(GenericContinuousRecord.valueOf(ref, nextPos, Float.NaN));
                nextPos++;
            }
            while (nextPos < datumEnd && nextPos <= rangeEnd) {
                result.add(GenericContinuousRecord.valueOf(ref, nextPos, value));
                nextPos++;
            }
            if (Thread.interrupted()) {
                throw new InterruptedException();
            }
        }
    } catch (RuntimeException ignored) {
        // If BigWig reader has no data in the given range, it throws a RuntimeException.  Really?  Who does that?
    }
    return result;
}

From source file:Main.java

/**
 * Determines the minimum and maximum values in the two dimensional array <tt>multi</tt>. Calls {@link #minMax(float[], float)} with
 * <tt>Float.NaN</tt> as the <tt>noDataValue</tt>.
 * /*from   ww  w.java  2  s. c o  m*/
 * @param multi
 * @return a <tt>float[]</tt> where [0]==minimum and [1]==maximum
 * @see #minMax(float[][], float)
 */
public static float[] minMax(float[][] multi) {
    return minMax(multi, Float.NaN);
}

From source file:org.apache.predictionio.examples.java.recommendations.tutorial4.FeatureBasedAlgorithm.java

public Float predict(FeatureBasedModel model, Query query) {
    final int uid = query.uid;
    final int iid = query.iid;

    if (!model.userFeatures.containsKey(uid)) {
        return Float.NaN;
    }/*from  ww w  . ja  v a2 s. c o  m*/

    if (!model.itemFeatures.containsKey(iid)) {
        return Float.NaN;
    }

    final RealVector userFeature = model.userFeatures.get(uid);
    final RealVector itemFeature = model.itemFeatures.get(iid);

    return new Float(userFeature.dotProduct(itemFeature));
}

From source file:com.facebook.react.views.toolbar.ReactToolbarManager.java

@ReactProp(name = "contentInsetStart", defaultFloat = Float.NaN)
public void setContentInsetStart(ReactToolbar view, float insetStart) {
    int inset = Float.isNaN(insetStart) ? getDefaultContentInsets(view.getContext())[0]
            : Math.round(PixelUtil.toPixelFromDIP(insetStart));
    view.setContentInsetsRelative(inset, view.getContentInsetEnd());
}

From source file:com.cloudera.oryx.als.computation.local.ReadInputs.java

private void readInput() throws IOException {
    File[] inputFiles = inputDir.listFiles(IOUtils.CSV_COMPRESSED_FILTER);
    if (inputFiles == null || inputFiles.length == 0) {
        log.info("No input files in {}", inputDir);
        return;/*ww  w .ja  va  2  s  .  co  m*/
    }
    Arrays.sort(inputFiles, ByLastModifiedComparator.INSTANCE);

    for (File inputFile : inputFiles) {
        log.info("Reading {}", inputFile);
        for (CharSequence line : new FileLineIterable(inputFile)) {

            String[] columns = DelimitedDataUtils.decode(line);

            String userIDString = columns[0];
            long userID = isInbound ? idMapping.add(userIDString) : Long.parseLong(userIDString);
            String itemIDString = columns[1];
            long itemID = isInbound ? idMapping.add(itemIDString) : Long.parseLong(itemIDString);
            float value;
            if (columns.length > 2) {
                String valueToken = columns[2];
                value = valueToken.isEmpty() ? Float.NaN : LangUtils.parseFloat(valueToken);
            } else {
                value = 1.0f;
            }

            if (Float.isNaN(value)) {
                // Remove, not set
                MatrixUtils.remove(userID, itemID, RbyRow, RbyColumn);
            } else {
                MatrixUtils.addTo(userID, itemID, value, RbyRow, RbyColumn);
            }

            if (knownItemIDs != null) {
                LongSet itemIDs = knownItemIDs.get(userID);
                if (Float.isNaN(value)) {
                    // Remove, not set
                    if (itemIDs != null) {
                        itemIDs.remove(itemID);
                        if (itemIDs.isEmpty()) {
                            knownItemIDs.remove(userID);
                        }
                    }
                } else {
                    if (itemIDs == null) {
                        itemIDs = new LongSet();
                        knownItemIDs.put(userID, itemIDs);
                    }
                    itemIDs.add(itemID);
                }
            }

        }
    }

}

From source file:ch.luethi.skylinestracker.PositionService.java

@Override
public void onLocationChanged(Location location) {
    if (location.getLatitude() != 0.0) {
        if (isOnline()) {
            app.lastLat = location.getLatitude();
            app.lastLon = location.getLongitude();
            // convert m/sec to km/hr
            float kmPerHr = location.hasSpeed() ? location.getSpeed() * 3.6F : Float.NaN;
            float[] accelVals = null;
            float vspd = Float.NaN;
            getOrCreateSkyLinesTrackingWriter().emitPosition(location.getTime(), app.lastLat, app.lastLon,
                    location.hasAltitude() ? (float) location.getAltitude() : Float.NaN,
                    (int) location.getBearing(), kmPerHr, accelVals, vspd);
            if (app.guiActive) {
                sendPositionStatus();/*  ww  w .j av  a  2  s.  co  m*/
            }
        } else {
            if (app.guiActive)
                sendConnectionStatus();
        }
    }
}

From source file:net.myrrix.online.generation.InputFilesReader.java

static void readInputFiles(FastByIDMap<FastIDSet> knownItemIDs, FastByIDMap<FastByIDFloatMap> rbyRow,
        FastByIDMap<FastByIDFloatMap> rbyColumn, FastIDSet itemTagIDs, FastIDSet userTagIDs, File inputDir)
        throws IOException {

    FilenameFilter csvFilter = new PatternFilenameFilter(".+\\.csv(\\.(zip|gz))?");

    File[] otherFiles = inputDir.listFiles(new InvertedFilenameFilter(csvFilter));
    if (otherFiles != null) {
        for (File otherFile : otherFiles) {
            log.info("Skipping file {}", otherFile.getName());
        }/* ww  w .  j  av  a  2s. c o m*/
    }

    File[] inputFiles = inputDir.listFiles(csvFilter);
    if (inputFiles == null) {
        log.info("No input files in {}", inputDir);
        return;
    }
    Arrays.sort(inputFiles, ByLastModifiedComparator.INSTANCE);

    IDMigrator hash = new OneWayMigrator();

    int lines = 0;
    int badLines = 0;
    for (File inputFile : inputFiles) {
        log.info("Reading {}", inputFile);
        for (String line : new FileLineIterable(inputFile)) {

            if (badLines > 100) { // Crude check
                throw new IOException("Too many bad lines; aborting");
            }

            lines++;

            if (line.isEmpty() || line.charAt(0) == '#') {
                continue;
            }

            Iterator<String> it = COMMA.split(line).iterator();

            long userID;
            boolean userIsTag;
            long itemID;
            boolean itemIsTag;
            float value;
            try {

                String userIDString = it.next();
                userIsTag = userIDString.startsWith("\"");
                if (userIsTag) {
                    userID = hash.toLongID(userIDString.substring(1, userIDString.length() - 1));
                } else {
                    userID = Long.parseLong(userIDString);
                }

                String itemIDString = it.next();
                itemIsTag = itemIDString.startsWith("\"");
                if (itemIsTag) {
                    itemID = hash.toLongID(itemIDString.substring(1, itemIDString.length() - 1));
                } else {
                    itemID = Long.parseLong(itemIDString);
                }

                if (it.hasNext()) {
                    String valueToken = it.next();
                    value = valueToken.isEmpty() ? Float.NaN : LangUtils.parseFloat(valueToken);
                } else {
                    value = 1.0f;
                }

            } catch (NoSuchElementException ignored) {
                log.warn("Ignoring line with too few columns: '{}'", line);
                badLines++;
                continue;
            } catch (IllegalArgumentException iae) { // includes NumberFormatException
                if (lines == 1) {
                    log.info("Ignoring header line: '{}'", line);
                } else {
                    log.warn("Ignoring unparseable line: '{}'", line);
                    badLines++;
                }
                continue;
            }

            if (userIsTag && itemIsTag) {
                log.warn("Two tags not allowed: '{}'", line);
                badLines++;
                continue;
            }

            if (userIsTag) {
                itemTagIDs.add(userID);
            }

            if (itemIsTag) {
                userTagIDs.add(itemID);
            }

            if (Float.isNaN(value)) {
                // Remove, not set
                MatrixUtils.remove(userID, itemID, rbyRow, rbyColumn);
            } else {
                MatrixUtils.addTo(userID, itemID, value, rbyRow, rbyColumn);
            }

            if (knownItemIDs != null) {
                FastIDSet itemIDs = knownItemIDs.get(userID);
                if (Float.isNaN(value)) {
                    // Remove, not set
                    if (itemIDs != null) {
                        itemIDs.remove(itemID);
                        if (itemIDs.isEmpty()) {
                            knownItemIDs.remove(userID);
                        }
                    }
                } else {
                    if (itemIDs == null) {
                        itemIDs = new FastIDSet();
                        knownItemIDs.put(userID, itemIDs);
                    }
                    itemIDs.add(itemID);
                }
            }

            if (lines % 1000000 == 0) {
                log.info("Finished {} lines", lines);
            }
        }
    }

    log.info("Pruning near-zero entries");
    removeSmall(rbyRow);
    removeSmall(rbyColumn);
}

From source file:com.facebook.react.views.toolbar.ReactToolbarManager.java

@ReactProp(name = "contentInsetEnd", defaultFloat = Float.NaN)
public void setContentInsetEnd(ReactToolbar view, float insetEnd) {
    int inset = Float.isNaN(insetEnd) ? getDefaultContentInsets(view.getContext())[1]
            : Math.round(PixelUtil.toPixelFromDIP(insetEnd));
    view.setContentInsetsRelative(view.getContentInsetStart(), inset);
}