@Test public void testMultiply() { double[][] tmpResult; try { tmpResult = getBase((SetlMatrix) simple.product(null, simple)).getArray(); } catch (SetlException ex) { System.err.println(ex.getMessage()); fail("simple_simple_mul error: exception on .product"); return; } double[][] shouldBeResult = new double[2][2]; shouldBeResult[0][0] = 7; shouldBeResult[0][1] = 10; shouldBeResult[1][0] = 15; shouldBeResult[1][1] = 22; assertTrue("simple_simple_mul error: wrong result: " + tmpResult + " vs " + shouldBeResult, Arrays.deepEquals(tmpResult, shouldBeResult)); try { tmpResult = getBase((SetlMatrix) simple.product(null, sns)).getArray(); } catch (SetlException ex) { System.err.println(ex.getMessage()); fail("simple_sns_mul error: exception on .product " + ex.getMessage()); return; } shouldBeResult = new double[2][3]; shouldBeResult[0][0] = 9; shouldBeResult[0][1] = 12; shouldBeResult[0][2] = 15; shouldBeResult[1][0] = 19; shouldBeResult[1][1] = 26; shouldBeResult[1][2] = 33; assertTrue("simple_sns_mul error: wrong result: " + tmpResult + " vs " + shouldBeResult, Arrays.deepEquals(tmpResult, shouldBeResult)); try { sns.product(null, simple); fail("sns_simple missing_error: Incompatible dimensions not found"); } catch (IncompatibleTypeException ex) { } catch (SetlException ex) { System.err.println(ex.getMessage()); fail("sns_simple wrong_error: SetlException"); } for (int i = -10000; i <= 10000; i++) { try { tmpResult = getBase((SetlMatrix) simple.product(null, sdi.get(i))).getArray(); } catch (SetlException ex) { System.err.println(ex.getMessage()); fail("simple_scalar_mul error: exception on .product"); return; } assertTrue("simple_scalar_mul error: wrong result " + i, tmpResult[0][0] == (simpleBase[0][0] * i) && tmpResult[0][1] == (simpleBase[0][1] * i) && tmpResult[1][0] == (simpleBase[1][0] * i) && tmpResult[1][1] == (simpleBase[1][1] * i)); } for (int i = -10000; i <= 10000; i++) { try { tmpResult = getBase((SetlMatrix) sdi.get(i).product(null, simple)).getArray(); } catch (SetlException ex) { System.err.println(ex.getMessage()); fail("scalar_simple_mul error: exception on .product"); return; } assertTrue("scalar_simple_mul error: wrong result " + i, tmpResult[0][0] == (simpleBase[0][0] * i) && tmpResult[0][1] == (simpleBase[0][1] * i) && tmpResult[1][0] == (simpleBase[1][0] * i) && tmpResult[1][1] == (simpleBase[1][1] * i)); } }
@Override public Value product(final State state, final Value multiplier) throws SetlException { if(multiplier instanceof SetlMatrix) { SetlMatrix b = (SetlMatrix) multiplier; if(this.matrix.getColumnDimension() == b.matrix.getRowDimension()) { return new SetlMatrix(this.matrix.times(b.matrix)); } else { throw new IncompatibleTypeException("Matrix multiplication is only defined if the number of columns of the first matrix equals the number of rows of the second matrix."); } } else if(multiplier instanceof SetlVector) { SetlMatrix vectorMatrix = new SetlMatrix(state, (SetlVector) multiplier); if(this.matrix.getColumnDimension() == vectorMatrix.matrix.getRowDimension()) { Matrix result = this.matrix.times(vectorMatrix.matrix); if (result.getColumnDimension() == 1) { ArrayList<Double> vector = new ArrayList<>(); for (int i = 0; i < result.getRowDimension(); i++) { vector.add(result.get(i, 0)); } return new SetlVector(vector); } throw new UndefinedOperationException("Multiplication result has unexpected dimensions: " + new SetlMatrix(result).toString(state)); } else { throw new IncompatibleTypeException("Multiplication is only defined if the number of columns of the matrix equals the number of dimensions of the vector."); } } else if(multiplier instanceof NumberValue) { return new SetlMatrix(this.matrix.times(multiplier.toJDoubleValue(state))); } else if(multiplier instanceof Term) { return ((Term)multiplier).productFlipped(state, this); } else { throw new IncompatibleTypeException("Multiplier is not a matrix."); } }
SetlMatrix extends IndexedCollectionValue { @Override public Value product(final State state, final Value multiplier) throws SetlException { if(multiplier instanceof SetlMatrix) { SetlMatrix b = (SetlMatrix) multiplier; if(this.matrix.getColumnDimension() == b.matrix.getRowDimension()) { return new SetlMatrix(this.matrix.times(b.matrix)); } else { throw new IncompatibleTypeException("Matrix multiplication is only defined if the number of columns of the first matrix equals the number of rows of the second matrix."); } } else if(multiplier instanceof SetlVector) { SetlMatrix vectorMatrix = new SetlMatrix(state, (SetlVector) multiplier); if(this.matrix.getColumnDimension() == vectorMatrix.matrix.getRowDimension()) { Matrix result = this.matrix.times(vectorMatrix.matrix); if (result.getColumnDimension() == 1) { ArrayList<Double> vector = new ArrayList<>(); for (int i = 0; i < result.getRowDimension(); i++) { vector.add(result.get(i, 0)); } return new SetlVector(vector); } throw new UndefinedOperationException("Multiplication result has unexpected dimensions: " + new SetlMatrix(result).toString(state)); } else { throw new IncompatibleTypeException("Multiplication is only defined if the number of columns of the matrix equals the number of dimensions of the vector."); } } else if(multiplier instanceof NumberValue) { return new SetlMatrix(this.matrix.times(multiplier.toJDoubleValue(state))); } else if(multiplier instanceof Term) { return ((Term)multiplier).productFlipped(state, this); } else { throw new IncompatibleTypeException("Multiplier is not a matrix."); } } }
SetlMatrix extends IndexedCollectionValue { @Override public Value product(final State state, final Value multiplier) throws SetlException { if(multiplier instanceof SetlMatrix) { SetlMatrix b = (SetlMatrix) multiplier; if(this.matrix.getColumnDimension() == b.matrix.getRowDimension()) { return new SetlMatrix(this.matrix.times(b.matrix)); } else { throw new IncompatibleTypeException("Matrix multiplication is only defined if the number of columns of the first matrix equals the number of rows of the second matrix."); } } else if(multiplier instanceof SetlVector) { SetlMatrix vectorMatrix = new SetlMatrix(state, (SetlVector) multiplier); if(this.matrix.getColumnDimension() == vectorMatrix.matrix.getRowDimension()) { Matrix result = this.matrix.times(vectorMatrix.matrix); if (result.getColumnDimension() == 1) { ArrayList<Double> vector = new ArrayList<>(); for (int i = 0; i < result.getRowDimension(); i++) { vector.add(result.get(i, 0)); } return new SetlVector(vector); } throw new UndefinedOperationException("Multiplication result has unexpected dimensions: " + new SetlMatrix(result).toString(state)); } else { throw new IncompatibleTypeException("Multiplication is only defined if the number of columns of the matrix equals the number of dimensions of the vector."); } } else if(multiplier instanceof NumberValue) { return new SetlMatrix(this.matrix.times(multiplier.toJDoubleValue(state))); } else if(multiplier instanceof Term) { return ((Term)multiplier).productFlipped(state, this); } else { throw new IncompatibleTypeException("Multiplier is not a matrix."); } } SetlMatrix(Jama.Matrix v);  SetlMatrix(final State state, final List<SetlVector> vectors);  SetlMatrix(final State state, final CollectionValue init);  SetlMatrix(final State state, final SetlVector vector); }
SetlMatrix extends IndexedCollectionValue { @Override public Value product(final State state, final Value multiplier) throws SetlException { if(multiplier instanceof SetlMatrix) { SetlMatrix b = (SetlMatrix) multiplier; if(this.matrix.getColumnDimension() == b.matrix.getRowDimension()) { return new SetlMatrix(this.matrix.times(b.matrix)); } else { throw new IncompatibleTypeException("Matrix multiplication is only defined if the number of columns of the first matrix equals the number of rows of the second matrix."); } } else if(multiplier instanceof SetlVector) { SetlMatrix vectorMatrix = new SetlMatrix(state, (SetlVector) multiplier); if(this.matrix.getColumnDimension() == vectorMatrix.matrix.getRowDimension()) { Matrix result = this.matrix.times(vectorMatrix.matrix); if (result.getColumnDimension() == 1) { ArrayList<Double> vector = new ArrayList<>(); for (int i = 0; i < result.getRowDimension(); i++) { vector.add(result.get(i, 0)); } return new SetlVector(vector); } throw new UndefinedOperationException("Multiplication result has unexpected dimensions: " + new SetlMatrix(result).toString(state)); } else { throw new IncompatibleTypeException("Multiplication is only defined if the number of columns of the matrix equals the number of dimensions of the vector."); } } else if(multiplier instanceof NumberValue) { return new SetlMatrix(this.matrix.times(multiplier.toJDoubleValue(state))); } else if(multiplier instanceof Term) { return ((Term)multiplier).productFlipped(state, this); } else { throw new IncompatibleTypeException("Multiplier is not a matrix."); } } SetlMatrix(Jama.Matrix v);  SetlMatrix(final State state, final List<SetlVector> vectors);  SetlMatrix(final State state, final CollectionValue init);  SetlMatrix(final State state, final SetlVector vector); @Override Value clone(); @Override Iterator<Value> iterator(); @Override Iterator<Value> descendingIterator(); @Override SetlBoolean isMatrix(); SetlVector toVector(); @Override Value difference(final State state, final Value subtrahend); @Override Value differenceAssign(final State state, final Value subtrahend); @Override Value factorial(final State state); @Override Value power(final State state, final Value exponent); @Override Value product(final State state, final Value multiplier); @Override Value productAssign(final State state, final Value multiplier); @Override Value sum(final State state, final Value summand); @Override Value sumAssign(final State state, final Value summand); @Override void addMember(State state, Value element); @Override SetlBoolean containsMember(State state, Value element); @Override Value firstMember(); @Override Value getMember(int index); @Override Value getMember(State state, Value index); @Override Value getMembers(final State state, final int expectedNumberOfMembers, final int lowFromStart, final int highFromStart); @Override Value lastMember(); @Override Value maximumMember(State state); @Override Value minimumMember(State state); @Override Value removeFirstMember(); @Override Value removeLastMember(); @Override void removeMember(State state, Value element); @Override void setMember(final State state, final Value index, final Value value); @Override void setMember(final State state, int index, final Value value); @Override int size(); SetlDouble condition(); SetlDouble determinant(); SetlList eigenVectors(State state); SetlMatrix hadamardProduct(State state, Value other); SetlList eigenValues(State state); SetlMatrix pseudoInverse(); SetlList singularValueDecomposition(State state); Value solve(SetlMatrix other); @Override void appendString(final State state, final StringBuilder sb, final int tabs); @Override void canonical(final State state, final StringBuilder sb); @Override MatchResult matchesTerm(State state, Value other); @Override int compareTo(CodeFragment other); @Override long compareToOrdering(); @Override boolean equalTo(Object other); @Override int hashCode(); }
SetlMatrix extends IndexedCollectionValue { @Override public Value product(final State state, final Value multiplier) throws SetlException { if(multiplier instanceof SetlMatrix) { SetlMatrix b = (SetlMatrix) multiplier; if(this.matrix.getColumnDimension() == b.matrix.getRowDimension()) { return new SetlMatrix(this.matrix.times(b.matrix)); } else { throw new IncompatibleTypeException("Matrix multiplication is only defined if the number of columns of the first matrix equals the number of rows of the second matrix."); } } else if(multiplier instanceof SetlVector) { SetlMatrix vectorMatrix = new SetlMatrix(state, (SetlVector) multiplier); if(this.matrix.getColumnDimension() == vectorMatrix.matrix.getRowDimension()) { Matrix result = this.matrix.times(vectorMatrix.matrix); if (result.getColumnDimension() == 1) { ArrayList<Double> vector = new ArrayList<>(); for (int i = 0; i < result.getRowDimension(); i++) { vector.add(result.get(i, 0)); } return new SetlVector(vector); } throw new UndefinedOperationException("Multiplication result has unexpected dimensions: " + new SetlMatrix(result).toString(state)); } else { throw new IncompatibleTypeException("Multiplication is only defined if the number of columns of the matrix equals the number of dimensions of the vector."); } } else if(multiplier instanceof NumberValue) { return new SetlMatrix(this.matrix.times(multiplier.toJDoubleValue(state))); } else if(multiplier instanceof Term) { return ((Term)multiplier).productFlipped(state, this); } else { throw new IncompatibleTypeException("Multiplier is not a matrix."); } } SetlMatrix(Jama.Matrix v);  SetlMatrix(final State state, final List<SetlVector> vectors);  SetlMatrix(final State state, final CollectionValue init);  SetlMatrix(final State state, final SetlVector vector); @Override Value clone(); @Override Iterator<Value> iterator(); @Override Iterator<Value> descendingIterator(); @Override SetlBoolean isMatrix(); SetlVector toVector(); @Override Value difference(final State state, final Value subtrahend); @Override Value differenceAssign(final State state, final Value subtrahend); @Override Value factorial(final State state); @Override Value power(final State state, final Value exponent); @Override Value product(final State state, final Value multiplier); @Override Value productAssign(final State state, final Value multiplier); @Override Value sum(final State state, final Value summand); @Override Value sumAssign(final State state, final Value summand); @Override void addMember(State state, Value element); @Override SetlBoolean containsMember(State state, Value element); @Override Value firstMember(); @Override Value getMember(int index); @Override Value getMember(State state, Value index); @Override Value getMembers(final State state, final int expectedNumberOfMembers, final int lowFromStart, final int highFromStart); @Override Value lastMember(); @Override Value maximumMember(State state); @Override Value minimumMember(State state); @Override Value removeFirstMember(); @Override Value removeLastMember(); @Override void removeMember(State state, Value element); @Override void setMember(final State state, final Value index, final Value value); @Override void setMember(final State state, int index, final Value value); @Override int size(); SetlDouble condition(); SetlDouble determinant(); SetlList eigenVectors(State state); SetlMatrix hadamardProduct(State state, Value other); SetlList eigenValues(State state); SetlMatrix pseudoInverse(); SetlList singularValueDecomposition(State state); Value solve(SetlMatrix other); @Override void appendString(final State state, final StringBuilder sb, final int tabs); @Override void canonical(final State state, final StringBuilder sb); @Override MatchResult matchesTerm(State state, Value other); @Override int compareTo(CodeFragment other); @Override long compareToOrdering(); @Override boolean equalTo(Object other); @Override int hashCode();  }