Skip to main content

Structured matrices

Project description

Structured Matrices

CI Coverage Status Latest Docs Code style: black

Structured matrices

Requirements and Installation

See the instructions here. Then simply

pip install backends-matrix

Example

>>> import lab as B

>>> from matrix import Diagonal

>>> d = Diagonal(B.rand(2, 3))  # A batch of diagonal marices

>>> d
<diagonal matrix: batch=(2,), shape=(3, 3), dtype=float64
 diag=[[0.427 0.912 0.622]
       [0.777 0.048 0.808]]>

>>> 2 * d
<diagonal matrix: batch=(2,), shape=(3, 3), dtype=float64
 diag=[[0.854 1.824 1.243]
       [1.553 0.096 1.616]]>
  
>>> 2 * d + 1
<Woodbury matrix: batch=(2,), shape=(3, 3), dtype=float64
 diag=<diagonal matrix: batch=(2,), shape=(3, 3), dtype=float64
       diag=[[0.854 1.824 1.243]
             [1.553 0.096 1.616]]>
 lr=<low-rank matrix: batch=(), shape=(3, 3), dtype=int64, rank=1
     left=[[1]
           [1]
           [1]]
     middle=<diagonal matrix: batch=(), shape=(1, 1), dtype=int64
             diag=[1]>>>

>>> B.inv(2 * d + 1)
<Woodbury matrix: batch=(2,), shape=(3, 3), dtype=float64
 diag=<diagonal matrix: batch=(2,), shape=(3, 3), dtype=float64
       diag=[[ 1.171  0.548  0.804]
             [ 0.644 10.386  0.619]]>
 lr=<low-rank matrix: batch=(2,), shape=(3, 3), dtype=float64, rank=1
     left=<dense matrix: batch=(2,), shape=(3, 1), dtype=float64
           mat=[[[ 1.171]
                 [ 0.548]
                 [ 0.804]]

                [[ 0.644]
                 [10.386]
                 [ 0.619]]]>
     middle=<dense matrix: batch=(2,), shape=(1, 1), dtype=float64
             mat=[[[-0.284]]

                  [[-0.079]]]>
     right=<dense matrix: batch=(2,), shape=(3, 1), dtype=float64
            mat=[[[ 1.171]
                  [ 0.548]
                  [ 0.804]]

                 [[ 0.644]
                  [10.386]
                  [ 0.619]]]>>>

>>> B.inv(B.inv(2 * d + 1))
<Woodbury matrix: batch=(2,), shape=(3, 3), dtype=float64
 diag=<diagonal matrix: batch=(2,), shape=(3, 3), dtype=float64
       diag=[[0.854 1.824 1.243]
             [1.553 0.096 1.616]]>
 lr=<low-rank matrix: batch=(2,), shape=(3, 3), dtype=float64, rank=1
     left=<dense matrix: batch=(2,), shape=(3, 1), dtype=float64
           mat=[[[1.]
                 [1.]
                 [1.]]

                [[1.]
                 [1.]
                 [1.]]]>
     middle=<dense matrix: batch=(2,), shape=(1, 1), dtype=float64
             mat=[[[1.]]

                  [[1.]]]>
     right=<dense matrix: batch=(2,), shape=(3, 1), dtype=float64
            mat=[[[1.]
                  [1.]
                  [1.]]

                 [[1.]
                  [1.]
                  [1.]]]>>>

>>> B.inv(B.inv(2 * d + 1)) - 1
<diagonal matrix: batch=(2,), shape=(3, 3), dtype=float64
 diag=[[0.854 1.824 1.243]
       [1.553 0.096 1.616]]>

Matrix Types

All matrix types are subclasses of AbstractMatrix.

The following base types are provided:

Zero
Dense
Diagonal
Constant
LowerTriangular
UpperTriangular

The following composite types are provided:

LowRank
Woodbury
Kronecker
TiledBlocks

Functions

The following functions are added to LAB. They can be accessed with B.<function> where import lab as B.

shape_broadcast(*elements)
shape_batch(a, *indices)
shape_batch_broadcast(*elements)
shape_matrix(a, *indices)
shape_matrix_broadcast(*elements)

broadcast_batch_to(a, *batch)

dense(a)
fill_diag(a, diag_len)
block(*rows)
block_diag(*blocks)

matmul_diag(a, b, tr_a=False, tr_b=False)

pd_inv(a)
schur(a)
pd_schur(a)
iqf(a, b, c)
iqf_diag(a, b, c)

ratio(a, c)
root(a)

sample(a, num=1)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

backends-matrix-1.2.11.tar.gz (56.6 kB view details)

Uploaded Source

File details

Details for the file backends-matrix-1.2.11.tar.gz.

File metadata

  • Download URL: backends-matrix-1.2.11.tar.gz
  • Upload date:
  • Size: 56.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for backends-matrix-1.2.11.tar.gz
Algorithm Hash digest
SHA256 6c50049340556b7c82fb26296976c2bca9cf94a12d3a6b2d5c1e06bd2fae51d9
MD5 1ee29b072a735a09dda1253020ef4e71
BLAKE2b-256 b85130746a137560e43fc5b0f8f16facbd199602a2ba06351b368364586a952c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page