JuliaLinearAlgebra / LinearMaps.jl

A Julia package for defining and working with linear maps, also known as linear transformations or linear operators acting on vectors. The only requirement for a LinearMap is that it can act on a vector (by multiplication) efficiently.
Other
303 stars 42 forks source link

Overload `LinearAlgebra.tr` #210

Closed dkarrasch closed 1 year ago

dkarrasch commented 1 year ago

Some users expressed interest in the trace function, so here we go. In the generic case, this is, of course, expensive, but in some cases we may leverage the lazy structure and algebraic rules to compute the trace allocation-free, like in the (lazy) Kronecker product of two square matrices. Another included classic use case is (lazy) rank-one matrices.

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01 :tada:

Comparison is base (b6b1044) 99.67% compared to head (fd150d4) 99.68%.

:exclamation: Current head fd150d4 differs from pull request most recent head bfaefd5. Consider uploading reports for the commit bfaefd5 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #210 +/- ## ========================================== + Coverage 99.67% 99.68% +0.01% ========================================== Files 21 22 +1 Lines 1540 1591 +51 ========================================== + Hits 1535 1586 +51 Misses 5 5 ``` | [Impacted Files](https://app.codecov.io/gh/JuliaLinearAlgebra/LinearMaps.jl/pull/210?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaLinearAlgebra) | Coverage Δ | | |---|---|---| | [src/LinearMaps.jl](https://app.codecov.io/gh/JuliaLinearAlgebra/LinearMaps.jl/pull/210?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaLinearAlgebra#diff-c3JjL0xpbmVhck1hcHMuamw=) | `100.00% <ø> (ø)` | | | [src/kronecker.jl](https://app.codecov.io/gh/JuliaLinearAlgebra/LinearMaps.jl/pull/210?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaLinearAlgebra#diff-c3JjL2tyb25lY2tlci5qbA==) | `100.00% <100.00%> (ø)` | | | [src/trace.jl](https://app.codecov.io/gh/JuliaLinearAlgebra/LinearMaps.jl/pull/210?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=JuliaLinearAlgebra#diff-c3JjL3RyYWNlLmps) | `100.00% <100.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

JeffFessler commented 1 year ago

The fallback code for general types might have been simpler if we allowed A[i,i] 🥲

dkarrasch commented 1 year ago

True, but less efficient, because how would you reuse the canonical vector?

dkarrasch commented 1 year ago

I wonder if we should have some kind of iterator for iterating all canonical vectors, though. Let me think about it...

JeffFessler commented 1 year ago

Ah yes, fair point.