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;
}
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;
}
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;
}
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;
}
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());
}
Aggregations