Code Monkey home page Code Monkey logo

blockdiagonals.jl's Introduction

BlockDiagonals.jl

Stable Dev CI Codecov code style blue

Functionality for working efficiently with block diagonal matrices. Note that non-square blocks are allowed, similarly to scipy.block_diag, but in contrast to the mathematical definition above.

Construct a BlockDiagonal matrix by passing in only the non-zero blocks on the diagonal, and use it as a regular matrix

julia> using BlockDiagonals

julia> bm = BlockDiagonal([rand(2, 3), ones(3, 2)])
5×5 BlockDiagonal{Float64, Matrix{Float64}}:
 0.289276  0.994487  0.287658  0.0  0.0
 0.659821  0.334724  0.780973  0.0  0.0
 0.0       0.0       0.0       1.0  1.0
 0.0       0.0       0.0       1.0  1.0
 0.0       0.0       0.0       1.0  1.0

julia> v = ones(5);

julia> bm * v
5-element Vector{Float64}:
 1.5714204086879524
 1.7755185907265039
 2.0
 2.0
 2.0

julia> svd(bm)
SVD{Float64, Float64, Matrix{Float64}}
U factor:
5×4 Matrix{Float64}:
  0.0      -0.70666   -0.707553   0.0
  0.0      -0.707553   0.70666    0.0
 -0.57735   0.0        0.0       -0.57735
 -0.57735   0.0        0.0        0.788675
 -0.57735   0.0        0.0       -0.211325
singular values:
4-element Vector{Float64}:
 2.4494897427831783
 1.3801377610748038
 0.6387290946600256
 0.0
Vt factor:
4×5 Matrix{Float64}:
  0.0        0.0        0.0       -0.707107  -0.707107
 -0.486385  -0.680801  -0.547667   0.0        0.0
  0.409549  -0.731322   0.545379   0.0        0.0
  0.0        0.0        0.0       -0.707107   0.707107

Additional functionality includes

julia> nblocks(bm)
2

julia> blocks(bm)
2-element Vector{Matrix{Float64}}:
 [0.2892758623451861 0.9944869494674535 0.2876575968753128; 0.6598212430288488 0.33472423873340906 0.780973108964246]
 [1.0 1.0; 1.0 1.0; 1.0 1.0]

julia> blocksizes(bm)
2-element Vector{Tuple{Int64, Int64}}:
 (2, 3)
 (3, 2)

julia> blocksize(bm, 1)
(2, 3)

blockdiagonals.jl's People

Contributors

nickrobinson251 avatar mzgubic avatar oxinabox avatar willtebbutt avatar mjp98 avatar abraemer avatar fchorney avatar theogf avatar thomasgudjonwright avatar rofinn avatar nanleij avatar eperim avatar github-actions[bot] avatar mjram0s avatar aminya avatar ararslan avatar dkarrasch avatar juliatagbot avatar mcognetta avatar matbesancon avatar matteoacrossi avatar platawiec avatar

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.