List of usage examples for java.lang Float isInfinite
public static boolean isInfinite(float v)
From source file:org.eclipse.dataset.FloatDataset.java
@Override public boolean containsInfs() { IndexIterator iter = getIterator(); // REAL_ONLY while (iter.hasNext()) { // REAL_ONLY if (Float.isInfinite(data[iter.index])) // CLASS_TYPE // REAL_ONLY return true; // REAL_ONLY } // REAL_ONLY return false; }
From source file:org.eclipse.dataset.FloatDataset.java
@Override public boolean containsInvalidNumbers() { IndexIterator iter = getIterator(); // REAL_ONLY while (iter.hasNext()) { // REAL_ONLY float x = data[iter.index]; // PRIM_TYPE // REAL_ONLY if (Float.isNaN(x) || Float.isInfinite(x)) // CLASS_TYPE // REAL_ONLY return true; // REAL_ONLY } // REAL_ONLY return false; }
From source file:net.pms.util.Rational.java
/** * Returns a {@link Rational} whose value is {@code (this + value)}. * * @param value the value to be added to this {@link Rational}. * @return The addition result./*from www . j a v a2 s. com*/ */ @Nonnull public Rational add(float value) { if (isNaN() || Float.isNaN(value)) { return NaN; } if (value == 0f) { return this; } if (isInfinite()) { if (Float.isInfinite(value) && signum() != Math.signum(value)) { return NaN; // Infinity minus infinity } return this; } return add(valueOf(value)); }
From source file:net.pms.util.Rational.java
/** * Returns a {@link Rational} whose value is {@code (this / value)}. * * @param value the value by which this {@link Rational} is to be divided. * @return The division result.//from ww w. j a v a 2 s . c om */ @Nonnull public Rational divide(float value) { if (isNaN() || Float.isNaN(value) || isInfinite() && Float.isInfinite(value)) { return NaN; } if (value == 0f) { if (signum() == 0) { return NaN; } return signum() > 0 ? POSITIVE_INFINITY : NEGATIVE_INFINITY; } if (Float.isInfinite(value)) { return ZERO; } if (signum() == 0 || isInfinite() || 1f == Math.abs(value)) { return value < 0f ? negate() : this; } return divide(valueOf(value)); }
From source file:org.eclipse.january.dataset.Stats.java
/** * @param a dataset/* w w w.ja v a 2 s .c om*/ * @param dtype * @param axis * @param ignoreInvalids see {@link IDataset#max(boolean...)} * @return typed product of items along axis in dataset * @since 2.0 */ public static Dataset typedProduct(final Dataset a, final int dtype, int axis, final boolean... ignoreInvalids) { axis = a.checkAxis(axis); final int[] oshape = a.getShape(); final int is = a.getElementsPerItem(); final int alen = oshape[axis]; oshape[axis] = 1; final boolean ignoreNaNs; final boolean ignoreInfs; if (a.hasFloatingPointElements()) { ignoreNaNs = ignoreInvalids != null && ignoreInvalids.length > 0 ? ignoreInvalids[0] : false; ignoreInfs = ignoreInvalids != null && ignoreInvalids.length > 1 ? ignoreInvalids[1] : ignoreNaNs; } else { ignoreNaNs = false; ignoreInfs = false; } @SuppressWarnings("deprecation") Dataset result = DatasetFactory.zeros(is, oshape, dtype); IndexIterator qiter = result.getIterator(true); int[] qpos = qiter.getPos(); int[] spos; // TODO add getLongArray(long[], int...) to CompoundDataset while (qiter.hasNext()) { spos = qpos.clone(); if (a.isComplex()) { double rv = 1, iv = 0; switch (dtype) { case Dataset.COMPLEX64: ComplexFloatDataset af = (ComplexFloatDataset) a; for (int j = 0; j < alen; j++) { spos[axis] = j; final float r1 = af.getReal(spos); final float i1 = af.getImag(spos); if (ignoreNaNs && (Float.isNaN(r1) || Float.isNaN(i1))) { continue; } if (ignoreInfs && (Float.isInfinite(r1) || Float.isInfinite(i1))) { continue; } final double tv = r1 * rv - i1 * iv; iv = r1 * iv + i1 * rv; rv = tv; if (Double.isNaN(rv) && Double.isNaN(iv)) { break; } } break; case Dataset.COMPLEX128: ComplexDoubleDataset ad = (ComplexDoubleDataset) a; for (int j = 0; j < alen; j++) { spos[axis] = j; final double r1 = ad.getReal(spos); final double i1 = ad.getImag(spos); if (ignoreNaNs && (Double.isNaN(r1) || Double.isNaN(i1))) { continue; } if (ignoreInfs && (Double.isInfinite(r1) || Double.isInfinite(i1))) { continue; } final double tv = r1 * rv - i1 * iv; iv = r1 * iv + i1 * rv; rv = tv; if (Double.isNaN(rv) && Double.isNaN(iv)) { break; } } break; } result.set(new Complex(rv, iv), qpos); } else { final long[] lresults; final double[] dresults; switch (dtype) { case Dataset.BOOL: case Dataset.INT8: case Dataset.INT16: case Dataset.INT32: case Dataset.INT64: long lresult = 1; for (int j = 0; j < alen; j++) { spos[axis] = j; lresult *= a.getInt(spos); } result.set(lresult, qpos); break; case Dataset.ARRAYINT8: lresults = new long[is]; for (int k = 0; k < is; k++) { lresults[k] = 1; } for (int j = 0; j < alen; j++) { spos[axis] = j; final byte[] va = (byte[]) a.getObject(spos); for (int k = 0; k < is; k++) { lresults[k] *= va[k]; } } result.set(lresults, qpos); break; case Dataset.ARRAYINT16: lresults = new long[is]; for (int k = 0; k < is; k++) { lresults[k] = 1; } for (int j = 0; j < alen; j++) { spos[axis] = j; final short[] va = (short[]) a.getObject(spos); for (int k = 0; k < is; k++) { lresults[k] *= va[k]; } } result.set(lresults, qpos); break; case Dataset.ARRAYINT32: lresults = new long[is]; for (int k = 0; k < is; k++) { lresults[k] = 1; } for (int j = 0; j < alen; j++) { spos[axis] = j; final int[] va = (int[]) a.getObject(spos); for (int k = 0; k < is; k++) { lresults[k] *= va[k]; } } result.set(lresults, qpos); break; case Dataset.ARRAYINT64: lresults = new long[is]; for (int k = 0; k < is; k++) { lresults[k] = 1; } for (int j = 0; j < alen; j++) { spos[axis] = j; final long[] va = (long[]) a.getObject(spos); for (int k = 0; k < is; k++) { lresults[k] *= va[k]; } } result.set(lresults, qpos); break; case Dataset.FLOAT32: case Dataset.FLOAT64: double dresult = 1.; for (int j = 0; j < alen; j++) { spos[axis] = j; final double x = a.getDouble(spos); if (ignoreNaNs && Double.isNaN(x)) { continue; } if (ignoreInfs && Double.isInfinite(x)) { continue; } dresult *= x; if (Double.isNaN(dresult)) { break; } } result.set(dresult, qpos); break; case Dataset.ARRAYFLOAT32: case Dataset.ARRAYFLOAT64: CompoundDataset da = (CompoundDataset) a; double[] dvalues = new double[is]; dresults = new double[is]; for (int k = 0; k < is; k++) { dresults[k] = 1.; } for (int j = 0; j < alen; j++) { spos[axis] = j; da.getDoubleArray(dvalues, spos); boolean okay = true; for (int k = 0; k < is; k++) { final double val = dvalues[k]; if (ignoreNaNs && Double.isNaN(val)) { okay = false; break; } if (ignoreInfs && Double.isInfinite(val)) { okay = false; break; } } if (okay) { for (int k = 0; k < is; k++) { dresults[k] *= dvalues[k]; } } } result.set(dresults, qpos); break; } } } result.setShape(ShapeUtils.squeezeShape(oshape, axis)); return result; }
From source file:org.alfresco.solr.SolrInformationServer.java
private NamedList<Object> fixStats(NamedList<Object> namedList) { int sz = namedList.size(); for (int i = 0; i < sz; i++) { Object value = namedList.getVal(i); if (value instanceof Number) { Number number = (Number) value; if (Float.isInfinite(number.floatValue()) || Float.isNaN(number.floatValue()) || Double.isInfinite(number.doubleValue()) || Double.isNaN(number.doubleValue())) { namedList.setVal(i, null); }// w w w. j a v a 2 s .c om } } return namedList; }
From source file:org.eclipse.dataset.CompoundFloatDataset.java
@Override public boolean containsInfs() { final IndexIterator iter = getIterator(); // REAL_ONLY while (iter.hasNext()) { // REAL_ONLY for (int i = 0; i < isize; i++) { // REAL_ONLY if (Float.isInfinite(data[iter.index + i])) // CLASS_TYPE // REAL_ONLY return true; // REAL_ONLY } // REAL_ONLY } // REAL_ONLY return false; }
From source file:org.eclipse.dataset.CompoundFloatDataset.java
@Override public boolean containsInvalidNumbers() { IndexIterator iter = getIterator(); // REAL_ONLY while (iter.hasNext()) { // REAL_ONLY for (int i = 0; i < isize; i++) { // REAL_ONLY float x = data[iter.index + i]; // PRIM_TYPE // REAL_ONLY if (Float.isNaN(x) || Float.isInfinite(x)) // CLASS_TYPE // REAL_ONLY return true; // REAL_ONLY } // REAL_ONLY } // REAL_ONLY return false; }
From source file:org.eclipse.january.dataset.Stats.java
/** * @param a dataset//from w w w . jav a 2s.co m * @param axis * @param ignoreInvalids see {@link Dataset#max(int, boolean...)} * @return cumulative product of items along axis in dataset * @since 2.0 */ public static Dataset cumulativeProduct(final Dataset a, int axis, final boolean... ignoreInvalids) { axis = a.checkAxis(axis); int dtype = a.getDType(); int[] oshape = a.getShape(); int alen = oshape[axis]; oshape[axis] = 1; final boolean ignoreNaNs; final boolean ignoreInfs; if (a.hasFloatingPointElements()) { ignoreNaNs = ignoreInvalids != null && ignoreInvalids.length > 0 ? ignoreInvalids[0] : false; ignoreInfs = ignoreInvalids != null && ignoreInvalids.length > 1 ? ignoreInvalids[1] : ignoreNaNs; } else { ignoreNaNs = false; ignoreInfs = false; } Dataset result = DatasetFactory.zeros(a); PositionIterator pi = result.getPositionIterator(axis); int[] pos = pi.getPos(); while (pi.hasNext()) { if (a.isComplex()) { double rv = 1, iv = 0; switch (dtype) { case Dataset.COMPLEX64: ComplexFloatDataset af = (ComplexFloatDataset) a; ComplexFloatDataset rf = (ComplexFloatDataset) result; for (int j = 0; j < alen; j++) { if (!Double.isNaN(rv) || !Double.isNaN(iv)) { pos[axis] = j; final float r1 = af.getReal(pos); final float i1 = af.getImag(pos); if (ignoreNaNs && (Float.isNaN(r1) || Float.isNaN(i1))) { continue; } if (ignoreInfs && (Float.isInfinite(r1) || Float.isInfinite(i1))) { continue; } final double tv = r1 * rv - i1 * iv; iv = r1 * iv + i1 * rv; rv = tv; } rf.set((float) rv, (float) iv, pos); } break; case Dataset.COMPLEX128: ComplexDoubleDataset ad = (ComplexDoubleDataset) a; ComplexDoubleDataset rd = (ComplexDoubleDataset) result; for (int j = 0; j < alen; j++) { if (!Double.isNaN(rv) || !Double.isNaN(iv)) { pos[axis] = j; final double r1 = ad.getReal(pos); final double i1 = ad.getImag(pos); if (ignoreNaNs && (Double.isNaN(r1) || Double.isNaN(i1))) { continue; } if (ignoreInfs && (Double.isInfinite(r1) || Double.isInfinite(i1))) { continue; } final double tv = r1 * rv - i1 * iv; iv = r1 * iv + i1 * rv; rv = tv; } rd.set(rv, iv, pos); } break; } } else { final int is; final long[] lresults; final double[] dresults; switch (dtype) { case Dataset.BOOL: case Dataset.INT8: case Dataset.INT16: case Dataset.INT32: case Dataset.INT64: long lresult = 1; for (int j = 0; j < alen; j++) { pos[axis] = j; lresult *= a.getInt(pos); result.set(lresult, pos); } break; case Dataset.ARRAYINT8: is = a.getElementsPerItem(); lresults = new long[is]; for (int k = 0; k < is; k++) { lresults[k] = 1; } for (int j = 0; j < alen; j++) { pos[axis] = j; final byte[] va = (byte[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] *= va[k]; } result.set(lresults, pos); } break; case Dataset.ARRAYINT16: is = a.getElementsPerItem(); lresults = new long[is]; for (int k = 0; k < is; k++) { lresults[k] = 1; } for (int j = 0; j < alen; j++) { pos[axis] = j; final short[] va = (short[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] *= va[k]; } result.set(lresults, pos); } break; case Dataset.ARRAYINT32: is = a.getElementsPerItem(); lresults = new long[is]; for (int k = 0; k < is; k++) { lresults[k] = 1; } for (int j = 0; j < alen; j++) { pos[axis] = j; final int[] va = (int[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] *= va[k]; } result.set(lresults, pos); } break; case Dataset.ARRAYINT64: is = a.getElementsPerItem(); lresults = new long[is]; for (int k = 0; k < is; k++) { lresults[k] = 1; } for (int j = 0; j < alen; j++) { pos[axis] = j; final long[] va = (long[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] *= va[k]; } result.set(lresults, pos); } break; case Dataset.FLOAT32: case Dataset.FLOAT64: double dresult = 1.; for (int j = 0; j < alen; j++) { if (!Double.isNaN(dresult)) { pos[axis] = j; final double x = a.getDouble(pos); if (ignoreNaNs && Double.isNaN(x)) { continue; } if (ignoreInfs && Double.isInfinite(x)) { continue; } dresult *= x; } result.set(dresult, pos); } break; case Dataset.ARRAYFLOAT32: case Dataset.ARRAYFLOAT64: is = a.getElementsPerItem(); CompoundDataset da = (CompoundDataset) a; double[] dvalues = new double[is]; dresults = new double[is]; for (int k = 0; k < is; k++) { dresults[k] = 1.; } for (int j = 0; j < alen; j++) { pos[axis] = j; da.getDoubleArray(dvalues, pos); boolean okay = true; for (int k = 0; k < is; k++) { final double val = dvalues[k]; if (ignoreNaNs && Double.isNaN(val)) { okay = false; break; } if (ignoreInfs && Double.isInfinite(val)) { okay = false; break; } } if (okay) { for (int k = 0; k < is; k++) { dresults[k] *= dvalues[k]; } } result.set(dresults, pos); } break; } } } return result; }
From source file:org.eclipse.january.dataset.Stats.java
/** * @param a dataset//from w w w . j a va 2 s. co m * @param axis * @param ignoreInvalids see {@link Dataset#max(int, boolean...)} * @return cumulative sum of items along axis in dataset * @since 2.0 */ public static Dataset cumulativeSum(final Dataset a, int axis, final boolean... ignoreInvalids) { axis = a.checkAxis(axis); int dtype = a.getDType(); int[] oshape = a.getShape(); int alen = oshape[axis]; oshape[axis] = 1; final boolean ignoreNaNs; final boolean ignoreInfs; if (a.hasFloatingPointElements()) { ignoreNaNs = ignoreInvalids != null && ignoreInvalids.length > 0 ? ignoreInvalids[0] : false; ignoreInfs = ignoreInvalids != null && ignoreInvalids.length > 1 ? ignoreInvalids[1] : ignoreNaNs; } else { ignoreNaNs = false; ignoreInfs = false; } Dataset result = DatasetFactory.zeros(a); PositionIterator pi = result.getPositionIterator(axis); int[] pos = pi.getPos(); while (pi.hasNext()) { if (a.isComplex()) { double rv = 0, iv = 0; switch (dtype) { case Dataset.COMPLEX64: ComplexFloatDataset af = (ComplexFloatDataset) a; ComplexFloatDataset rf = (ComplexFloatDataset) result; for (int j = 0; j < alen; j++) { if (!Double.isNaN(rv) || !Double.isNaN(iv)) { pos[axis] = j; final float r1 = af.getReal(pos); final float i1 = af.getImag(pos); if (ignoreNaNs && (Float.isNaN(r1) || Float.isNaN(i1))) { continue; } if (ignoreInfs && (Float.isInfinite(r1) || Float.isInfinite(i1))) { continue; } rv += r1; iv += i1; } rf.set((float) rv, (float) iv, pos); } break; case Dataset.COMPLEX128: ComplexDoubleDataset ad = (ComplexDoubleDataset) a; ComplexDoubleDataset rd = (ComplexDoubleDataset) result; for (int j = 0; j < alen; j++) { if (!Double.isNaN(rv) || !Double.isNaN(iv)) { pos[axis] = j; final double r1 = ad.getReal(pos); final double i1 = ad.getImag(pos); if (ignoreNaNs && (Double.isNaN(r1) || Double.isNaN(i1))) { continue; } if (ignoreInfs && (Double.isInfinite(r1) || Double.isInfinite(i1))) { continue; } rv += r1; iv += i1; } rd.set(rv, iv, pos); } break; } } else { final int is; final long[] lresults; final double[] dresults; switch (dtype) { case Dataset.BOOL: case Dataset.INT8: case Dataset.INT16: case Dataset.INT32: case Dataset.INT64: long lresult = 0; for (int j = 0; j < alen; j++) { pos[axis] = j; lresult += a.getInt(pos); result.set(lresult, pos); } break; case Dataset.ARRAYINT8: is = a.getElementsPerItem(); lresults = new long[is]; for (int j = 0; j < alen; j++) { pos[axis] = j; final byte[] va = (byte[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] += va[k]; } result.set(lresults, pos); } break; case Dataset.ARRAYINT16: is = a.getElementsPerItem(); lresults = new long[is]; for (int j = 0; j < alen; j++) { pos[axis] = j; final short[] va = (short[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] += va[k]; } result.set(lresults, pos); } break; case Dataset.ARRAYINT32: is = a.getElementsPerItem(); lresults = new long[is]; for (int j = 0; j < alen; j++) { pos[axis] = j; final int[] va = (int[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] += va[k]; } result.set(lresults, pos); } break; case Dataset.ARRAYINT64: is = a.getElementsPerItem(); lresults = new long[is]; for (int j = 0; j < alen; j++) { pos[axis] = j; final long[] va = (long[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] += va[k]; } result.set(lresults, pos); } break; case Dataset.FLOAT32: case Dataset.FLOAT64: double dresult = 0.; for (int j = 0; j < alen; j++) { if (!Double.isNaN(dresult)) { pos[axis] = j; final double x = a.getDouble(pos); if (ignoreNaNs && Double.isNaN(x)) { continue; } if (ignoreInfs && Double.isInfinite(x)) { continue; } dresult += x; } result.set(dresult, pos); } break; case Dataset.ARRAYFLOAT32: case Dataset.ARRAYFLOAT64: is = a.getElementsPerItem(); CompoundDataset da = (CompoundDataset) a; double[] dvalues = new double[is]; dresults = new double[is]; for (int j = 0; j < alen; j++) { pos[axis] = j; da.getDoubleArray(dvalues, pos); boolean okay = true; for (int k = 0; k < is; k++) { final double val = dvalues[k]; if (ignoreNaNs && Double.isNaN(val)) { okay = false; break; } if (ignoreInfs && Double.isInfinite(val)) { okay = false; break; } } if (okay) { for (int k = 0; k < is; k++) { dresults[k] += dvalues[k]; } } result.set(dresults, pos); } break; } } } return result; }