Skip to content

Assigning symbolic SparseArrays fails #6

@davidschlegel

Description

@davidschlegel

If I want to have a multi-dimensional sparse array. I could define

using Symbolics
using SparseArrayKit

@variables a
 A = SparseArray{Num}(undef, (1,2,3)) #3dimesional array with size 1, 2, and 3 each
A[1,1,1] = a

But this gives the well-known error
ERROR: TypeError: non-boolean used in boolean context
This is due to the fact that in line #34 of sparsearray.jl we have the zero-comparison if v != zero(v).
This however fails for symbolic expressions as == or != defines an equation.
In this context, one should use if v !== zero(v) to evaluate the expression. Then everything works and still works for regular numbers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions