Skip to content

sparse() silently converts false entries to 0 #3609

@gwhitney

Description

@gwhitney

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions