Example usage for org.apache.commons.math3.linear RealVector isNaN

List of usage examples for org.apache.commons.math3.linear RealVector isNaN

Introduction

In this page you can find the example usage for org.apache.commons.math3.linear RealVector isNaN.

Prototype

public abstract boolean isNaN();

Source Link

Document

Check whether any coordinate of this vector is NaN .

Usage

From source file:net.sf.dsp4j.octave_3_2_4.m.polynomial.Roots.java

public static Complex[] roots(RealVector v) {

    if (v.isInfinite() || v.isNaN()) {
        throw new RuntimeException("roots: inputs must not contain Inf or NaN");
    }//from   w w  w.  j  av a2s . co m

    int n = v.getDimension();

    // ## If v = [ 0 ... 0 v(k+1) ... v(k+l) 0 ... 0 ], we can remove the
    // ## leading k zeros and n - k - l roots of the polynomial are zero.

    int[] f = new int[v.getDimension()];
    if (v.getDimension() > 0) {
        int fI = 0;
        double max = v.getMaxValue();
        double min = FastMath.abs(v.getMinValue());
        if (min > max) {
            max = min;
        }
        RealVector v1 = v.mapDivide(max);
        f = OctaveBuildIn.find(v1);
    }

    Complex[] r = new Complex[0];
    if (f.length > 0 && n > 1) {
        v = v.getSubVector(f[0], f[f.length - 1] - f[0] + 1);
        if (v.getDimension() > 1) {
            double[] ones = new double[v.getDimension() - 2];
            Arrays.fill(ones, 1);
            RealMatrix A = OctaveBuildIn.diag(ones, -1);
            for (int i = 0; i < A.getRowDimension(); i++) {
                A.setEntry(i, 0, -v.getEntry(i + 1) / v.getEntry(0));
            }
            try {
                r = Eig.eig(A);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            if (f[f.length - 1] < n) {
                int diffLength = n - 1 - f[f.length - 1];
                if (diffLength > 0) {
                    int rl = r.length;
                    r = Arrays.copyOf(r, r.length + diffLength);
                    Arrays.fill(r, rl, r.length, Complex.ZERO);
                }
            }
        } else {
            r = new Complex[n - f[f.length - 1]];
            Arrays.fill(r, Complex.ZERO);
        }
    } else {
        r = new Complex[0];
    }
    return r;

}

From source file:com.cloudera.oryx.common.math.OpenMapRealVector.java

@SuppressWarnings("deprecation")
@Deprecated//from w w  w. ja  v a 2  s.  c  o m
@Override
public OpenMapRealVector ebeMultiply(RealVector v) {
    checkVectorDimensions(v.getDimension());
    OpenMapRealVector res = new OpenMapRealVector(this);
    OpenIntToDoubleHashMap.Iterator iter = entries.iterator();
    while (iter.hasNext()) {
        iter.advance();
        res.setEntry(iter.key(), iter.value() * v.getEntry(iter.key()));
    }
    /*
     * MATH-803: the above loop assumes that 0d * x  = 0d for any double x,
     * which allows to consider only the non-zero entries of this. However,
     * this fails if this[i] == 0d and (v[i] = NaN or v[i] = Infinity).
     *
     * These special cases are handled below.
     */
    if (v.isNaN() || v.isInfinite()) {
        int n = getDimension();
        for (int i = 0; i < n; i++) {
            double y = v.getEntry(i);
            if (Double.isNaN(y)) {
                res.setEntry(i, Double.NaN);
            } else if (Double.isInfinite(y)) {
                double x = this.getEntry(i);
                res.setEntry(i, x * y);
            }
        }
    }
    return res;
}