mljs/matrix

Cannot add a matrix and a 1x1 matrix

Closed this issue · 2 comments

Adding a matrix and a scalar works as expected, but adding a matrix and a 1x1 matrix throws RangeError('Matrices dimensions must be equal').

It would be convenient if the two were treated as equivalent; I don't know whether the current behavior is a bug or a deliberate design decision.

This works:

const { Matrix } = require('ml-matrix');
var A = new Matrix([[1, 1], [2, 2]]);
A.add(1)

But this doesn't:

const { Matrix } = require('ml-matrix');
var A = new Matrix([[1, 1], [2, 2]]);
A.add(Matrix.ones(1,1))

Hello, it was a deliberate design decision because it wasn't obvious to us what should be done with other cases.

  • What if B is smaller than A (6x6.plus(3x4))?
  • What if B is larger than A (6x6.plus(7x9))?

If we can give a consistent result to all possible cases, I'm all for implementing it.
Do you know what other matrix libraries do (in JS or other languages)?

I'll close this because there was no follow-up but feel free to restart the discussion.