Skip to content

Allocation-free 5-arg mul! for custom maps #75

@jagot

Description

@jagot

This is basically a follow-up to #56;

If I have a custom type for which I have a defined a allocation-free 5-arg mul!

struct MyIntegralOperator{T} <: LinearMap{T}
...
end

mul!(y, A::MyIntegralOperator, x, α=true, β=false) = ...

which I want to form linear combinations of, how do I get allocation-free application? Right now, I think I need to duplicate the following functions, since it is not possible for types outside of LinearMaps.jl to belong to FreeMap:

https://github.com/Jutho/LinearMaps.jl/blob/95cc89cffff4b980af41aea32483af739a2d168c/src/linearcombination.jl#L83-L93

and

https://github.com/Jutho/LinearMaps.jl/blob/95cc89cffff4b980af41aea32483af739a2d168c/src/linearcombination.jl#L113-L138

A possible approach could be to tag the LinearCombination object with a trait, i.e. a type parameter (e.g. MulStyle) that indicates which method to dispatch to. Then the user would only need to overload mulstyle(::MyIntegralOperator) = FiveArgs. This pattern has been used to great effect in e.g. https://github.com/JuliaArrays/LazyArrays.jl/blob/db8b20746c26873d635df18bcaac06382def11bb/src/linalg/muladd.jl

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions