Search in sources :

Example 91 with SortedMap

use of java.util.SortedMap in project symja_android_library by axkr.

the class ExprPolynomial method multiply.

/**
	 * GenPolynomial multiplication. Product with ring element and exponent
	 * vector.
	 * 
	 * @param s
	 *            coefficient.
	 * @param e
	 *            exponent.
	 * @return this * s x<sup>e</sup>.
	 */
public ExprPolynomial multiply(IExpr s, ExpVectorLong e) {
    if (s == null) {
        return ring.getZero();
    }
    if (s.isZero()) {
        return ring.getZero();
    }
    if (this.isZero()) {
        return this;
    }
    // if (this instanceof GenSolvablePolynomial) {
    // // throw new RuntimeException("wrong method dispatch in JRE ");
    // logger.debug("warn: wrong method dispatch in JRE multiply(s,e) -
    // trying to fix");
    // GenSolvablePolynomial<C> T = (GenSolvablePolynomial<C>) this;
    // return T.multiply(s, e);
    // }
    ExprPolynomial p = ring.getZero().copy();
    SortedMap<ExpVectorLong, IExpr> pv = p.val;
    for (Map.Entry<ExpVectorLong, IExpr> m1 : val.entrySet()) {
        IExpr c1 = m1.getValue();
        ExpVectorLong e1 = m1.getKey();
        // check non zero if not domain
        IExpr c = c1.multiply(s);
        if (!c.isZero()) {
            ExpVectorLong e2 = e1.sum(e);
            pv.put(e2, c);
        }
    }
    return p;
}
Also used : JASIExpr(org.matheclipse.core.convert.JASIExpr) IExpr(org.matheclipse.core.interfaces.IExpr) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 92 with SortedMap

use of java.util.SortedMap in project symja_android_library by axkr.

the class ExprPolynomial method multiply.

/**
	 * GenPolynomial multiplication.
	 * 
	 * @param S
	 *            GenPolynomial.
	 * @return this*S.
	 */
public ExprPolynomial multiply(ExprPolynomial S) {
    if (S == null) {
        return ring.getZero();
    }
    if (S.isZero()) {
        return ring.getZero();
    }
    if (this.isZero()) {
        return this;
    }
    assert (ring.nvar == S.ring.nvar);
    // if (this instanceof GenSolvablePolynomial && S instanceof
    // GenSolvablePolynomial) {
    // // throw new RuntimeException("wrong method dispatch in JRE ");
    // logger.debug("warn: wrong method dispatch in JRE multiply(S) - trying
    // to fix");
    // GenSolvablePolynomial<C> T = (GenSolvablePolynomial<C>) this;
    // GenSolvablePolynomial<C> Sp = (GenSolvablePolynomial<C>) S;
    // return T.multiply(Sp);
    // }
    ExprPolynomial p = ring.getZero().copy();
    SortedMap<ExpVectorLong, IExpr> pv = p.val;
    for (Map.Entry<ExpVectorLong, IExpr> m1 : val.entrySet()) {
        IExpr c1 = m1.getValue();
        ExpVectorLong e1 = m1.getKey();
        for (Map.Entry<ExpVectorLong, IExpr> m2 : S.val.entrySet()) {
            IExpr c2 = m2.getValue();
            ExpVectorLong e2 = m2.getKey();
            // check non zero if not domain
            IExpr c = c1.multiply(c2);
            if (!c.isZero()) {
                ExpVectorLong e = e1.sum(e2);
                IExpr c0 = pv.get(e);
                if (c0 == null) {
                    pv.put(e, c);
                } else {
                    c0 = c0.add(c);
                    if (!c0.isZero()) {
                        pv.put(e, c0);
                    } else {
                        pv.remove(e);
                    }
                }
            }
        }
    }
    return p;
}
Also used : JASIExpr(org.matheclipse.core.convert.JASIExpr) IExpr(org.matheclipse.core.interfaces.IExpr) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 93 with SortedMap

use of java.util.SortedMap in project symja_android_library by axkr.

the class ExprPolynomial method scaleSubtractMultiple.

/**
	 * GenPolynomial scale and subtract a multiple.
	 * 
	 * @param b
	 *            scale factor.
	 * @param a
	 *            coefficient.
	 * @param S
	 *            GenPolynomial.
	 * @return this * b - a S.
	 */
