Example usage for java.lang Float isNaN

List of usage examples for java.lang Float isNaN

Introduction

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

Prototype

public static boolean isNaN(float v) 

Source Link

Document

Returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.

Usage

From source file:au.org.ala.layers.dao.LayerIntersectDAOImpl.java

/**
 * Single coordinate sampling.//from w ww .j a  v  a  2 s.c  om
 *
 * @param fieldIds  comma separated field ids.
 * @param longitude
 * @param latitude
 * @return the intersection value for each input field id as a \n separated
 * String.
 */
@Override
public String sampling(String fieldIds, double longitude, double latitude) {
    init();

    double[][] p = { { longitude, latitude } };
    String[] fields = fieldIds.split(",");

    //count el fields
    int elCount = 0;
    for (int i = 0; i < fields.length; i++) {
        if (fields[i].length() > 0 && fields[i].charAt(0) == 'e') {
            elCount++;
        }
    }

    StringBuilder sb = new StringBuilder();
    HashMap<String, Float> gridValues = null;
    for (String fid : fields) {
        IntersectionFile f = getConfig().getIntersectionFile(fid);

        if (sb.length() > 0) {
            sb.append("\n");
        }

        if (f != null) {
            if (f.getShapeFields() != null && getConfig().getShapeFileCache() != null) {
                SimpleShapeFile ssf = getConfig().getShapeFileCache().get(f.getFilePath());
                if (ssf != null) {
                    int column_idx = ssf.getColumnIdx(f.getShapeFields());
                    String[] categories = ssf.getColumnLookup(column_idx);
                    short[] idx = ssf.getColumnIdxs(f.getShapeFields());
                    int value = ssf.intersectInt(longitude, latitude);
                    if (value >= 0) {
                        sb.append(categories[idx[value]]);
                    }
                } else {
                    ObjectDAO objectDao = (ObjectDAO) appcontext.getBean("objectDao");
                    Objects o = objectDao.getObjectByIdAndLocation(f.getFieldId(), longitude, latitude);
                    if (o != null) {
                        sb.append(o.getName());
                    }
                }
            } else {
                if (gridValues == null && gridReaders != null && elCount > gridGroupCount) {
                    try {
                        GridCacheReader gcr = gridReaders.take();
                        gridValues = gcr.sample(longitude, latitude);
                        gridReaders.put(gcr);
                    } catch (Exception e) {
                        logger.error("GridCacheReader failed.", e);
                    }
                }

                if (gridValues != null) {
                    Float v = gridValues.get(fid);
                    if (v == null && !gridValues.containsKey(fid)) {
                        Grid g = new Grid(f.getFilePath());
                        if (g != null) {
                            float fv = g.getValues(p)[0];
                            if (f.getClasses() != null) {
                                GridClass gc = f.getClasses().get((int) fv);
                                if (gc != null) {
                                    sb.append(gc.getName());
                                }
                            } else {
                                if (!Float.isNaN(fv)) {
                                    sb.append(String.valueOf(fv));
                                }
                            }
                        }
                    } else {
                        if (f.getClasses() != null) {
                            GridClass gc = f.getClasses().get(v.intValue());
                            if (gc != null) {
                                sb.append(gc.getName());
                            }
                        } else {
                            if (v != null && !v.isNaN()) {
                                sb.append(String.valueOf(v));
                            }
                        }
                    }
                } else {
                    Grid g = new Grid(f.getFilePath());
                    if (g != null) {
                        float fv = g.getValues(p)[0];
                        if (f.getClasses() != null) {
                            GridClass gc = f.getClasses().get((int) fv);
                            if (gc != null) {
                                sb.append(gc.getName());
                            }
                        } else {
                            if (!Float.isNaN(fv)) {
                                sb.append(String.valueOf(fv));
                            }
                        }
                    }
                }
            }
        } else {
            String[] info = getConfig().getAnalysisLayerInfo(fid);

            if (info != null) {
                String filename = info[1];
                Grid grid = new Grid(filename);

                if (grid != null && (new File(filename + ".grd").exists())) {
                    sb.append(String.valueOf(grid.getValues(p)[0]));
                }
            }
        }
    }

    return sb.toString();
}

From source file:edu.ucsc.barrel.cdf_gen.SpectrumExtract.java

