Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Efficient reducing functions (maximum, sum, etc.) #115

Open
kshedden opened this issue Oct 17, 2023 · 5 comments
Open

Efficient reducing functions (maximum, sum, etc.) #115

kshedden opened this issue Oct 17, 2023 · 5 comments

Comments

@kshedden
Copy link

It seems that currently the package iterates over the full matrix rather than exploiting the Toeplitz structure.

@dlfivefifty
Copy link
Member

We'd be happy to merge a PR that fixes this

@putianyi889
Copy link
Contributor

mapreduce would be the one to implement

@dlfivefifty
Copy link
Member

I don’t think mapreduce is really possible: consider mapreduce(identity, max, A) vs mapreduce(identity, +,A). I don’t think there’s a way to optimise both for toeplitz

@putianyi889
Copy link
Contributor

Technically it's partially possible once #86 is merged: for commutative operations and mapreduce without the dim argument, do mapreduce on all diagonals that are Fills (assuming FillArrays.jl has that implemented), then do mapreduce again on the results. sum would need to work like this while maximum could be easier to do.

Anyway, maximum and sum with a dim argument are not trivial. Circulant has shortcuts, otherwise there need to be some special algorithms.

@putianyi889
Copy link
Contributor

Example:

for op in (:+, :max)
    @eval mapreduce(f, ::typeof($op), A::AbstractToeplitz) = mapreduce(identity, $op, [mapreduce(f, $op, diag(A, k)) for k in -size(A,1)+1:size(A,2)-1])
end

Note that there is an allocation which might be avoided by using a generator/lazy array. This only works after #86 and JuliaArrays/FillArrays.jl#301

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants