From 78023a81fb3843cb2e3b3434ad9b7b1c0fe362e8 Mon Sep 17 00:00:00 2001 From: ChrisRackauckas-Claude Date: Wed, 26 Aug 2026 04:55:08 -0400 Subject: [PATCH] Fix CanonicalMoments SymbolicsExt precompilation under Symbolics 7 The docs build fails while precompiling `CanonicalMoments -> SymbolicsExt`, which cascades into an OUQBase precompile failure, because the extension relies on two things that no longer hold with Symbolics 7: - `@register_array_symbolic` inspects each declared argument type, and `AbstractVecOrMat{<:Real}` is a `UnionAll` wrapping a `Union`. Symbolics 7 reaches for `.parameters` on it, raising `FieldError: type Union has no field parameters`. Declaring the argument as `AbstractArray{<:Real}` keeps both the vector and matrix cases without introducing a `Union`. - `Symbolics.array_term` was removed in Symbolics 7, so the manual companion matrix term construction cannot work. Registering `CanonicalMoments._companion_matrix` instead lets the macro build the lazy array term for symbolic inputs and fall through to the existing numeric implementation otherwise. Verified that the extension precompiles and that the symbolic support/weight path round-trips against the numeric implementation on both Symbolics 6.29.2 and 7.36.0, and that `docs/make.jl` completes. Co-authored-by: Cursor --- lib/CanonicalMoments/ext/SymbolicsExt.jl | 26 ++++++++++-------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/lib/CanonicalMoments/ext/SymbolicsExt.jl b/lib/CanonicalMoments/ext/SymbolicsExt.jl index 8949d76..451b742 100644 --- a/lib/CanonicalMoments/ext/SymbolicsExt.jl +++ b/lib/CanonicalMoments/ext/SymbolicsExt.jl @@ -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],) @@ -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