Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions lib/CanonicalMoments/ext/SymbolicsExt.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module SymbolicsExt
using Symbolics
import Symbolics: unwrap, wrap, array_term
using CanonicalMoments
using LinearAlgebra

@register_array_symbolic (alg::CanonicalMoments.EigvalSupportAlg)(M::AbstractMatrix{<:Real}) begin
size = (size(M)[1],)
Expand All @@ -14,26 +12,24 @@ end
eltype = eltype(M)
end

# `AbstractVecOrMat` is a `Union` alias, which `@register_array_symbolic` cannot
# introspect; `AbstractArray` covers both the vector and matrix cases.
@register_array_symbolic (alg::CanonicalMoments.EigvecWeightAlg)(
M::AbstractMatrix{<:Real},
λ::AbstractVecOrMat{<:Real},
λ::AbstractArray{<:Real},
) begin
size = size(M)
eltype = eltype(M)
end

function CanonicalMoments._companion_matrix(B::Vector{Num}, C::Vector{Num})
dv = -B
ndims = length(B)
ev = sqrt.(C[2:end]) # Probably use views here
_comp_mat_unwrapped = array_term(
SymTridiagonal,
unwrap.(dv),
unwrap.(ev);
eltype = Real,
size = (ndims, ndims),
)
return wrap(_comp_mat_unwrapped)
# Registering the companion matrix constructor keeps it lazy for symbolic inputs
# while deferring to the numeric implementation otherwise.
@register_array_symbolic CanonicalMoments._companion_matrix(
B::AbstractVector{<:Real},
C::AbstractVector{<:Real},
) begin
size = (length(B), length(B))
eltype = Real
end

end
Loading