Skip to main content

scirs2_python/
lib.rs

1//! SciRS2 Python Bindings
2//!
3//! This crate provides Python bindings for the SciRS2 scientific computing library,
4//! offering a high-performance SciPy alternative with a familiar Python API.
5//!
6//! # Modules
7//!
8//! - `cluster`: Clustering algorithms (K-Means, DBSCAN, Hierarchical, etc.)
9//! - `series`: Time series analysis and ARIMA models
10//! - `linalg`: Linear algebra operations
11//! - `stats`: Statistical distributions and tests
12//! - `fft`: Fast Fourier Transforms
13//! - `optimize`: Optimization algorithms
14//! - `special`: Special mathematical functions
15//! - `integrate`: Numerical integration
16//! - `interpolate`: Interpolation functions
17//! - `signal`: Signal processing
18//! - `spatial`: Spatial algorithms
19//! - `sparse`: Sparse matrix operations
20//! - `ndimage`: N-dimensional image processing
21//! - `graph`: Graph algorithms
22//! - `metrics`: ML evaluation metrics
23//! - `io`: File I/O operations
24//! - `datasets`: Dataset loading and generation
25//! - `transform`: Data transformation and preprocessing
26//! - `text`: Text processing and NLP
27//! - `vision`: Computer vision algorithms
28//! - `autograd`: Automatic differentiation (placeholder)
29//! - `neural`: Neural network layers (placeholder)
30//!
31//! # Architecture
32//!
33//! This crate uses:
34//! - **scirs2-numpy** - SciRS2 fork of rust-numpy with native ndarray 0.17 support
35//! - **PyO3** for Python-Rust interop
36//! - **NumPy** for seamless array compatibility
37//!
38//! Using scirs2-numpy provides direct ndarray 0.17 compatibility with all
39//! internal SciRS2 crates, eliminating version mismatches and enabling
40//! zero-copy operations where possible.
41
42use pyo3::prelude::*;
43
44// Core modules (always available)
45pub mod async_ops;
46pub mod dlpack;
47pub mod error;
48pub mod gpu_ops;
49pub mod pandas_compat;
50pub mod parallel;
51
52// Submodules
53#[cfg(feature = "cluster")]
54pub mod cluster;
55
56#[cfg(feature = "series")]
57pub mod series;
58
59#[cfg(feature = "linalg")]
60pub mod linalg;
61
62#[cfg(feature = "stats")]
63pub mod stats;
64
65#[cfg(feature = "fft")]
66pub mod fft;
67
68#[cfg(feature = "optimize")]
69pub mod optimize;
70
71#[cfg(feature = "special")]
72pub mod special;
73
74#[cfg(feature = "integrate")]
75pub mod integrate;
76
77#[cfg(feature = "interpolate")]
78pub mod interpolate;
79
80#[cfg(feature = "signal")]
81pub mod signal;
82
83#[cfg(feature = "spatial")]
84pub mod spatial;
85
86#[cfg(feature = "sparse")]
87pub mod sparse;
88
89#[cfg(feature = "ndimage")]
90pub mod ndimage;
91
92#[cfg(feature = "graph")]
93#[allow(unused_must_use)] // For graph.add_edge() Result
94pub mod graph;
95
96#[cfg(feature = "metrics")]
97pub mod metrics;
98
99#[cfg(feature = "io")]
100pub mod io;
101
102#[cfg(feature = "datasets")]
103pub mod datasets;
104
105#[cfg(feature = "transform")]
106pub mod transform;
107
108#[cfg(feature = "text")]
109pub mod text;
110
111#[cfg(feature = "vision")]
112pub mod vision;
113
114#[cfg(feature = "autograd")]
115pub mod autograd;
116
117#[cfg(feature = "neural")]
118pub mod neural;
119
120// Symbolic mathematics — always available (additive, no feature gate).
121pub mod symbolic;
122
123/// SciRS2 Python module
124///
125/// A comprehensive scientific computing library in Rust with Python bindings.
126/// Provides SciPy-compatible APIs with Rust-level performance.
127#[pymodule]
128fn scirs2(m: &Bound<'_, PyModule>) -> PyResult<()> {
129    // Package metadata
130    m.add("__version__", env!("CARGO_PKG_VERSION"))?;
131    m.add(
132        "__author__",
133        "COOLJAPAN OU (Team KitaSan) <contact@cooljapan.tech>",
134    )?;
135
136    // Register core modules (async, pandas support, DLPack interop, parallel batch, GPU ops)
137    async_ops::register_async_module(m)?;
138    pandas_compat::register_pandas_module(m)?;
139    dlpack::register_dlpack_module(m)?;
140    parallel::register_parallel_module(m)?;
141    gpu_ops::register_gpu_module(m)?;
142
143    // Register classes and functions directly in main module
144    #[cfg(feature = "cluster")]
145    cluster::register_module(m)?;
146
147    #[cfg(feature = "series")]
148    series::register_module(m)?;
149
150    #[cfg(feature = "linalg")]
151    linalg::register_module(m)?;
152
153    #[cfg(feature = "stats")]
154    stats::register_module(m)?;
155
156    #[cfg(feature = "fft")]
157    fft::register_module(m)?;
158
159    #[cfg(feature = "optimize")]
160    optimize::register_module(m)?;
161
162    #[cfg(feature = "special")]
163    special::register_module(m)?;
164
165    #[cfg(feature = "integrate")]
166    integrate::register_module(m)?;
167
168    #[cfg(feature = "interpolate")]
169    interpolate::register_module(m)?;
170
171    #[cfg(feature = "signal")]
172    signal::register_module(m)?;
173
174    #[cfg(feature = "spatial")]
175    spatial::register_module(m)?;
176
177    #[cfg(feature = "sparse")]
178    sparse::register_module(m)?;
179
180    #[cfg(feature = "ndimage")]
181    ndimage::register_module(m)?;
182
183    #[cfg(feature = "graph")]
184    graph::register_module(m)?;
185
186    #[cfg(feature = "metrics")]
187    metrics::register_module(m)?;
188
189    #[cfg(feature = "io")]
190    io::register_module(m)?;
191
192    #[cfg(feature = "datasets")]
193    datasets::register_module(m)?;
194
195    #[cfg(feature = "transform")]
196    transform::register_module(m)?;
197
198    #[cfg(feature = "text")]
199    text::register_module(m)?;
200
201    #[cfg(feature = "vision")]
202    vision::register_module(m)?;
203
204    #[cfg(feature = "autograd")]
205    autograd::register_module(m)?;
206
207    #[cfg(feature = "neural")]
208    neural::register_module(m)?;
209
210    // Symbolic mathematics sub-namespace (always registered).
211    symbolic::register_module(m)?;
212
213    Ok(())
214}