Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,19 @@ end
Base.isapprox(p::_APL, α; kwargs...) = isapprox(promote(p, α)...; kwargs...)
Base.isapprox(α, p::_APL; kwargs...) = isapprox(promote(p, α)...; kwargs...)

MA.operate!(::typeof(-), ::AbstractTermLike) = error("not implemented yet")

MA.operate_to!(::AbstractTermLike, ::typeof(-), ::_APL) = error("not implemented yet")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we just keep the MethodError ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AbstractTermLike subtypes _APL, so we have to have a separate method. Do you want me to do throw(MethodError(...)) instead of error("not implemented yet")?


function MA.operate!(::typeof(-), p::_APL)
negate!! = x -> MA.operate!!(-, x)
return map_coefficients!(negate!!, p, nonzero = true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use Base.Fix1(MA.operate!!, -) to avoid creating a closure that might allocate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use Base.Fix1(MA.operate!!, -)

I prefer to never use either Fix1 or Fix2, because I can never remember which is which. Should I?

to avoid creating a closure that might allocate

In this case this is not an issue, as the closure doesn't capture any variables.

end

function MA.operate_to!(o::P, ::typeof(-), p::P) where {P<:_APL}
return map_coefficients_to!(o, -, p, nonzero = true)
end

# `MA.operate(-, p)` redirects to `-p` as it assumes that `-p` can be modified
# through the MA API without modifying `p`. We should either copy the monomial
# here or implement a `MA.operate(-, p)` that copies it. We choose the first
Expand Down