Polynomials
Dense multivariate polynomials whose coefficients are stored in a fixed order defined by a MultiindexSet (Grlex-sorted).
MORFE.Polynomials.DensePolynomial — Type
DensePolynomial{T, NVAR, N, A}Cache-friendly dense polynomial with a single contiguous coefficient array.
Type parameters
| param | meaning |
|---|---|
T | Scalar element type (Float64, ComplexF64, …). Must be a concrete bits type for best performance. |
NVAR | Number of input variables. |
N | ndims(coefficients). Number of axes: N = 1 for scalar, N = 2 for vector-valued, etc. |
A | Concrete array type (Array{T,N} normally; can be an Mmap array). |
Fields
coefficients::A— shape(d1, …, d_{N-1}, L). The last axis indexes theLmonomials inmultiindex_set. Leading axes describe the coefficient shape (none for scalar,(K,)for a K-vector, etc.).multiindex_set::MultiindexSet{NVAR}— Grlex-ordered monomial basis.max_exponents::SVector{NVAR,Int}— per-variable max exponent (used to pre-allocate the power table inevaluate).
MORFE.Polynomials.DensePolynomial — Method
DensePolynomial(dict::Dict{Vector{Int}, SVector{K,T}}) where {K,T}Vector-valued polynomial from an exponent → SVector dictionary. Coefficients are laid out column-by-column (parallel fill).
MORFE.Polynomials.DensePolynomial — Method
DensePolynomial(dict::Dict{Vector{Int}, T}) where T<:NumberScalar polynomial from an exponent → coefficient dictionary.
MORFE.Polynomials.DensePolynomial — Method
DensePolynomial(coeff_vec::Vector{SVector{K,T}}, mset)Vector-valued polynomial from the old Vector{SVector} layout. Converts to a contiguous (K × L) matrix, filling columns in parallel.
MORFE.Polynomials._monomial_vector! — Method
_monomial_vector!(m, poly, vals)Fill the pre-allocated vector m (length L) with the value of each monomial in poly.multiindex_set evaluated at vals. This is the central loop; called once per evaluate.
MORFE.Polynomials._precompute_powers — Method
_precompute_powers(T, vals, max_exps) -> NTuple of VectorsFor each variable j, store vals[j]^e for e = 0 … max_exps[j]. Avoids repeated ^ calls inside the inner loop.
MORFE.Polynomials.coeff_shape — Method
coeff_shape(p) -> NTupleLeading axes of the coefficient array. () for scalar, (K,) for K-vector, (m,n) for a matrix-valued polynomial, etc.
MORFE.Polynomials.coefficient — Method
coefficient(p, exp) -> scalar or viewReturn the coefficient of the monomial with exponent exp. For scalar polynomials this is a T; for vector-valued it is a Vector{T} view into the backing array — no allocation.
MORFE.Polynomials.each_term — Method
each_term(poly) -> generator of (exponent, coefficient)Yields (SVector{NVAR,Int}, coeff) for every nonzero monomial.
- Scalar (N=1):
coeffis aT. - Vector (N=2):
coeffis aSubArray{T,1}view (no allocation).
MORFE.Polynomials.evaluate — Method
evaluate(poly::DensePolynomial{T,NVAR,1}, vals) -> TScalar polynomial evaluation: sum(c_i * m_i) without conjugation.
MORFE.Polynomials.evaluate — Method
evaluate(poly::DensePolynomial{T,NVAR,2}, vals, component::Int) -> TEvaluate a single component of a vector-valued polynomial without allocating a full output vector.
MORFE.Polynomials.evaluate — Method
evaluate(poly::DensePolynomial{T,NVAR,2}, vals) -> Vector{T}Vector-valued polynomial evaluation via BLAS gemv:
result = coefficients (K × L) * m (L,) → (K,)A single BLAS call, no per-term allocation.
MORFE.Polynomials.evaluate — Method
evaluate(poly::DensePolynomial{T,NVAR,N}, vals) -> ArrayGeneral tensor-valued case: reshape to (prod(leading_dims), L), gemv, reshape back.
MORFE.Polynomials.extract_component — Method
extract_component(poly::DensePolynomial{T,NVAR,2}, idx) -> DensePolynomial{T,NVAR,1}Return the idx-th component as a scalar polynomial. The coefficient vector is a copy of row idx of the matrix.
MORFE.Polynomials.linear_matrix_of_polynomial — Method
linear_matrix_of_polynomial(poly::DensePolynomial{T,NVAR,2}) -> Matrix{T}Return the (K × NVAR) matrix A such that the linear part equals A * x. Reads directly from the coefficient matrix — no intermediate arrays.
MORFE.Polynomials.mmap_polynomial — Method
mmap_polynomial(path, coeff_size::NTuple, T::Type, mset; write=false)Return a DensePolynomial whose coefficient array is backed by a memory-mapped file at path. coeff_size is the leading axes of the coefficient array (empty () for scalar, (K,) for K-vector, …).
The OS page-cache handles RAM pressure automatically: only accessed pages are loaded, so polynomials larger than available RAM work transparently.
Example
# 5-vector polynomial with 1 000 000 monomials, stored on disk
p = mmap_polynomial("coeffs.bin", (5,), Float64, mset; write=true)MORFE.Polynomials.similar_poly — Method
similar_poly(dict::Dict{SVector{NVAR,Int}, Vector{T}}) where {NVAR, T<:Number}Vector-valued polynomial from a dictionary mapping exponents to Vector{T} coefficients. All vectors must have the same length K.