@Test public void testSum() { double[][] tmpResult; try { tmpResult = getBase((SetlMatrix) simple.sum(state, simple)).getArray(); } catch (SetlException ex) { System.err.println(ex.getMessage()); fail("simple_sum error: exception"); return; } double[][] cmpr = new double[2][2]; cmpr[0][0] = 2; cmpr[0][1] = 4; cmpr[1][0] = 6; cmpr[1][1] = 8; assertTrue("simple_sum error: wrong result: " + tmpResult + " vs " + cmpr, Arrays.deepEquals(tmpResult, cmpr)); try { tmpResult = getBase((SetlMatrix) sns.sum(state, sns)).getArray(); } catch (SetlException ex) { System.err.println(ex.getMessage()); fail("sns_sum error: exception"); return; } cmpr = new double[2][3]; cmpr[0][0] = 2; cmpr[0][1] = 4; cmpr[0][2] = 6; cmpr[1][0] = 8; cmpr[1][1] = 10; cmpr[1][2] = 12; assertTrue("sns_sum error: wrong result " + tmpResult + " vs " + cmpr, Arrays.deepEquals(tmpResult, cmpr)); try { sns.sum(null, simple); fail("sum missing_error"); } catch (IncompatibleTypeException ex) { } catch (SetlException ex) { System.err.println(ex.getMessage()); fail("sum wrong_error"); } }
@Override public Value sum(final State state, final Value summand) throws SetlException { boolean isMatrix = summand instanceof SetlMatrix; if(isMatrix || summand instanceof SetlVector) { SetlMatrix b = isMatrix ? (SetlMatrix)summand : new SetlMatrix(state, (SetlVector)summand); if(this.matrix.getColumnDimension() == b.matrix.getColumnDimension()) { if(this.matrix.getRowDimension() == b.matrix.getRowDimension()) { return new SetlMatrix(this.matrix.plus(b.matrix)); } else { throw new IncompatibleTypeException("Summands have different number of rows."); } } else { throw new IncompatibleTypeException("Summands have different number of columns."); } } else if(summand instanceof Term) { return ((Term)summand).sumFlipped(state, this); } else { throw new IncompatibleTypeException("Summand is not of type Matrix."); } }
SetlMatrix extends IndexedCollectionValue { @Override public Value sum(final State state, final Value summand) throws SetlException { boolean isMatrix = summand instanceof SetlMatrix; if(isMatrix || summand instanceof SetlVector) { SetlMatrix b = isMatrix ? (SetlMatrix)summand : new SetlMatrix(state, (SetlVector)summand); if(this.matrix.getColumnDimension() == b.matrix.getColumnDimension()) { if(this.matrix.getRowDimension() == b.matrix.getRowDimension()) { return new SetlMatrix(this.matrix.plus(b.matrix)); } else { throw new IncompatibleTypeException("Summands have different number of rows."); } } else { throw new IncompatibleTypeException("Summands have different number of columns."); } } else if(summand instanceof Term) { return ((Term)summand).sumFlipped(state, this); } else { throw new IncompatibleTypeException("Summand is not of type Matrix."); } } }
SetlMatrix extends IndexedCollectionValue { @Override public Value sum(final State state, final Value summand) throws SetlException { boolean isMatrix = summand instanceof SetlMatrix; if(isMatrix || summand instanceof SetlVector) { SetlMatrix b = isMatrix ? (SetlMatrix)summand : new SetlMatrix(state, (SetlVector)summand); if(this.matrix.getColumnDimension() == b.matrix.getColumnDimension()) { if(this.matrix.getRowDimension() == b.matrix.getRowDimension()) { return new SetlMatrix(this.matrix.plus(b.matrix)); } else { throw new IncompatibleTypeException("Summands have different number of rows."); } } else { throw new IncompatibleTypeException("Summands have different number of columns."); } } else if(summand instanceof Term) { return ((Term)summand).sumFlipped(state, this); } else { throw new IncompatibleTypeException("Summand is not of type 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 sum(final State state, final Value summand) throws SetlException { boolean isMatrix = summand instanceof SetlMatrix; if(isMatrix || summand instanceof SetlVector) { SetlMatrix b = isMatrix ? (SetlMatrix)summand : new SetlMatrix(state, (SetlVector)summand); if(this.matrix.getColumnDimension() == b.matrix.getColumnDimension()) { if(this.matrix.getRowDimension() == b.matrix.getRowDimension()) { return new SetlMatrix(this.matrix.plus(b.matrix)); } else { throw new IncompatibleTypeException("Summands have different number of rows."); } } else { throw new IncompatibleTypeException("Summands have different number of columns."); } } else if(summand instanceof Term) { return ((Term)summand).sumFlipped(state, this); } else { throw new IncompatibleTypeException("Summand is not of type 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 sum(final State state, final Value summand) throws SetlException { boolean isMatrix = summand instanceof SetlMatrix; if(isMatrix || summand instanceof SetlVector) { SetlMatrix b = isMatrix ? (SetlMatrix)summand : new SetlMatrix(state, (SetlVector)summand); if(this.matrix.getColumnDimension() == b.matrix.getColumnDimension()) { if(this.matrix.getRowDimension() == b.matrix.getRowDimension()) { return new SetlMatrix(this.matrix.plus(b.matrix)); } else { throw new IncompatibleTypeException("Summands have different number of rows."); } } else { throw new IncompatibleTypeException("Summands have different number of columns."); } } else if(summand instanceof Term) { return ((Term)summand).sumFlipped(state, this); } else { throw new IncompatibleTypeException("Summand is not of type 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();  }