Skip to content

Commit

Permalink
vector setter and test
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlogic committed Dec 17, 2023
1 parent 52cb3a7 commit 82a2c9f
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 8 deletions.
30 changes: 28 additions & 2 deletions native/RealPolynomial.i
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,36 @@ import arb.algebra.Ring;

static { System.loadLibrary("arblib"); }

public Real set(int i, Real two)
/**
* Call this{@link #set(int, Real)} successively
*
* @param elements an array of values whose length is no greater than
* this{@link #getLength()}
* @return this
*/
public RealPolynomial set(Real... elements)
{
assert elements.length <= getLength() : String.format("cannot set elemenets of dimension %d because the dimension of this polynomials coeffecients is only %d\n",
elements.length,
getLength());
for (int i = 0; i < elements.length; i++)
{
set(i, elements[i]);
}
return this;
}

/**
* Set the value of the i-th element of this polynomial's coefficients
*
* @param i index which must be less than this{@link #getLength()}
* @param val value to be set
* @return this
*/
public Real set(int i, Real val)
{
assert i < getLength() : String.format("i = %d >= length = %d\n", i, getLength());
return get(i).set(two);
return get(i).set(val);
}

@Override
Expand Down
30 changes: 28 additions & 2 deletions src/main/java/arb/RealPolynomial.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,36 @@ public synchronized void delete() {

static { System.loadLibrary("arblib"); }

public Real set(int i, Real two)
/**
* Call this{@link #set(int, Real)} successively
*
* @param elements an array of values whose length is no greater than
* this{@link #getLength()}
* @return this
*/
public RealPolynomial set(Real... elements)
{
assert elements.length <= getLength() : String.format("cannot set elemenets of dimension %d because the dimension of this polynomials coeffecients is only %d\n",
elements.length,
getLength());
for (int i = 0; i < elements.length; i++)
{
set(i, elements[i]);
}
return this;
}

/**
* Set the value of the i-th element of this polynomial's coefficients
*
* @param i index which must be less than this{@link #getLength()}
* @param val value to be set
* @return this
*/
public Real set(int i, Real val)
{
assert i < getLength() : String.format("i = %d >= length = %d\n", i, getLength());
return get(i).set(two);
return get(i).set(val);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package arb.expressions;

import static arb.RealConstants.oneQuarter;
import static arb.RealConstants.two;
import static arb.RealConstants.π;
import static arb.functions.polynomials.RealPolynomialFunction.express;

import arb.RealConstants;
Expand All @@ -17,14 +20,16 @@ public static void testBasic()
x.set(0, RealConstants.two);
RealPolynomial y = new RealPolynomial(3);
context.registerVariable("y", y);
y.set(1, RealConstants.oneQuarter);
y.set(1, RealConstants.oneQuarter);
y.set(2, RealConstants.π);
RealPolynomialFunction f = express("x+y", context, true);
RealPolynomialFunction f = express("x+y", context, false);
RealPolynomial z = f.evaluate(x, 1, 128, new RealPolynomial());
System.out.format("x + y = z\n");
RealPolynomial correctZ = new RealPolynomial(3);
correctZ.set(two, oneQuarter, π );
System.out.format("x + y = z\n");
System.out.println("x=" + x);
System.out.println("y=" + y);
System.out.println("z=" + z);
assert false : "TODO: assert that z=[2,1/4,π]";
assertEquals( correctZ, z );
}
}

0 comments on commit 82a2c9f

Please sign in to comment.