Comments (6)
I was using the following snippet:
using BandedMatrices, SparseArrays, LinearAlgebra, BenchmarkTools
n = 10000
h = 1/n
A = BandedMatrix{Float64}(undef, (n,n), (1,1))
A[band(0)] .= -2/h^2
A[band(1)] .= A[band(-1)] .= 1/h^2
B = sparse(A)
C = SymTridiagonal(A)
f = fill(1.0,n)
Then
julia> @btime $A\$f;
643.493 μs (7 allocations: 469.03 KiB)
julia> @btime $B\$f;
2.662 ms (64 allocations: 5.42 MiB)
julia> @btime $C\$f;
173.811 μs (8 allocations: 234.66 KiB)
(I'm on Linux and have weened myself off MKL since they changed their free license to prohibit academic work -- not sure if bundling with JuliaPro changes that. But good to know! In any case, things become more interesting with 2D operators using kron
and with BlockBandedMatrices
for optimality systems for PDE-constrained optimization. Also, unlike BandedMatrix
, SymTridiagonalMatrix
has no lu
(or rather, cholesky
) method -- but then, neither does SymBandedMatrix
, although it should, or isn't it exported?)
from bandedmatrices.jl.
Sorry, I’ll fix that now. The easiest is
A = BandedMatrix{Float64}(undef, (n,n), (1,1))
A[band(0)] .= -2/h^2
A[band(1)] .= A[band(-1)] .= 1/h^2
See also
https://github.com/JuliaMatrices/BandedMatrices.jl/blob/master/examples/clarrays.jl
from bandedmatrices.jl.
Ooh, that's clever -- thanks! (I didn't think to look into that example since it seemed too advanced. Maybe your snippet could be added to the documentation, since the discrete gradient or Laplacian are poster children for banded matrices and using a BandedMatrix
rather than a SparseArray
for the latter gives about a speedup factor of 4?)
from bandedmatrices.jl.
Yes I should add a finite difference example. If you make one I’d be happy to accept a PR.
Note that OpenBLAS (Julia’s default) is pretty slow for banded matrices. If you use MKL (JuliaPro) or Apples BLAS it’s much faster.
from bandedmatrices.jl.
Note you can also use SymTridiagonal
in Base.
from bandedmatrices.jl.
The README constructor now works.
from bandedmatrices.jl.
Related Issues (20)
- BandedMatrix with upper/subdiagonals far away from the main diagonal HOT 1
- Question : Finding the bandwidth of a matrix HOT 7
- versioned document is not deployed HOT 1
- Feature request: convenience functions to construct types equivalent to those from LinearAlgebra HOT 1
- In-place assignment on subviews of bands HOT 1
- Products and inverses of symmetric banded matrices HOT 2
- LU decomposition HOT 4
- Docs 404 HOT 1
- Matrix-vector product with a transposed/adjoint `BandedMatrix` is slow
- Stable docs not building HOT 8
- `Adjoint`/`Transpose` don't define `bandeddata` HOT 4
- Tag v1.0
- Why is `BandedMatrix` mutable? HOT 4
- Matrix-Matrix product is slow with diagonal banded matrices HOT 4
- Is the type parameter `<:` intentional? HOT 1
- getindex for BandedEigenvalues is extremely slow HOT 2
- setindex with ranges is broken
- `isbanded` should not be exported
- lu(A) is not banded HOT 6
- When to use BandedMatrices over static arrays? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bandedmatrices.jl.