Module structured_matrix

Module structured_matrix 

Source
Expand description

Structured coefficient matrix operations for interpolation algorithms

This module provides optimized implementations for common matrix operations that arise in interpolation, particularly B-spline fitting and scattered data interpolation. The key optimizations leverage structure in the matrices:

  • Band matrix operations: B-spline coefficient matrices are often banded
  • Sparse matrix operations: For large scattered data problems
  • Block-structured operations: Tensor product splines have block structure
  • Vectorized operations: SIMD-optimized matrix-vector products
  • Cache-optimized algorithms: Memory access patterns optimized for modern CPUs

§Performance Benefits

  • Band matrix solvers: O(n) storage and O(n*b²) operations vs O(n³) for general matrices
  • Sparse operations: Only store and operate on non-zero elements
  • Block operations: Leverage BLAS Level 3 operations for better cache efficiency
  • Vectorized operations: Use SIMD instructions for element-wise operations

§Examples

use scirs2_core::ndarray::{Array1, Array2};
use scirs2_interpolate::structured_matrix::{BandMatrix, solve_band_system};

// Create a tridiagonal matrix for cubic spline interpolation
let n = 100;
let mut band_matrix = BandMatrix::new(n, 1, 1); // 1 super, 1 sub diagonal

// Fill the tridiagonal matrix
for i in 0..n {
    band_matrix.set_diagonal(i, 2.0);
    if i > 0 {
        band_matrix.set_subdiagonal(i, 1.0);
    }
    if i < n-1 {
        band_matrix.set_superdiagonal(i, 1.0);
    }
}

// Solve the system efficiently
let rhs = Array1::linspace(0.0, 1.0, n);
let solution = solve_band_system(&band_matrix, &rhs.view()).unwrap();

Structs§

BandMatrix
A band matrix optimized for storage and operations
CSRMatrix
Sparse matrix in Compressed Sparse Row (CSR) format

Functions§

create_bspline_band_matrix
Create a band matrix for B-spline interpolation
solve_band_system
Solve a band linear system using optimized LU factorization
solve_sparse_system
Solve a sparse linear system using iterative methods
solve_structured_least_squares
Optimized least squares solver for structured matrices
vectorized_matvec
Vectorized matrix-vector product (scalar fallback)