Skip to main content

scirs2/
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(deprecated)] // For PyAnyMethods::downcast - will be updated in future pyo3 version
94#[allow(unused_must_use)] // For graph.add_edge() Result
95pub mod graph;
96
97#[cfg(feature = "metrics")]
98pub mod metrics;
99
100#[cfg(feature = "io")]
101pub mod io;
102
103#[cfg(feature = "datasets")]
104pub mod datasets;
105
106#[cfg(feature = "transform")]
107pub mod transform;
108
109#[cfg(feature = "text")]
110pub mod text;
111
112#[cfg(feature = "vision")]
113pub mod vision;
114
115#[cfg(feature = "autograd")]
116pub mod autograd;
117
118#[cfg(feature = "neural")]
119pub mod neural;
120
121// Symbolic mathematics — always available (additive, no feature gate).
122pub mod symbolic;
123
124/// SciRS2 Python module
125///
126/// A comprehensive scientific computing library in Rust with Python bindings.
127/// Provides SciPy-compatible APIs with Rust-level performance.
128#[pymodule]
129fn scirs2(m: &Bound<'_, PyModule>) -> PyResult<()> {
130    // Package metadata
131    m.add("__version__", env!("CARGO_PKG_VERSION"))?;
132    m.add(
133        "__author__",
134        "COOLJAPAN OU (Team KitaSan) <contact@cooljapan.tech>",
135    )?;
136
137    // Register core modules (async, pandas support, DLPack interop, parallel batch, GPU ops)
138    async_ops::register_async_module(m)?;
139    pandas_compat::register_pandas_module(m)?;
140    dlpack::register_dlpack_module(m)?;
141    parallel::register_parallel_module(m)?;
142    gpu_ops::register_gpu_module(m)?;
143
144    // Register classes and functions directly in main module
145    #[cfg(feature = "cluster")]
146    cluster::register_module(m)?;
147
148    #[cfg(feature = "series")]
149    series::register_module(m)?;
150
151    #[cfg(feature = "linalg")]
152    linalg::register_module(m)?;
153
154    #[cfg(feature = "stats")]
155    stats::register_module(m)?;
156
157    #[cfg(feature = "fft")]
158    fft::register_module(m)?;
159
160    #[cfg(feature = "optimize")]
161    optimize::register_module(m)?;
162
163    #[cfg(feature = "special")]
164    special::register_module(m)?;
165
166    #[cfg(feature = "integrate")]
167    integrate::register_module(m)?;
168
169    #[cfg(feature = "interpolate")]
170    interpolate::register_module(m)?;
171
172    #[cfg(feature = "signal")]
173    signal::register_module(m)?;
174
175    #[cfg(feature = "spatial")]
176    spatial::register_module(m)?;
177
178    #[cfg(feature = "sparse")]
179    sparse::register_module(m)?;
180
181    #[cfg(feature = "ndimage")]
182    ndimage::register_module(m)?;
183
184    #[cfg(feature = "graph")]
185    graph::register_module(m)?;
186
187    #[cfg(feature = "metrics")]
188    metrics::register_module(m)?;
189
190    #[cfg(feature = "io")]
191    io::register_module(m)?;
192
193    #[cfg(feature = "datasets")]
194    datasets::register_module(m)?;
195
196    #[cfg(feature = "transform")]
197    transform::register_module(m)?;
198
199    #[cfg(feature = "text")]
200    text::register_module(m)?;
201
202    #[cfg(feature = "vision")]
203    vision::register_module(m)?;
204
205    #[cfg(feature = "autograd")]
206    autograd::register_module(m)?;
207
208    #[cfg(feature = "neural")]
209    neural::register_module(m)?;
210
211    // Symbolic mathematics sub-namespace (always registered).
212    symbolic::register_module(m)?;
213
214    Ok(())
215}