Skip to content

Different behavior of map(array) vs map(matrix) #3241

@dvd101x

Description

@dvd101x

Hi,

On the current version 13.0.3

By running some tests and changing from Array to Matrix, I'm getting an unexpected error.

math.map([1, 8, 27], math.format) //['1', '8', '27']

math.map(math.matrix([1, 8, 27]), math.format)  // TypeError: Unexpected type of argument in function format (expected: number or BigNumber or function or Object or bigint or Fraction or string or boolean, actual: Array, index: 1)

The source of the issue might be that the array implementation is using applyCallback but the matrix implementation is using maxArgumentCount.

It can be fixed by changing

  'Matrix, function': function (x, callback) {
    return x.map(callback)
  }

to

'Matrix, function': (M, callback) => M.create(_map(M.toArray(), callback))

But then Matrix.map still has the issue in math.matrix([1, 8, 27]).map(math.format)

Some of the logic of mapping an array and mapping a matrix is repeated but having a few differences. Maybe there is an opportunity to use a single implementation either in Matrix, in Array or making both of them match.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions