Skip to main content

sparse_ir/
lib.rs

1//! # sparse-ir: Rust implementation of SparseIR functionality
2//!
3//! A high-performance implementation of the SparseIR (Sparse Intermediate Representation)
4//! library in Rust, providing analytical continuation and sparse representation
5//! functionality for quantum many-body physics calculations.
6
7/// Print a warning to stderr only when the `SPARSEIR_DEBUG` environment
8/// variable is set.
9///
10/// Library code must not write to stderr unconditionally; these are advisory
11/// diagnostics (e.g. ill-conditioned sampling) for debugging, not error reports.
12#[macro_export]
13macro_rules! debug_warn {
14    ($($arg:tt)*) => {
15        if std::env::var("SPARSEIR_DEBUG").is_ok() {
16            eprintln!("[SPARSEIR WARN] {}", format!($($arg)*));
17        }
18    };
19}
20
21pub mod basis;
22pub mod basis_trait; // Common trait for basis representations
23pub mod col_piv_qr; // Column-pivoted QR decomposition using nalgebra
24pub mod dlr; // Discrete Lehmann Representation utilities
25pub mod fitters; // Least-squares fitters (real/complex matrices)
26pub mod fpu_check; // FPU state checking for Intel Fortran compatibility
27pub mod freq;
28pub mod gauss;
29pub mod gemm; // Matrix multiplication utilities (Faer backend)
30pub mod interpolation1d;
31pub mod interpolation2d;
32pub mod kernel;
33pub mod kernelmatrix;
34pub mod matsubara_sampling; // Sparse sampling in Matsubara frequencies
35pub mod numeric;
36pub mod poly;
37pub mod polyfourier;
38pub mod sampling; // Sparse sampling in imaginary time
39pub mod special_functions;
40pub mod sve;
41pub mod taufuncs;
42pub mod traits;
43pub mod tsvd; // High-precision truncated SVD using nalgebra // Imaginary time τ normalization utilities
44pub mod working_buffer; // Reusable working buffer for in-place operations
45
46// Re-export commonly used types and traits
47pub use basis::{BosonicBasis, FermionicBasis, FiniteTempBasis};
48pub use basis_trait::Basis;
49pub use dlr::{
50    DiscreteLehmannRepresentation, DlrError, bosonic_single_pole, fermionic_single_pole,
51    giwn_single_pole, gtau_single_pole,
52};
53pub use fitters::InplaceFitter;
54pub use freq::{BosonicFreq, FermionicFreq, MatsubaraFreq};
55pub use gauss::{Rule, legendre, legendre_custom, legendre_twofloat};
56pub use interpolation1d::Interpolate1D;
57pub use interpolation2d::Interpolate2D;
58pub use kernel::{
59    AbstractKernel, CentrosymmKernel, KernelProperties, LogisticKernel, LogisticSVEHints,
60    RegularizedBoseKernel, RegularizedBoseSVEHints, SVEHints, SymmetryType,
61    compute_logistic_kernel,
62};
63pub use kernelmatrix::{
64    DiscretizedKernel, InterpolatedKernel, matrix_from_gauss, matrix_from_gauss_noncentrosymmetric,
65    matrix_from_gauss_with_segments,
66};
67pub use matsubara_sampling::{MatsubaraSampling, MatsubaraSamplingPositiveOnly};
68pub use numeric::CustomNumeric;
69pub use poly::{PiecewiseLegendrePoly, PiecewiseLegendrePolyVector};
70pub use polyfourier::{
71    BosonicPiecewiseLegendreFT, BosonicPiecewiseLegendreFTVector, FermionicPiecewiseLegendreFT,
72    FermionicPiecewiseLegendreFTVector, PiecewiseLegendreFT, PiecewiseLegendreFTVector, PowerModel,
73};
74pub use sampling::TauSampling;
75pub use sve::{
76    CentrosymmSVE, SVDStrategy, SVEResult, SVEStrategy, SamplingSVE, TworkType, compute_sve,
77    truncate,
78};
79pub use traits::{Bosonic, Fermionic, Statistics, StatisticsMarker, StatisticsType};
80pub use tsvd::{
81    SVDResult, TSVDConfig, TSVDError, svd_decompose, tsvd, tsvd_df64, tsvd_df64_from_f64, tsvd_f64,
82};
83
84// Re-export external dependencies for convenience
85pub use mdarray::{DTensor, DynRank, Tensor};
86pub use xprec::Df64;
87
88// Test utilities (only available in test mode)
89#[cfg(test)]
90pub mod test_utils;