mathjs icon indicating copy to clipboard operation
mathjs copied to clipboard

operations between jagged arrays and scalars

Open dvd101x opened this issue 1 month ago • 1 comments

Hi, this is the proof of concept discussed at #3537

It's more inline with what Jos and Glen suggested as my initial idea was flawed. This PR only shows two main changes.

  • refactors matAlgo14xDs to use it's map method and includes a hack to make the matrix creation faster.
  • makes a new matAlgo15xAs to map arrays that can be jagged or non homogeneous and there is no need to convert to matrix and then back to array.

My expectation is that all operations between Matrix|Array and scalar should be faster.

The new functionality is that it's possible to do stuff like

math.add([1,[2,3]], 1)

math.config({matrix:"Array"})
math.evaluate("[1,[2,3]] + 1")

dvd101x avatar Dec 09 '25 03:12 dvd101x

Nice! This actually simplifies the code since you can "just" use the map function.

What are the next steps? Add some unit tests for jagged inputs, update docs, and see what the performance impact is?

josdejong avatar Dec 10 '25 15:12 josdejong

Yes exactly, I will proceed with the next steps in the following weeks.

Maybe later I will come back to broadcasting jagged arrays.

dvd101x avatar Dec 11 '25 15:12 dvd101x