public ExprPolynomial scaleSubtractMultiple(IExpr b, IExpr a, ExprPolynomial S) {
    if (a == null || S == null) {
        return this.multiply(b);
    }
    if (a.isZero() || S.isZero()) {
        return this.multiply(b);
    }
    if (this.isZero() || b == null || b.isZero()) {
        // left?
        return S.multiply(a.negate());
    }
    if (b.isOne()) {
        return subtractMultiple(a, S);
    }
    assert (ring.nvar == S.ring.nvar);
    ExprPolynomial n = this.multiply(b);
    SortedMap<ExpVectorLong, IExpr> nv = n.val;
    SortedMap<ExpVectorLong, IExpr> sv = S.val;
    for (Map.Entry<ExpVectorLong, IExpr> me : sv.entrySet()) {
        ExpVectorLong f = me.getKey();
        // f = e.sum(f);
        // assert y != null
        IExpr y = me.getValue();
        // now y can be zero
        y = a.multiply(y);
        IExpr x = nv.get(f);
        if (x != null) {
            x = x.subtract(y);
            if (!x.isZero()) {
                nv.put(f, x);
            } else {
                nv.remove(f);
            }
        } else if (!y.isZero()) {
            nv.put(f, y.negate());
        }
    }
    return n;
}
Also used : JASIExpr(org.matheclipse.core.convert.JASIExpr) IExpr(org.matheclipse.core.interfaces.IExpr) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 94 with SortedMap

use of java.util.SortedMap in project symja_android_library by axkr.

the class ExprPolynomial method multiply.

/**
	 * GenPolynomial multiplication. Product with coefficient ring element.
	 * 
	 * @param s
	 *            coefficient.
	 * @return this*s.
	 */
public ExprPolynomial multiply(IExpr s) {
    if (s == null) {
        return ring.getZero();
    }
    if (s.isZero()) {
        return ring.getZero();
    }
    if (this.isZero()) {
        return this;
    }
    // if (this instanceof GenSolvablePolynomial) {
    // // throw new RuntimeException("wrong method dispatch in JRE ");
    // logger.debug("warn: wrong method dispatch in JRE multiply(s) - trying
    // to fix");
    // GenSolvablePolynomial<C> T = (GenSolvablePolynomial<C>) this;
    // return T.multiply(s);
    // }
    ExprPolynomial p = ring.getZero().copy();
    SortedMap<ExpVectorLong, IExpr> pv = p.val;
    for (Map.Entry<ExpVectorLong, IExpr> m1 : val.entrySet()) {
        IExpr c1 = m1.getValue();
        ExpVectorLong e1 = m1.getKey();
        // check non zero if not domain
        IExpr c = c1.multiply(s);
        if (!c.isZero()) {
            // or m1.setValue( c )
            pv.put(e1, c);
        }
    }
    return p;
}
Also used : JASIExpr(org.matheclipse.core.convert.JASIExpr) IExpr(org.matheclipse.core.interfaces.IExpr) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 95 with SortedMap

use of java.util.SortedMap in project opennms by OpenNMS.

the class RRDv3IT method testSamplesMultipleRRAs2.

/**
 * Test samples for multiple RRAs (2)
 *
 * @throws Exception the exception
 */
@Test
public void testSamplesMultipleRRAs2() throws Exception {
    File source = new File("src/test/resources/sample-counter-rras.xml");
    RRDv3 rrd = JaxbUtils.unmarshal(RRDv3.class, source);
    Assert.assertNotNull(rrd);
    SortedMap<Long, List<Double>> samples = rrd.generateSamples();
    Assert.assertFalse(samples.isEmpty());
    int size = rrd.getRras().stream().mapToInt(r -> r.getRows().size()).sum();
    // There are 3 timestamps that exist in both RRAs and the last one is incomplete
    Assert.assertEquals(size - 3 - 1, samples.size());
}
Also used : FileWriter(java.io.FileWriter) RRA(org.opennms.netmgt.rrd.model.v3.RRA) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) CFType(org.opennms.netmgt.rrd.model.v3.CFType) DSType(org.opennms.netmgt.rrd.model.v3.DSType) NavigableMap(java.util.NavigableMap) AbstractRRD(org.opennms.netmgt.rrd.model.AbstractRRD) File(java.io.File) ArrayList(java.util.ArrayList) List(java.util.List) RRDv3(org.opennms.netmgt.rrd.model.v3.RRDv3) Map(java.util.Map) JaxbUtils(org.opennms.core.xml.JaxbUtils) Assert(org.junit.Assert) Row(org.opennms.netmgt.rrd.model.Row) SortedMap(java.util.SortedMap) RRDv3(org.opennms.netmgt.rrd.model.v3.RRDv3) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Aggregations

SortedMap (java.util.SortedMap)228 Map (java.util.Map)174 TreeMap (java.util.TreeMap)115 HashMap (java.util.HashMap)66 NavigableMap (java.util.NavigableMap)33 ArrayList (java.util.ArrayList)31 Iterator (java.util.Iterator)31 Test (org.junit.Test)25 ImmutableMap (com.google.common.collect.ImmutableMap)21 IOException (java.io.IOException)20 List (java.util.List)17 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)17 JASIExpr (org.matheclipse.core.convert.JASIExpr)16 IExpr (org.matheclipse.core.interfaces.IExpr)16 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)14 File (java.io.File)14 Entry (java.util.Map.Entry)13 ConcurrentMap (java.util.concurrent.ConcurrentMap)12 ConcurrentNavigableMap (java.util.concurrent.ConcurrentNavigableMap)12 LinkedHashMap (java.util.LinkedHashMap)11