Skip to content

Commit 36c3156

Browse files
authored
Fix ldiv for Julia v1.6 (#46)
* Fix ldiv for Julia v1.6 * Fix * Fix
1 parent 83c72e2 commit 36c3156

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

src/chebyshev.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ function SA.coeffs(
104104
ext = SA.coeffs(algebra_element(cfs, source), extended)
105105
return SA.SparseCoefficients(
106106
sub.monomials,
107-
LinearAlgebra.UpperTriangular(A) \ ext,
107+
#LinearAlgebra.UpperTriangular(A) \ ext, # Julia v1.6 converts `A` to the eltype of the `result` which is bad for JuMP
108+
LinearAlgebra.ldiv!(
109+
zeros(_promote_coef(eltype(ext), Chebyshev), size(A, 2)),
110+
LinearAlgebra.UpperTriangular(A),
111+
ext,
112+
),
108113
)
109114
end
110115

src/monomial.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ function Base.copy(basis::SubBasis)
118118
return typeof(basis)(copy(basis.monomials))
119119
end
120120

121-
Base.:(==)(a::SubBasis, b::SubBasis) = a.monomials == b.monomials
121+
function Base.:(==)(a::SubBasis{B}, b::SubBasis{B}) where {B}
122+
return a.monomials == b.monomials
123+
end
122124

123125
function algebra_type(::Type{BT}) where {B,M,BT<:MonomialIndexedBasis{B,M}}
124126
return Algebra{BT,B,M}

src/orthogonal.jl

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,8 @@ function univariate_orthogonal_basis(
105105
end
106106
end
107107

108-
function explicit_basis_covering(
109-
::FullBasis{B,M},
110-
monos::SubBasis{<:AbstractMonomial,M},
111-
) where {B<:AbstractMultipleOrthogonal,M}
112-
to_add = collect(monos.monomials)
108+
function _covering(::FullBasis{B,M}, monos) where {B,M}
109+
to_add = collect(monos)
113110
m = Set{M}(to_add)
114111
while !isempty(to_add)
115112
mono = pop!(to_add)
@@ -125,7 +122,22 @@ function explicit_basis_covering(
125122
end
126123
end
127124
end
128-
return SubBasis{B}(MP.monomial_vector(collect(m)))
125+
return collect(m)
126+
end
127+
128+
function explicit_basis_covering(
129+
full::FullBasis{BM,M},
130+
monos::SubBasis{B,M},
131+
) where {BM<:AbstractMonomial,B<:AbstractMultipleOrthogonal,M}
132+
full = FullBasis{B,M}()
133+
return SubBasis{BM}(_covering(full, monos.monomials))
134+
end
135+
136+
function explicit_basis_covering(
137+
full::FullBasis{B,M},
138+
monos::SubBasis{<:AbstractMonomial,M},
139+
) where {B<:AbstractMultipleOrthogonal,M}
140+
return SubBasis{B}(_covering(full, monos.monomials))
129141
end
130142

131143
function _scalar_product_function(::Type{<:AbstractMultipleOrthogonal}, i::Int) end

test/runtests.jl

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,23 @@ function _test_basis(basis)
2121
end
2222

2323
struct TypeA end
24-
struct TypeB end
2524
Base.zero(::Type{TypeA}) = TypeA()
25+
Base.iszero(::TypeA) = false
26+
LinearAlgebra.adjoint(::TypeA) = TypeA()
27+
struct TypeB end
28+
Base.zero(::Type{TypeB}) = TypeB()
29+
Base.iszero(::TypeB) = false
30+
LinearAlgebra.adjoint(::TypeB) = TypeB()
31+
2632
Base.:*(::Float64, ::TypeA) = TypeB()
33+
Base.:*(::TypeA, ::Float64) = TypeB()
34+
Base.:*(::Float64, ::TypeB) = TypeB()
35+
Base.:*(::TypeB, ::Float64) = TypeB()
36+
Base.:/(::TypeA, ::Float64) = TypeB()
37+
Base.:/(::TypeB, ::Float64) = TypeB()
38+
Base.:+(::TypeB, ::TypeB) = TypeB()
39+
Base.:-(::TypeB, ::TypeB) = TypeB()
40+
Base.convert(::Type{TypeB}, ::TypeA) = TypeB()
2741

2842
function api_test(B::Type{<:MB.AbstractMonomialIndexed}, degree)
2943
@polyvar x[1:2]
@@ -66,6 +80,15 @@ function api_test(B::Type{<:MB.AbstractMonomialIndexed}, degree)
6680
a = MB.algebra_element(ones(length(basis)), basis)
6781
_test_op(MB.implicit, a)
6882
@test SA.star(a) == a
83+
if B == Chebyshev || B == ScaledMonomial
84+
mono = explicit_basis_covering(
85+
FullBasis{Monomial,eltype(basis.monomials)}(),
86+
basis,
87+
)
88+
a = MB.algebra_element(fill(TypeA(), length(basis)), mono)
89+
@test SA.coeffs(a, full_basis).values ==
90+
fill(TypeB(), length(basis))
91+
end
6992
end
7093
mono = x[1]^2 * x[2]^3
7194
p = MB.Polynomial{B}(mono)

0 commit comments

Comments
 (0)