private static float[] binvert(float[] start, float f) {
    int size = start.length, bad_vals = 0;

    float[] iter1 = new float[size];
    float[] iter2 = new float[size];

    //first iteration of Newton-Raphson  
    for (int i = 0; i < size; i++) {
        if (start[i] < 0) {
            iter1[i] = Float.NaN;
        } else {/*from  w  w w .  j a  v  a2 s .  c om*/
            iter1[i] = (start[i] + f * start[i]) / (1.0f + f * (1.0f + (float) Math.log(start[i])));
            if (iter1[i] < 0) {
                iter1[i] = Float.NaN;
            }
        }
    }

    //second iteration of Newton-Raphson  
    for (int i = 0; i < size; i++) {
        if (Float.isNaN(iter1[i])) {
            bad_vals++;
        } else {
            iter2[i] = (start[i] + f * iter1[i]) / (1.0f + f * (1.0f + (float) Math.log(iter1[i])));
            if (Float.isInfinite(iter2[i]) || iter2[i] < 0) {
                bad_vals++;
                iter2[i] = Float.NaN;
            }
        }
    }

    //turn bad values into negatives ascending to zero
    if (bad_vals > 0) {
        for (int i = 0; i < size; i++) {
            if (Float.isNaN(iter2[i])) {
                bad_vals--;
                iter2[i] = 0 - bad_vals;
            }
        }
    }

    return iter2;
}

From source file:juicebox.mapcolorui.HeatmapRenderer.java

/**
 * Render a dense matrix. Used for Pearsons correlation.  The bitmap is drawn at 1 data point
 * per pixel, scaling happens elsewhere.
 *
 * @param rm         Matrix to render/*from ww w. j  ava  2 s  .  c o m*/
 * @param originX    origin in pixels
 * @param originY    origin in pixels
 * @param colorScale color scale to apply
 * @param g          graphics to render matrix into
 */
private void renderMatrix(BasicMatrix rm, int originX, int originY, int width, int height,
        ColorScale colorScale, Graphics2D g) {

    int endX = Math.min(originX + width, rm.getColumnDimension());
    int endY = Math.min(originY + height, rm.getRowDimension());

    for (int row = originY; row < endY; row++) {
        for (int col = originX; col < endX; col++) {

            float score = rm.getEntry(row, col);
            Color color;
            if (Float.isNaN(score)) {
                color = Color.gray;
            } else {
                color = score == 0 ? Color.black : colorScale.getColor(score);
            }
            int px = col - originX;
            int py = row - originY;
            g.setColor(color);
            //noinspection SuspiciousNameCombination
            g.fillRect(px, py, HiCGlobals.BIN_PIXEL_WIDTH, HiCGlobals.BIN_PIXEL_WIDTH);
            // Assuming same chromosome
            if (col != row) {
                px = row - originX;
                py = col - originY;
                g.fillRect(px, py, HiCGlobals.BIN_PIXEL_WIDTH, HiCGlobals.BIN_PIXEL_WIDTH);
            }
        }
    }
}

From source file:com.tmall.wireless.tangram3.view.BannerView.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    if (!Float.isNaN(ratio)) {
        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        heightMeasureSpec = MeasureSpec.makeMeasureSpec((int) (widthSize / ratio), MeasureSpec.EXACTLY);
    } else if (height > 0) {
        heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
    }/*from   www. j  a  va2 s.com*/
    mUltraViewPager.measure(widthMeasureSpec, heightMeasureSpec);
    mIndicator.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    int headerHeight = 0;
    if (!mHeaderViewHolders.isEmpty()) {
        for (int i = 0, count = mHeaderViewHolders.size(); i < count; i++) {
            View header = mHeaderViewHolders.get(i).itemView;
            LayoutParams lp = (LayoutParams) header.getLayoutParams();
            header.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            headerHeight += header.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
        }
    }
    int footerHeight = 0;
    if (!mFooterViewHolders.isEmpty()) {
        for (int i = 0, count = mFooterViewHolders.size(); i < count; i++) {
            View footer = mFooterViewHolders.get(i).itemView;
            LayoutParams lp = (LayoutParams) footer.getLayoutParams();
            footer.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
            footerHeight += footer.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
        }
    }

    int measureWidth = mUltraViewPager.getMeasuredWidth();
    int measureHeight = mUltraViewPager.getMeasuredHeight();
    if (isIndicatorOutside) {
        int indicatorHeight = mIndicator.getMeasuredHeight();
        setMeasuredDimension(measureWidth, measureHeight + indicatorHeight + headerHeight + footerHeight);
    } else {
        setMeasuredDimension(measureWidth, measureHeight + headerHeight + footerHeight);
    }
}

