numerics
Loading...
Searching...
No Matches
num::BandedMatrix Class Reference

Banded matrix with efficient storage for direct solvers. More...

#include <banded.hpp>

Public Member Functions

 BandedMatrix (idx n, idx kl, idx ku)
 Construct a banded matrix.
 
 BandedMatrix (idx n, idx kl, idx ku, real val)
 Construct with initial value.
 
 ~BandedMatrix ()
 
 BandedMatrix (const BandedMatrix &)
 
 BandedMatrix (BandedMatrix &&) noexcept
 
BandedMatrixoperator= (const BandedMatrix &)
 
BandedMatrixoperator= (BandedMatrix &&) noexcept
 
idx size () const
 Matrix dimension.
 
idx rows () const
 
idx cols () const
 
idx kl () const
 Number of lower diagonals.
 
idx ku () const
 Number of upper diagonals.
 
idx bandwidth () const
 Total bandwidth (kl + ku + 1)
 
idx ldab () const
 Leading dimension of band storage (2*kl + ku + 1)
 
realoperator() (idx i, idx j)
 Access element at (row, col) in original matrix coordinates.
 
real operator() (idx i, idx j) const
 
realband (idx band_row, idx col)
 Direct access to band storage.
 
real band (idx band_row, idx col) const
 
realdata ()
 Raw pointer to band storage (column-major)
 
const realdata () const
 
bool in_band (idx i, idx j) const
 Check if (i,j) is within the band.
 
void to_gpu ()
 
void to_cpu ()
 
realgpu_data ()
 
const realgpu_data () const
 
bool on_gpu () const
 

Detailed Description

Banded matrix with efficient storage for direct solvers.

Uses LAPACK-style band storage format optimized for LU factorization. For a matrix with kl lower diagonals and ku upper diagonals, storage layout is:

  • Rows 0 to kl-1: Extra space for fill-in during LU factorization
  • Rows kl to kl+ku: Upper diagonals (ku at top, main diagonal at kl+ku)
  • Rows kl+ku+1 to 2*kl+ku: Lower diagonals

Element A(i,j) is stored at band(kl + ku + i - j, j) for max(0,j-ku) <= i <= min(n-1,j+kl)

This format enables:

  • Column-major access patterns for LU factorization
  • SIMD-friendly memory layout
  • Direct compatibility with LAPACK routines if needed

Definition at line 32 of file banded.hpp.

Constructor & Destructor Documentation

◆ BandedMatrix() [1/4]

num::BandedMatrix::BandedMatrix ( idx  n,
idx  kl,
idx  ku 
)

Construct a banded matrix.

Parameters
nMatrix dimension (n x n)
klNumber of lower diagonals
kuNumber of upper diagonals

Definition at line 20 of file banded.cpp.

◆ BandedMatrix() [2/4]

num::BandedMatrix::BandedMatrix ( idx  n,
idx  kl,
idx  ku,
real  val 
)

Construct with initial value.

Definition at line 26 of file banded.cpp.

References num::ipow().

◆ ~BandedMatrix()

num::BandedMatrix::~BandedMatrix ( )

Definition at line 31 of file banded.cpp.

References num::cuda::free().

◆ BandedMatrix() [3/4]

num::BandedMatrix::BandedMatrix ( const BandedMatrix other)

Definition at line 37 of file banded.cpp.

References num::ipow().

◆ BandedMatrix() [4/4]

num::BandedMatrix::BandedMatrix ( BandedMatrix &&  other)
noexcept

Definition at line 44 of file banded.cpp.

References num::ipow().

Member Function Documentation

◆ band() [1/2]

real & num::BandedMatrix::band ( idx  band_row,
idx  col 
)

Direct access to band storage.

Parameters
band_rowRow in band storage (0 to ldab-1)
colColumn index (0 to n-1)

Definition at line 84 of file banded.cpp.

References num::ipow().

◆ band() [2/2]

real num::BandedMatrix::band ( idx  band_row,
idx  col 
) const

Definition at line 88 of file banded.cpp.

References num::ipow().

◆ bandwidth()

idx num::BandedMatrix::bandwidth ( ) const
inline

Total bandwidth (kl + ku + 1)

Definition at line 63 of file banded.hpp.

◆ cols()

idx num::BandedMatrix::cols ( ) const
inline

Definition at line 54 of file banded.hpp.

◆ data() [1/2]

real * num::BandedMatrix::data ( )
inline

Raw pointer to band storage (column-major)

Definition at line 82 of file banded.hpp.

◆ data() [2/2]

const real * num::BandedMatrix::data ( ) const
inline

Definition at line 83 of file banded.hpp.

◆ gpu_data() [1/2]

real * num::BandedMatrix::gpu_data ( )
inline

Definition at line 91 of file banded.hpp.

◆ gpu_data() [2/2]

const real * num::BandedMatrix::gpu_data ( ) const
inline

Definition at line 92 of file banded.hpp.

◆ in_band()

bool num::BandedMatrix::in_band ( idx  i,
idx  j 
) const

Check if (i,j) is within the band.

Definition at line 92 of file banded.cpp.

References num::ipow().

◆ kl()

idx num::BandedMatrix::kl ( ) const
inline

Number of lower diagonals.

Definition at line 57 of file banded.hpp.

◆ ku()

idx num::BandedMatrix::ku ( ) const
inline

Number of upper diagonals.

Definition at line 60 of file banded.hpp.

◆ ldab()

idx num::BandedMatrix::ldab ( ) const
inline

Leading dimension of band storage (2*kl + ku + 1)

Definition at line 66 of file banded.hpp.

◆ on_gpu()

bool num::BandedMatrix::on_gpu ( ) const
inline

Definition at line 93 of file banded.hpp.

◆ operator()() [1/2]

real & num::BandedMatrix::operator() ( idx  i,
idx  j 
)

Access element at (row, col) in original matrix coordinates.

Parameters
iRow index (0-based)
jColumn index (0-based)
Returns
Reference to element (undefined if outside band)

Definition at line 76 of file banded.cpp.

References num::ipow().

◆ operator()() [2/2]

real num::BandedMatrix::operator() ( idx  i,
idx  j 
) const

Definition at line 80 of file banded.cpp.

References num::ipow().

◆ operator=() [1/2]

BandedMatrix & num::BandedMatrix::operator= ( BandedMatrix &&  other)
noexcept

Definition at line 63 of file banded.cpp.

References num::cuda::free(), and num::ipow().

◆ operator=() [2/2]

BandedMatrix & num::BandedMatrix::operator= ( const BandedMatrix other)

Definition at line 51 of file banded.cpp.

References num::cuda::free(), and num::ipow().

◆ rows()

idx num::BandedMatrix::rows ( ) const
inline

Definition at line 53 of file banded.hpp.

◆ size()

idx num::BandedMatrix::size ( ) const
inline

Matrix dimension.

Definition at line 52 of file banded.hpp.

◆ to_cpu()

void num::BandedMatrix::to_cpu ( )

Definition at line 103 of file banded.cpp.

References num::cuda::to_host().

◆ to_gpu()

void num::BandedMatrix::to_gpu ( )

Definition at line 96 of file banded.cpp.

References num::cuda::alloc(), and num::cuda::to_device().


The documentation for this class was generated from the following files: