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

Eigen for AbstractFill and eigvals for Tridiagonal{<:Number,<:AbstractFillVector} #256

Closed
wants to merge 17 commits into from

Conversation

jishnub
Copy link
Member

@jishnub jishnub commented May 27, 2023

The various tridiagonal matrices that wrap AbstractFillVectors are Toeplitz matrices, and their eigenvalues may be computed analytically in O(n) time, and eigenvectors in O(n^2). Aside from this, since a square AbstractFillMatrix is of rank-1, it has only one non-zero eigenvalue that may be computed trivially in O(1) time, and the eigenvectors may also be evaluated in O(n^2).

julia> T = Tridiagonal(Fill(2,400), Fill(5,401), Fill(2,400));

julia> @btime eigvals($T);
  12.503 μs (1 allocation: 3.31 KiB)  # This PR
  8.211 ms (11 allocations: 1.37 MiB) # master

julia> @btime eigen($T);
  875.773 μs (4 allocations: 2.46 MiB) # This PR
  26.678 ms (16 allocations: 3.83 MiB) # master

julia> F = Fill(2, 40, 40);

julia> @btime eigvals($F); # This PR
  4.211 ns (0 allocations: 0 bytes)

julia> @btime eigen($F);
  1.444 μs (1 allocation: 12.62 KiB)

julia> @btime eigvals($(Matrix(F))); # as on aster
  106.181 μs (10 allocations: 27.94 KiB)

@codecov
Copy link

codecov bot commented May 27, 2023

Codecov Report

Merging #256 (d3ad175) into master (91f9f6f) will increase coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #256      +/-   ##
==========================================
+ Coverage   99.74%   99.77%   +0.03%     
==========================================
  Files           5        5              
  Lines         771      882     +111     
==========================================
+ Hits          769      880     +111     
  Misses          2        2              
Impacted Files Coverage Δ
src/FillArrays.jl 99.42% <ø> (ø)
src/fillalgebra.jl 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@jishnub
Copy link
Member Author

jishnub commented Jun 5, 2023

I'm not fully sure about d5ff1e4, where I evaluate sin(pi*q*j/(n+1)) iteratively. This is faster than calling sinpi on each iteration, but this might reduce the accuracy for large matrices as floating-point errors pile up. Should we revert this, and go back to calling sinpi in each iteration?

@dlfivefifty
Copy link
Member

I don't really think this PR belongs here, it's too complicated for this package.... ToeplitzMatrices.jl would be a better home even if it means type-piracy...

@jishnub
Copy link
Member Author

jishnub commented Jun 5, 2023

Perhaps this can be simplified somewhat by removing the eigenvalue sorting. The Toeplitz component may be moved to ToeplitzMatrices, but the eigen for FillArrays may remain here?

@dlfivefifty
Copy link
Member

Yes I'm happy for the eigen for Fill to be here... just Toeplitz matrices becomes a bit too algorithmic and then its harder to maintain...

@jishnub
Copy link
Member Author

jishnub commented Jul 15, 2023

I've moved the tridiagonal methods to ToeplitzMatrices.jl. I'm closing this for now, as eigen for Fill arrays is perhaps not a very useful operation (and it's trivial in any case)

@jishnub jishnub closed this Jul 15, 2023
@jishnub jishnub deleted the eigvals branch July 15, 2023 03:54
@jishnub jishnub mentioned this pull request Dec 22, 2023
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

Successfully merging this pull request may close these issues.

None yet

2 participants