PolyMath icon indicating copy to clipboard operation
PolyMath copied to clipboard

Matrix subtraction ignores matrix size mismatch

Open emdonahue opened this issue 8 years ago • 5 comments

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.

emdonahue avatar May 19 '17 13:05 emdonahue

Can you wrote a test about that ?

SergeStinckwich avatar May 19 '17 16:05 SergeStinckwich

I have submitted a slice with a new test.

emdonahue avatar May 19 '17 16:05 emdonahue

Ok the test has been in PolyMath 0.93. We need to fix the code to pass the test now.

SergeStinckwich avatar Dec 31 '17 15:12 SergeStinckwich

Any news on this ?

SergeStinckwich avatar Jun 28 '18 09:06 SergeStinckwich

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?

emdonahue avatar Jun 28 '18 18:06 emdonahue