Giter Club home page Giter Club logo

Comments (6)

clason avatar clason commented on June 28, 2024 1

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.

dlfivefifty avatar dlfivefifty commented on June 28, 2024

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.

clason avatar clason commented on June 28, 2024

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.

dlfivefifty avatar dlfivefifty commented on June 28, 2024

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.

dlfivefifty avatar dlfivefifty commented on June 28, 2024

Note you can also use SymTridiagonal in Base.

from bandedmatrices.jl.

dlfivefifty avatar dlfivefifty commented on June 28, 2024

The README constructor now works.

from bandedmatrices.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.