Skip to content

Commit

Permalink
Make code more basis independent
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Nov 23, 2023
1 parent 442c962 commit e95b80d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/border.jl
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ function solve(b::BorderBasis{E}, solver::AlgebraicBorderSolver{D}) where {D,E}
ind = independent_basis(b)
dep = dependent_basis(b.dependence)
system = [
dep.monomials[col] - MP.polynomial(b.matrix[:, col], ind) for
col in eachindex(dep.monomials)
MB.generators(dep)[col] - MP.polynomial(b.matrix[:, col], ind) for
col in eachindex(dep)
]
filter!(!MP.isconstant, system)
V = if MP.mindegree(b.dependence) == MP.maxdegree(b.dependence)
Expand Down
37 changes: 20 additions & 17 deletions src/dependence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,16 @@ function Base.show(io::IO, d::BasisDependence)
else
println(io, "bases:")
end
for (cat, monos) in basis_categories(d)
for (cat, basis) in basis_categories(d)
println(io, " ", category_label(cat), ":")
println(io, " ", MB.MonomialBasis(monos))
println(io, " ", basis)
end
return
end

function sub_basis(d::BasisDependence, I::AbstractVector{Int})
@assert issorted(I)
return typeof(d.basis)(d.basis.monomials[I])
return d.basis[I]
end

function independent_basis(d::BasisDependence)
Expand Down Expand Up @@ -197,13 +197,13 @@ end

function BasisDependence{LinearDependence}(
r,
basis::MB.MonomialBasis{M},
) where {M}
basis::MB.AbstractPolynomialBasis,
)
return BasisDependence(
basis,
LinearDependence[
is_dependent!(r, i) ? DEPENDENT : INDEPENDENT for
i in eachindex(basis.monomials)
i in eachindex(basis)
],
)
end
Expand Down Expand Up @@ -238,7 +238,7 @@ function BasisDependence{StaircaseDependence}(
r,
basis::MB.MonomialBasis{M},
) where {M}
if isempty(basis.monomials)
if isempty(basis)
return BasisDependence(basis, StaircaseDependence[])
end
function dependence(mono)
Expand Down Expand Up @@ -312,28 +312,31 @@ end
MP.variables(d::BasisDependence) = MP.variables(d.basis.monomials)

function MP.mindegree(d::BasisDependence, args...)
return MP.mindegree(d.basis.monomials, args...)
return MP.mindegree(d.basis, args...)
end

function MP.maxdegree(d::BasisDependence, args...)
return MP.maxdegree(d.basis.monomials, args...)
return MP.maxdegree(d.basis, args...)
end

function _ticks(d::BasisDependence, v)
return MP.mindegree(d, v):MP.maxdegree(d, v)
end

function basis_categories(d::BasisDependence{D}) where {D}
M = eltype(d.basis.monomials)
categories = Dict{D,Vector{M}}()
for (i, mono) in enumerate(d.basis.monomials)
categories = Dict{D,Vector{Int}}()
for i in eachindex(d.basis)
cat = d.dependence[i]
if !haskey(categories, cat)
categories[cat] = M[]
categories[cat] = Int[]
end
push!(categories[cat], mono)
push!(categories[cat], i)
end
cats = [(cat, d.basis[I]) for (cat, I) in categories]
if eltype(cats) <: MP.AbstractMonomial
sort!(cats)
end
return sort!(collect(categories))
return cats
end

RecipesBase.@recipe function f(d::BasisDependence)
Expand All @@ -345,14 +348,14 @@ RecipesBase.@recipe function f(d::BasisDependence)
if length(t) >= 3
zticks --> t[3]
end
for (cat, monos) in basis_categories(d)
for (cat, basis) in basis_categories(d)
RecipesBase.@series begin
seriestype --> :scatter
markercolor --> category_markercolor(cat)
markershape --> category_markershape(cat)
markerstrokewidth --> category_markerstrokewidth(cat)
label := category_label(cat)
_split_exponents(monos)
_split_exponents(generators(basis))
end
end
end

0 comments on commit e95b80d

Please sign in to comment.