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/// SciRS2 Python module
122///
123/// A comprehensive scientific computing library in Rust with Python bindings.
124/// Provides SciPy-compatible APIs with Rust-level performance.
125#[pymodule]
126fn scirs2(m: &Bound<'_, PyModule>) -> PyResult<()> {
127    // Package metadata
128    m.add("__version__", env!("CARGO_PKG_VERSION"))?;
129    m.add(
130        "__author__",
131        "COOLJAPAN OU (Team KitaSan) <contact@cooljapan.tech>",
132    )?;
133
134    // Register core modules (async, pandas support, DLPack interop, parallel batch, GPU ops)
135    async_ops::register_async_module(m)?;
136    pandas_compat::register_pandas_module(m)?;
137    dlpack::register_dlpack_module(m)?;
138    parallel::register_parallel_module(m)?;
139    gpu_ops::register_gpu_module(m)?;
140
141    // Register classes and functions directly in main module
142    #[cfg(feature = "cluster")]
143    cluster::register_module(m)?;
144
145    #[cfg(feature = "series")]
146    series::register_module(m)?;
147
148    #[cfg(feature = "linalg")]
149    linalg::register_module(m)?;
150
151    #[cfg(feature = "stats")]
152    stats::register_module(m)?;
153
154    #[cfg(feature = "fft")]
155    fft::register_module(m)?;
156
157    #[cfg(feature = "optimize")]
158    optimize::register_module(m)?;
159
160    #[cfg(feature = "special")]
161    special::register_module(m)?;
162
163    #[cfg(feature = "integrate")]
164    integrate::register_module(m)?;
165
166    #[cfg(feature = "interpolate")]
167    interpolate::register_module(m)?;
168
169    #[cfg(feature = "signal")]
170    signal::register_module(m)?;
171
172    #[cfg(feature = "spatial")]
173    spatial::register_module(m)?;
174
175    #[cfg(feature = "sparse")]
176    sparse::register_module(m)?;
177
178    #[cfg(feature = "ndimage")]
179    ndimage::register_module(m)?;
180
181    #[cfg(feature = "graph")]
182    graph::register_module(m)?;
183
184    #[cfg(feature = "metrics")]
185    metrics::register_module(m)?;
186
187    #[cfg(feature = "io")]
188    io::register_module(m)?;
189
190    #[cfg(feature = "datasets")]
191    datasets::register_module(m)?;
192
193    #[cfg(feature = "transform")]
194    transform::register_module(m)?;
195
196    #[cfg(feature = "text")]
197    text::register_module(m)?;
198
199    #[cfg(feature = "vision")]
200    vision::register_module(m)?;
201
202    #[cfg(feature = "autograd")]
203    autograd::register_module(m)?;
204
205    #[cfg(feature = "neural")]
206    neural::register_module(m)?;
207
208    Ok(())
209}