Skip to content

Commit

Permalink
Fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Jul 3, 2024
1 parent a8a25c8 commit 640605f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/MultivariateBases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ MP.monomial_type(::Type{<:Algebra{B}}) where {B} = MP.monomial_type(B)
function MP.polynomial_type(::Type{<:Algebra{B}}, ::Type{T}) where {B,T}
return MP.polynomial_type(B, T)
end
function MA.promote_operation(::typeof(SA.basis), ::Type{<:Algebra{B}}) where {B}
function MA.promote_operation(
::typeof(SA.basis),
::Type{<:Algebra{B}},
) where {B}
return B
end
SA.basis(a::Algebra) = a.basis
Expand Down
40 changes: 33 additions & 7 deletions src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,28 @@ const _AE = SA.AlgebraElement{<:Algebra}

for op in [:+, :-, :*]
@eval begin
function MA.promote_operation(::typeof($op), ::Type{P}, ::Type{Q}) where {P<:_APL,Q<:_AE}
function MA.promote_operation(
::typeof($op),
::Type{P},
::Type{Q},
) where {P<:_APL,Q<:_AE}
return MA.promote_operation($op, P, MP.polynomial_type(Q))
end
Base.$op(p::_APL, q::_AE) = $op(p, MP.polynomial(q))
function MA.promote_operation(::typeof($op), ::Type{P}, ::Type{Q}) where {P<:_AE,Q<:_APL}
function MA.promote_operation(
::typeof($op),
::Type{P},
::Type{Q},
) where {P<:_AE,Q<:_APL}
return MA.promote_operation($op, MP.polynomial_type(P), Q)
end
Base.$op(p::_AE, q::_APL) = $op(MP.polynomial(p), q)
# Break ambiguity between the two defined below and the generic one in SA
function MA.promote_operation(::typeof($op), ::Type{P}, ::Type{Q}) where {P<:_AE,Q<:_AE}
function MA.promote_operation(
::typeof($op),
::Type{P},
::Type{Q},
) where {P<:_AE,Q<:_AE}
return SA.algebra_promote_operation($op, P, Q)
end
function Base.$op(p::_AE, q::_AE)
Expand All @@ -23,24 +35,38 @@ for op in [:+, :-, :*]
end
for op in [:+, :-]
@eval begin
function MA.promote_operation(::typeof($op), ::Type{P}, ::Type{Q}) where {P,Q<:_AE}
function MA.promote_operation(
::typeof($op),
::Type{P},
::Type{Q},
) where {P,Q<:_AE}
I = MA.promote_operation(implicit, Q)
return MA.promote_operation(
$op,
constant_algebra_element_type(MA.promote_operation(SA.basis, I), P),
constant_algebra_element_type(
MA.promote_operation(SA.basis, I),
P,
),
I,
)
end
function Base.$op(p, q::_AE)
i = implicit(q)
return $op(constant_algebra_element(typeof(SA.basis(i)), p), i)
end
function MA.promote_operation(::typeof($op), ::Type{P}, ::Type{Q}) where {P<:_AE,Q}
function MA.promote_operation(
::typeof($op),
::Type{P},
::Type{Q},
) where {P<:_AE,Q}
I = MA.promote_operation(implicit, P)
return MA.promote_operation(
$op,
I,
constant_algebra_element_type(MA.promote_operation(SA.basis, I), Q),
constant_algebra_element_type(
MA.promote_operation(SA.basis, I),
Q,
),
)
end
function Base.$op(p::_AE, q)
Expand Down
4 changes: 3 additions & 1 deletion test/hermite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ end
M = typeof(x^2)
mono = MB.FullBasis{MB.Monomial,M}()
basis = MB.FullBasis{MB.PhysicistsHermite,M}()
err = ErrorException("Convertion from `$mono` to `$basis` not implemented yet")
err = ErrorException(
"Convertion from `$mono` to `$basis` not implemented yet",
)
@test_throws err SA.coeffs(MB.algebra_element(x + 1), basis)
end
5 changes: 2 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ end

function _test_basis(basis)
B = typeof(basis)
@test typeof(MB.algebra(basis)) ==
MA.promote_operation(MB.algebra, B)
@test typeof(MB.algebra(basis)) == MA.promote_operation(MB.algebra, B)
@test typeof(MB.constant_algebra_element(B, 1)) ==
MB.constant_algebra_element_type(B, Int)
MB.constant_algebra_element_type(B, Int)
end

function api_test(B::Type{<:MB.AbstractMonomialIndexed}, degree)
Expand Down

0 comments on commit 640605f

Please sign in to comment.