From source file:org.caleydo.core.util.impute.KNNImpute.java

/**
 * @return//from   ww w.  j  a v a 2s. c o  m
 */
private boolean toomanyNaNsInAColumn() {
    float colmax = desc.getColmax();
    if (Float.isInfinite(colmax) || Float.isNaN(colmax))
        return false;
    int max = Math.round(colmax * genes.size());
    for (int i = 0; i < samples; ++i) {
        int nans = getSample(i).getNans();
        if (nans > max)
            return true;
    }
    return false;
}

From source file:com.google.android.car.kitchensink.sensor.SensorsTestFragment.java

private String getCompassString(CarSensorEvent event) {
    String bear = mNaString;//from w w  w.j  ava  2  s.  c  o m
    String pitch = mNaString;
    String roll = mNaString;
    if (event != null) {
        CarSensorEvent.CompassData compass = event.getCompassData();
        bear = Float.isNaN(compass.bearing) ? bear : String.valueOf(compass.bearing);
        pitch = Float.isNaN(compass.pitch) ? pitch : String.valueOf(compass.pitch);
        roll = Float.isNaN(compass.roll) ? roll : String.valueOf(compass.roll);
    }
    return getContext().getString(R.string.sensor_compass, getTimestamp(event), bear, pitch, roll);
}

From source file:org.apache.vxquery.runtime.functions.cast.CastToStringOperation.java

public void convertFloatCanonical(FloatPointable floatp, DataOutput dOut) throws SystemException, IOException {
    abvsInner.reset();//from  ww w  .  j av  a  2s . c  o m
    float value = floatp.getFloat();

    if (Float.isInfinite(value)) {
        if (value == Float.NEGATIVE_INFINITY) {
            FunctionHelper.writeCharSequence("-", dOutInner);
        }
        FunctionHelper.writeCharSequence("INF", dOutInner);
    } else if (Float.isNaN(value)) {
        FunctionHelper.writeCharSequence("NaN", dOutInner);
    } else {
        dOut.write(returnTag);
        dOut.writeUTF(Float.toString(value));
        return;
    }
    sendStringDataOutput(dOut);
}

From source file:routines.system.BigDataParserUtils.java

public static Byte parseTo_Byte(float input) {
    if (Float.isNaN(input)) {
        return null;
    }//from  w w w .j a  v a2s  .  c  o  m
    return ((Float) input).byteValue();
}

From source file:juicebox.data.MatrixZoomData.java

/**
 * Computes eigenvector from Pearson's./*from   w  w w.  ja v  a 2 s .  c  o m*/
 *
 * @param df    Expected values, needed to get Pearson's
 * @param which Which eigenvector; 0 is principal.
 * @return Eigenvector
 */
public double[] computeEigenvector(ExpectedValueFunction df, int which) {
    BasicMatrix pearsons = getPearsons(df);
    if (pearsons == null) {
        return null;
    }

    int dim = pearsons.getRowDimension();
    double[][] data = new double[dim][dim];
    BitSet bitSet = new BitSet(dim);
    for (int i = 0; i < dim; i++) {
        for (int j = 0; j < dim; j++) {
            float tmp = pearsons.getEntry(i, j);
            data[i][j] = tmp;
            if (data[i][j] != 0 && !Float.isNaN(tmp)) {
                bitSet.set(i);
            }
        }
    }

    int[] nonCentromereColumns = new int[bitSet.cardinality()];
    int count = 0;
    for (int i = 0; i < dim; i++) {
        if (bitSet.get(i))
            nonCentromereColumns[count++] = i;
    }

    RealMatrix subMatrix = new Array2DRowRealMatrix(data).getSubMatrix(nonCentromereColumns,
            nonCentromereColumns);
    RealVector rv = (new EigenDecompositionImpl(subMatrix, 0)).getEigenvector(which);

    double[] ev = rv.toArray();

    int size = pearsons.getColumnDimension();
    double[] eigenvector = new double[size];
    int num = 0;
    for (int i = 0; i < size; i++) {
        if (num < nonCentromereColumns.length && i == nonCentromereColumns[num]) {
            eigenvector[i] = ev[num];
            num++;
        } else {
            eigenvector[i] = Double.NaN;
        }
    }
    return eigenvector;

}