Matrix subtraction ignores matrix size mismatch
Subtracting a matrix with n rows from a matrix with <n rows simply ignores the extra rows and returns a matrix with no clear mathematical interpretation.
a := PMMatrix rows: #((1 2)).
b := PMMatrix rows: #((1 2) (3 4)).
a - b. "a PMVector(0 0)"
Note that this behavior is different from interpolating matrix a with 0's, as then we would have a -3 and a -4. Instead, it just drops the second row entirely.
Can you wrote a test about that ?
I have submitted a slice with a new test.
Ok the test has been in PolyMath 0.93. We need to fix the code to pass the test now.
Any news on this ?
There was disagreement on the mailing list about whether matrix operations should include bounds checking, as this would slow down matrix computations. I have been planning to suggest a compromise, as there now exists a Contracts library that could do bounds checking with pragmas, thus letting people enable checking during development and turn it off at runtime with no performance penalty. It might look something like:
PMMatrix >> -
- aMatrix
<type: #sameDimensions: returns: #sameDimensions:>
"subtraction code here..."
and then people who want bounds checking to throw an error could enable it in their TestCase>>setUp with a line like:
'Polymath-Core' asPackage enableContractC.
And people who don't can just ignore it with no performance penalty. Technically, the pragmas could be added without adding any dependencies to the Polymath tests, but if Polymath wanted to use contracts in its own testing, it would just require a dependency from Polymath-Tests to Contracts.
I was thinking of proposing it to the mailing list, but I hadn't gotten around to it. What do you think?