mathjs icon indicating copy to clipboard operation
mathjs copied to clipboard

sparse() silently converts `false` entries to `0`

Open gwhitney opened this issue 1 month ago • 1 comments

Describe the bug There does not seem to be any way to put a false value into a SparseMatrix.

To reproduce In the mathjs.org REPL:

sparse([[true, false]]).valueOf()
    [[true, 0]]

sparse([[true, false]], 'boolean').valueOf()
    Error: There are no conversions to boolean defined.

The error message in the second case is particularly mysterious, because there does not appear to be any conversion necessary: all of the inputs are boolean, and the requested type is boolean.

The difficulty seems to be twofold: (a) SparseMatrix's methodology for selecting the zero value of a given instance does not currently handle boolean (or for that matter, bigint). (b) A SparseMatrix instance does not remember its own zero value.

I will submit a PR for this bug once we reach some plan of action for #3608. Thanks.

gwhitney avatar Dec 10 '25 06:12 gwhitney

Thanks for reporting this bug Glen!

josdejong avatar Dec 10 '25 14:12 josdejong