You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As mentioned in this discussion on Discourse, I am trying to programmatically construct symbols using sparse arrays. That is to say, I would like to programmatically generate/define a sparse array for which the non-zero entries are of type Sym, that can then subsequently be used in symbolic calculations and or other modules (e.g., ModelingToolkit.jl/DifferentialEquations.jl).
In general, I would be happy to use existing sparse array packages, like SparseArrays, and convert the sparse arrays to symbolic ones, i.e. something along the lines of
Is this possible? If yes, how? If not, how should I proceed? Note that the above example is just an illustrative example of what I would like to achieve. My personal use-case is to use sparse arrays as input variables of ODESystems (see the mentioned discussion), but in general I believe creating sparse array symbols that support sparse array methods can perhaps be useful.
If this is not the right place, or if anything is unclear, please let me know. Thanks a lot.
The text was updated successfully, but these errors were encountered:
I think this is not 100% what you have in mind, but it should work roughly.
using SparseArrays
using Symbolics
a =sprand(10, 10, 0.1)
nzrows, nzcols, nzvals =findnz(a)
A =map(CartesianIndices(a)) do id
iszero(a[id]) &&returnNum(0) # Gets detected
Symbolics.variable(:A, Tuple(id)...) # Return a variable for a nonzero entryend|> SparseMatrixCSC # Wrap in SparseMatrix
(A*A')[Base.OneTo(10),Base.OneTo(10)] # Still sparse
As mentioned in this discussion on Discourse, I am trying to programmatically construct symbols using sparse arrays. That is to say, I would like to programmatically generate/define a sparse array for which the non-zero entries are of type
Sym
, that can then subsequently be used in symbolic calculations and or other modules (e.g.,ModelingToolkit.jl
/DifferentialEquations.jl
).In general, I would be happy to use existing sparse array packages, like
SparseArrays
, and convert the sparse arrays to symbolic ones, i.e. something along the lines ofIs this possible? If yes, how? If not, how should I proceed? Note that the above example is just an illustrative example of what I would like to achieve. My personal use-case is to use sparse arrays as input variables of
ODESystem
s (see the mentioned discussion), but in general I believe creating sparse array symbols that support sparse array methods can perhaps be useful.If this is not the right place, or if anything is unclear, please let me know. Thanks a lot.
The text was updated successfully, but these errors were encountered: