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 error;
47pub mod pandas_compat;
48
49// Submodules
50#[cfg(feature = "cluster")]
51pub mod cluster;
52
53#[cfg(feature = "series")]
54pub mod series;
55
56#[cfg(feature = "linalg")]
57pub mod linalg;
58
59#[cfg(feature = "stats")]
60pub mod stats;
61
62#[cfg(feature = "fft")]
63pub mod fft;
64
65#[cfg(feature = "optimize")]
66pub mod optimize;
67
68#[cfg(feature = "special")]
69pub mod special;
70
71#[cfg(feature = "integrate")]
72pub mod integrate;
73
74#[cfg(feature = "interpolate")]
75pub mod interpolate;
76
77#[cfg(feature = "signal")]
78pub mod signal;
79
80#[cfg(feature = "spatial")]
81pub mod spatial;
82
83#[cfg(feature = "sparse")]
84pub mod sparse;
85
86#[cfg(feature = "ndimage")]
87pub mod ndimage;
88
89#[cfg(feature = "graph")]
90#[allow(deprecated)] // For PyAnyMethods::downcast - will be updated in future pyo3 version
91#[allow(unused_must_use)] // For graph.add_edge() Result
92pub mod graph;
93
94#[cfg(feature = "metrics")]
95pub mod metrics;
96
97#[cfg(feature = "io")]
98pub mod io;
99
100#[cfg(feature = "datasets")]
101pub mod datasets;
102
103#[cfg(feature = "transform")]
104pub mod transform;
105
106#[cfg(feature = "text")]
107pub mod text;
108
109#[cfg(feature = "vision")]
110pub mod vision;
111
112#[cfg(feature = "autograd")]
113pub mod autograd;
114
115#[cfg(feature = "neural")]
116pub mod neural;
117
118/// SciRS2 Python module
119///
120/// A comprehensive scientific computing library in Rust with Python bindings.
121/// Provides SciPy-compatible APIs with Rust-level performance.
122#[pymodule]
123fn scirs2(m: &Bound<'_, PyModule>) -> PyResult<()> {
124    // Package metadata
125    m.add("__version__", env!("CARGO_PKG_VERSION"))?;
126    m.add(
127        "__author__",
128        "COOLJAPAN OU (Team KitaSan) <contact@cooljapan.tech>",
129    )?;
130
131    // Register core modules (async and pandas support)
132    async_ops::register_async_module(m)?;
133    pandas_compat::register_pandas_module(m)?;
134
135    // Register classes and functions directly in main module
136    #[cfg(feature = "cluster")]
137    cluster::register_module(m)?;
138
139    #[cfg(feature = "series")]
140    series::register_module(m)?;
141
142    #[cfg(feature = "linalg")]
143    linalg::register_module(m)?;
144
145    #[cfg(feature = "stats")]
146    stats::register_module(m)?;
147
148    #[cfg(feature = "fft")]
149    fft::register_module(m)?;
150
151    #[cfg(feature = "optimize")]
152    optimize::register_module(m)?;
153
154    #[cfg(feature = "special")]
155    special::register_module(m)?;
156
157    #[cfg(feature = "integrate")]
158    integrate::register_module(m)?;
159
160    #[cfg(feature = "interpolate")]
161    interpolate::register_module(m)?;
162
163    #[cfg(feature = "signal")]
164    signal::register_module(m)?;
165
166    #[cfg(feature = "spatial")]
167    spatial::register_module(m)?;
168
169    #[cfg(feature = "sparse")]
170    sparse::register_module(m)?;
171
172    #[cfg(feature = "ndimage")]
173    ndimage::register_module(m)?;
174
175    #[cfg(feature = "graph")]
176    graph::register_module(m)?;
177
178    #[cfg(feature = "metrics")]
179    metrics::register_module(m)?;
180
181    #[cfg(feature = "io")]
182    io::register_module(m)?;
183
184    #[cfg(feature = "datasets")]
185    datasets::register_module(m)?;
186
187    #[cfg(feature = "transform")]
188    transform::register_module(m)?;
189
190    #[cfg(feature = "text")]
191    text::register_module(m)?;
192
193    #[cfg(feature = "vision")]
194    vision::register_module(m)?;
195
196    #[cfg(feature = "autograd")]
197    autograd::register_module(m)?;
198
199    #[cfg(feature = "neural")]
200    neural::register_module(m)?;
201
202    Ok(())
203}