josdejong / josdejong/mathjs

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

Open
#3,609 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
15.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

**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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.