1#![cfg_attr(not(feature = "std"), no_std)]
61#![warn(missing_docs, clippy::all)]
62#![allow(clippy::float_cmp)] extern crate alloc;
66
67#[cfg(feature = "std")]
68extern crate std;
69
70pub use error::{SolverError, Result};
72pub use matrix::{Matrix, SparseMatrix, SparseFormat};
73pub use solver::{
74 SolverAlgorithm, SolverOptions, SolverResult, PartialSolution,
75 NeumannSolver, ForwardPushSolver, BackwardPushSolver, HybridSolver
76};
77pub use types::{
78 NodeId, EdgeId, Precision, ConvergenceMode, NormType,
79 ErrorBounds, SolverStats
80};
81
82#[cfg(any(feature = "simd", feature = "std"))]
84pub use simd_ops::{matrix_vector_multiply_simd, dot_product_simd, axpy_simd};
85
86#[cfg(feature = "std")]
87pub use simd_ops::parallel_matrix_vector_multiply;
88
89pub use optimized_solver::{OptimizedConjugateGradientSolver, OptimizedSparseMatrix};
91
92pub use math_wasm::{Matrix as WasmMatrix, Vector as WasmVector};
94pub use solver_core::{ConjugateGradientSolver, SolverConfig as WasmSolverConfig};
95
96#[cfg(feature = "wasm")]
97pub use wasm_iface::{WasmSublinearSolver, MatrixView, SolutionStep};
98
99pub mod error;
101pub mod matrix;
102pub mod solver;
103pub mod types;
104
105#[cfg(feature = "wasm")]
107pub mod wasm_iface;
108
109pub mod math_wasm;
111pub mod solver_core;
112
113#[cfg(any(feature = "simd", feature = "std"))]
115pub mod simd_ops;
116
117pub mod optimized_solver;
119
120#[cfg(feature = "cli")]
121pub mod cli;
122
123mod utils;
125
126pub const VERSION: &str = env!("CARGO_PKG_VERSION");
128pub const DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
129
130#[cfg(feature = "std")]
135pub fn init() {
136 #[cfg(feature = "env_logger")]
137 env_logger::try_init().ok();
138}
139
140#[cfg(feature = "wasm")]
144pub fn init_wasm() {
145 #[cfg(feature = "console_error_panic_hook")]
146 console_error_panic_hook::set_once();
147}
148
149#[cfg(feature = "wasm")]
151pub fn set_panic_hook() {
152 #[cfg(feature = "console_error_panic_hook")]
153 console_error_panic_hook::set_once();
154}
155
156pub fn has_simd_support() -> bool {
158 #[cfg(feature = "simd")]
159 {
160 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
161 {
162 is_x86_feature_detected!("avx2")
163 }
164 #[cfg(target_arch = "aarch64")]
165 {
166 std::arch::is_aarch64_feature_detected!("neon")
167 }
168 #[cfg(not(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")))]
169 {
170 false
171 }
172 }
173 #[cfg(not(feature = "simd"))]
174 {
175 false
176 }
177}
178
179pub fn build_info() -> BuildInfo {
181 BuildInfo {
182 version: VERSION,
183 features: get_enabled_features(),
184 simd_support: has_simd_support(),
185 target_arch: "wasm32",
186 target_os: "unknown",
187 }
188}
189
190#[derive(Debug, Clone, PartialEq)]
192#[derive(serde::Serialize, serde::Deserialize)]
193pub struct BuildInfo {
194 pub version: &'static str,
196 pub features: Vec<&'static str>,
198 pub simd_support: bool,
200 pub target_arch: &'static str,
202 pub target_os: &'static str,
204}
205
206fn get_enabled_features() -> Vec<&'static str> {
207 let mut features = Vec::new();
208
209 #[cfg(feature = "std")]
210 features.push("std");
211
212 #[cfg(feature = "wasm")]
213 features.push("wasm");
214
215 #[cfg(feature = "cli")]
216 features.push("cli");
217
218 #[cfg(feature = "simd")]
219 features.push("simd");
220
221 features
222}
223
224#[cfg(feature = "wasm")]
226pub use wasm_bindgen;
227
228#[cfg(feature = "wasm")]
229pub use js_sys;
230
231#[cfg(feature = "wasm")]
232pub use web_sys;
233
234#[cfg(all(test, feature = "std"))]
235mod tests {
236 use super::*;
237
238 #[test]
239 fn test_build_info() {
240 let info = build_info();
241 assert_eq!(info.version, VERSION);
242 assert!(!info.features.is_empty());
243 }
244
245 #[test]
246 fn test_version_info() {
247 assert!(!VERSION.is_empty());
248 assert!(!DESCRIPTION.is_empty());
249 }
250}