After sending out my query to the groovy user list I got back some ideas (no offense to Yann, just something I need to tackle on my own, so I didn’t look at your solution). What I ended up doing was two-fold:
- Create a new MetaClass using ExpandoMetaClass
- Define a new class that understood what row and matrix it was going to operate on (so it can have its own operator overloading)
Yes it was a little bit of extra work, but worth it. I also implemented my or operator overloading so that I can specify augmented matrices in three formats:
A|Ifor the identity matrix (only works on square matrices)A|0for the zero column, used for solving the set of linear equationsA|bfor a vector column, also used for solving the set of linear equations
As always it helps to learn from others’ mistakes (and oddities) so I’ll share mine along the road:
- When dealing with EMC (ExpandoMetaClass) watch out for the use of the
thiskeyword - Closure delegates don’t always act the way you would hope when extending
GroovyObjectSupport(at least I couldn’t get it to work right which is one reason why I switched to EMC) - Overriding the
oroperator works fine until you get to an object that has overridden theequalsoperator. In this case Groovy kept trying to find out if myMatrixwas equal to myMatrixColumn. Once I figured this out I just returned false if theMatrixColumnwas being compared against aMatrixthen it worked as expected.
The next part I want to add is the ability to track the EROs through Elementary Matrices. These are matrices that start out as 1s along the diagonal and they get the same EROs applied to them (this will be useful further down the line for other operations).
Related Posts: