From 4c99d67232f2f65391c30bfaed8b00763abde4b3 Mon Sep 17 00:00:00 2001 From: villberg Date: Fri, 26 Sep 2014 12:56:14 +0000 Subject: [PATCH] Ones was broken, transpose was missing, multiplication operator did not handle all cases. Better error reporting. Detection and reporting of infinities. refs #5224 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30323 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../src/fi/semantum/sysdyn/solver/Array.java | 61 ++++++++++++++++++- .../semantum/sysdyn/solver/Environment.java | 13 +++- .../sysdyn/solver/Multiplication.java | 4 ++ .../src/fi/semantum/sysdyn/solver/Solver.java | 7 ++- 4 files changed, 82 insertions(+), 3 deletions(-) diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java index e7b1959d..6cdc5b83 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java @@ -16,6 +16,9 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +/* + * For matrices first dimension is rows and second is columns i.e. top level elements are rows + */ public class Array implements IExpression { public static final Array FULL = new Array(); @@ -309,7 +312,7 @@ public class Array implements IExpression { double result = 0; Collection lae = elements(); Collection rae = other.elements(); - if(lae.size() != rae.size()) throw new IllegalStateException(); + if(lae.size() != rae.size()) throw new IllegalStateException("inner product: vector sizes do not match: " + this + " vs. " + other); Iterator li = lae.iterator(); Iterator ri = rae.iterator(); for(int i=0;i lae = elements(); @@ -535,5 +569,30 @@ public class Array implements IExpression { public void applyPartial(Array[] indices, Array value) { applyPartial(indices, value, 0); } + + public Array transposed() { + + List elements = elements(); + if(elements.isEmpty()) return this; + + Array first = (Array)elements.get(0); + + Array[] arrs = new Array[first.elements().size()]; + for(int i=0;i