1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
//! # OptiRS - Advanced ML Optimization Built on SciRS2
//!
//! **Version:** 0.3.1
//! **Release Date:** 2026-03-27 (Stable Release)
//!
//! [](https://crates.io/crates/optirs)
//! [](https://docs.rs/optirs)
//! [](https://github.com/cool-japan/optirs)
//!
//! OptiRS is a comprehensive optimization library for machine learning, built exclusively on
//! the [SciRS2](https://github.com/cool-japan/scirs) scientific computing ecosystem. It provides
//! state-of-the-art optimization algorithms with advanced hardware acceleration.
//!
//! ## Dependencies
//!
//! - `scirs2-core` 0.1.1 - Required foundation
//!
//! ## Sub-Crate Status (v0.1.0)
//!
//! - ✅ `optirs-core` - Production Ready (19 optimizers, SIMD, parallel, metrics)
//! - ✅ `optirs-bench` - Production Ready (comprehensive benchmarking and profiling)
//! - 🚧 `optirs-gpu` - Framework Ready (GPU kernels in development)
//! - 🔬 `optirs-learned` - Research Phase (meta-learning and learned optimizers)
//! - 🔬 `optirs-nas` - Research Phase (neural architecture search)
//! - 📝 `optirs-tpu` - Framework Ready (TPU coordination planning stage)
//!
//! ## Quick Start
//!
//! Add OptiRS to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! optirs-core = "0.3.1"
//! ```
//!
//! Basic usage:
//!
//! ```rust
//! use optirs::prelude::*;
//! use scirs2_core::ndarray::Array1;
//!
//! # fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
//! // Create Adam optimizer
//! let mut optimizer = Adam::new(0.001);
//!
//! // Prepare parameters and gradients
//! let params = Array1::from_vec(vec![1.0, 2.0, 3.0, 4.0]);
//! let gradients = Array1::from_vec(vec![0.1, 0.2, 0.15, 0.08]);
//!
//! // Perform optimization step
//! let updated_params = optimizer.step(¶ms, &gradients)?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Features
//!
//! ### Core Optimizers (`optirs-core`)
//!
//! 16 state-of-the-art optimizers with performance optimizations:
//!
//! - **First-Order**: SGD, Adam, AdamW, RMSprop, Adagrad, LAMB, LARS, Lion, RAdam, SAM
//! - **SIMD-Accelerated**: SimdSGD (2-4x faster for large arrays)
//! - **Sparse**: SparseAdam, GroupedAdam
//! - **Wrapper**: Lookahead
//! - **Second-Order**: L-BFGS, Newton
//!
//! #### Performance Features
//!
//! - **SIMD Acceleration** - 2-4x speedup for large parameter arrays
//! - **Parallel Processing** - 4-8x speedup for multiple parameter groups
//! - **Memory-Efficient** - Gradient accumulation and chunked processing
//! - **GPU Framework** - 10-50x potential speedup with GPU acceleration
//! - **Production Metrics** - Real-time monitoring with minimal overhead
//!
//! ### GPU Acceleration (`optirs-gpu`) [Coming Soon]
//!
//! ```toml
//! [dependencies]
//! optirs-gpu = { version = "0.1.0", features = ["cuda"] }
//! ```
//!
//! - **Multi-Backend**: CUDA, Metal, OpenCL, WebGPU
//! - **Tensor Cores**: Mixed-precision training support
//! - **Memory Management**: Advanced GPU memory pools
//! - **Multi-GPU**: Distributed optimization across GPUs
//!
//! ### TPU Coordination (`optirs-tpu`) [Coming Soon]
//!
//! ```toml
//! [dependencies]
//! optirs-tpu = "0.1.0"
//! ```
//!
//! - **Pod Management**: TPU pod coordination
//! - **XLA Integration**: Compiler optimizations
//! - **Fault Tolerance**: Robust hardware failure handling
//! - **Large-Scale**: Distributed training for massive models
//!
//! ### Learned Optimizers (`optirs-learned`) [Research Phase]
//!
//! - **Transformer-based**: Self-attention optimization
//! - **LSTM**: Recurrent optimizer networks
//! - **Meta-Learning**: Learning to optimize across tasks
//! - **Few-Shot**: Rapid adaptation to new problems
//!
//! ### Neural Architecture Search (`optirs-nas`) [Research Phase]
//!
//! - **Search Strategies**: Bayesian, evolutionary, RL-based
//! - **Multi-Objective**: Balance accuracy, efficiency, resources
//! - **Progressive**: Gradually increasing complexity
//! - **Hardware-Aware**: Optimization for specific targets
//!
//! ## Module Organization
//!
//! OptiRS is organized into feature-gated modules:
//!
//! - [`core`] - Core optimizers and utilities (always available)
//! - `gpu` - GPU acceleration (feature: `gpu`)
//! - `tpu` - TPU coordination (feature: `tpu`)
//! - `learned` - Learned optimizers (feature: `learned`)
//! - `nas` - Neural architecture search (feature: `nas`)
//! - `bench` - Benchmarking tools (feature: `bench`)
//!
//! ## Examples
//!
//! ### SIMD Acceleration
//!
//! ```rust
//! use optirs::prelude::*;
//! use scirs2_core::ndarray::Array1;
//!
//! # fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
//! // Large parameter array (SIMD shines with 10k+ elements)
//! let params = Array1::from_elem(100_000, 1.0f32);
//! let grads = Array1::from_elem(100_000, 0.001f32);
//!
//! let mut optimizer = SimdSGD::new(0.01f32);
//! let updated = optimizer.step(¶ms, &grads)?;
//! # Ok(())
//! # }
//! ```
//!
//! ### Parallel Processing
//!
//! ```rust
//! use optirs::prelude::*;
//! use optirs::core::parallel_optimizer::parallel_step_array1;
//! use scirs2_core::ndarray::Array1;
//!
//! # fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
//! let params_list = vec![
//! Array1::from_elem(10_000, 1.0),
//! Array1::from_elem(20_000, 1.0),
//! ];
//! let grads_list = vec![
//! Array1::from_elem(10_000, 0.01),
//! Array1::from_elem(20_000, 0.01),
//! ];
//!
//! let mut optimizer = Adam::new(0.001);
//! let results = parallel_step_array1(&mut optimizer, ¶ms_list, &grads_list)?;
//! # Ok(())
//! # }
//! ```
//!
//! ### Production Monitoring
//!
//! ```rust
//! use optirs::core::optimizer_metrics::{MetricsCollector, MetricsReporter};
//! use optirs::prelude::*;
//! use scirs2_core::ndarray::Array1;
//! use std::time::Instant;
//!
//! # fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
//! let mut collector = MetricsCollector::new();
//! collector.register_optimizer("adam");
//!
//! let mut optimizer = Adam::new(0.001);
//! let params = Array1::from_elem(1000, 1.0);
//! let grads = Array1::from_elem(1000, 0.01);
//!
//! let params_before = params.clone();
//! let start = Instant::now();
//! let params = optimizer.step(¶ms, &grads)?;
//! let duration = start.elapsed();
//!
//! collector.update(
//! "adam",
//! duration,
//! 0.001,
//! &grads.view(),
//! ¶ms_before.view(),
//! ¶ms.view(),
//! )?;
//!
//! println!("{}", collector.summary_report());
//! # Ok(())
//! # }
//! ```
//!
//! ## SciRS2 Integration
//!
//! OptiRS is built **exclusively** on SciRS2:
//!
//! - ✅ **Arrays**: `scirs2_core::ndarray` (NOT direct ndarray)
//! - ✅ **Random**: `scirs2_core::random` (NOT direct rand)
//! - ✅ **SIMD**: `scirs2_core::simd_ops`
//! - ✅ **Parallel**: `scirs2_core::parallel_ops`
//! - ✅ **GPU**: `scirs2_core::gpu`
//! - ✅ **Metrics**: `scirs2_core::metrics`
//!
//! This ensures type safety, performance, and consistency across the ecosystem.
//!
//! ## Performance
//!
//! - **549 unit tests** + **54 doc tests** = **603 total tests**
//! - **Zero clippy warnings** - Production quality
//! - **Comprehensive benchmarks** - Using Criterion.rs
//! - **Statistical analysis** - For reliable performance metrics
//!
//! ## Documentation
//!
//! - **API Documentation**: [docs.rs/optirs](https://docs.rs/optirs)
//! - **User Guide**: See `USAGE_GUIDE.md` (8000+ words)
//! - **Examples**: See `examples/` directory
//! - **README**: Comprehensive feature overview
//!
//! ## Contributing
//!
//! Contributions are welcome! Ensure:
//!
//! - **100% SciRS2 usage** - No direct external dependencies
//! - **All tests pass** - Run `cargo test`
//! - **Zero warnings** - Run `cargo clippy`
//! - **Documentation** - Add examples to public APIs
//!
//! ## License
//!
//! licensed under Apache-2.0
pub use optirs_core as core;
pub use optirs_gpu as gpu;
pub use optirs_tpu as tpu;
pub use optirs_learned as learned;
pub use optirs_nas as nas;
pub use optirs_bench as bench;
/// Common imports for ease of use
// Re-export core functionality at the top level
pub use crate;
pub use crateoptimizers;
pub use crateregularizers;
pub use crateschedulers;