sparse_ir_capi/
lib.rs

1//! C API for SparseIR Rust implementation
2//!
3//! This crate provides a C-compatible interface to the SparseIR library,
4//! enabling usage from languages like Julia, Python, Fortran, and C++.
5
6// C API requires unsafe operations with raw pointers
7#![allow(clippy::not_unsafe_ptr_arg_deref)]
8
9#[macro_use]
10mod macros;
11
12mod basis;
13mod dlr;
14mod funcs;
15mod gemm;
16mod kernel;
17mod sampling;
18mod sve;
19mod types;
20mod utils;
21
22pub use basis::*;
23pub use dlr::*;
24pub use funcs::*;
25pub use gemm::*;
26pub use kernel::*;
27pub use sampling::*;
28pub use sve::*;
29pub use types::*;
30pub use utils::*;
31
32/// Complex number type for C API (compatible with C's double complex)
33///
34/// This type is compatible with C99's `double complex` and C++'s `std::complex<double>`.
35/// Layout: `{double re; double im;}` with standard alignment.
36#[repr(C)]
37#[derive(Debug, Clone, Copy)]
38pub struct Complex64 {
39    pub re: f64,
40    pub im: f64,
41}
42
43/// Error codes for C API (compatible with libsparseir)
44pub type StatusCode = libc::c_int;
45
46// Status codes matching libsparseir
47pub const SPIR_COMPUTATION_SUCCESS: StatusCode = 0;
48pub const SPIR_GET_IMPL_FAILED: StatusCode = -1;
49pub const SPIR_INVALID_DIMENSION: StatusCode = -2;
50pub const SPIR_INPUT_DIMENSION_MISMATCH: StatusCode = -3;
51pub const SPIR_OUTPUT_DIMENSION_MISMATCH: StatusCode = -4;
52pub const SPIR_NOT_SUPPORTED: StatusCode = -5;
53pub const SPIR_INVALID_ARGUMENT: StatusCode = -6;
54pub const SPIR_INTERNAL_ERROR: StatusCode = -7;
55
56// Order type constants (matching libsparseir)
57pub const SPIR_ORDER_ROW_MAJOR: libc::c_int = 0;
58pub const SPIR_ORDER_COLUMN_MAJOR: libc::c_int = 1;
59
60// Statistics type constants (matching libsparseir)
61pub const SPIR_STATISTICS_BOSONIC: libc::c_int = 0;
62pub const SPIR_STATISTICS_FERMIONIC: libc::c_int = 1;
63
64// Twork type constants (matching libsparseir)
65pub const SPIR_TWORK_FLOAT64: libc::c_int = 0;
66pub const SPIR_TWORK_FLOAT64X2: libc::c_int = 1;
67pub const SPIR_TWORK_AUTO: libc::c_int = -1;
68
69// SVD strategy constants (matching libsparseir)
70// Note: Currently not used in Rust implementation, but included for API compatibility
71pub const SPIR_SVDSTRAT_FAST: libc::c_int = 0;
72pub const SPIR_SVDSTRAT_ACCURATE: libc::c_int = 1;
73pub const SPIR_SVDSTRAT_AUTO: libc::c_int = -1;