Skip to main content

fcmaes_core/
lib.rs

1#![doc = include_str!("../README.md")]
2#![deny(missing_docs)]
3#![deny(rustdoc::broken_intra_doc_links)]
4// Public entry points must state how they fail. Optimizer misuse (wrong batch
5// length, ask/tell out of order, mismatched bounds) is the most common
6// integration error, so the panicking and fallible variants both document
7// their contract.
8#![warn(clippy::missing_errors_doc)]
9#![warn(clippy::missing_panics_doc)]
10
11pub mod biteopt;
12pub mod cmaes;
13pub mod crfmnes;
14pub mod da;
15pub mod de;
16pub mod fitness;
17pub mod mapelites;
18pub mod mode;
19pub mod moretry;
20pub mod pgpe;
21pub mod retry;
22pub mod rng;
23
24pub use biteopt::{
25    BiteOpt, BiteParams, BiteResult, DeepBiteOpt, optimize_bite, validate_bite_inputs,
26};
27pub use cmaes::{AcmaResult, Cmaes, CmaesParams};
28pub use crfmnes::{Crfmnes, CrfmnesParams, CrfmnesResult};
29pub use da::{DaParams, DaResult, optimize_da};
30pub use de::{De, DeParams, DeResult};
31pub use fitness::{Fitness, NAN_REPLACEMENT, Objective, parallel_batch};
32pub use mapelites::{
33    Archive, DiversifierParams, MapElitesParams, QdBatchFitness, QdFitness, diversify,
34    diversify_batch, map_elites, map_elites_batch, map_elites_batch_with_progress,
35};
36pub use mode::{Mode, ModeParams, ModeResult};
37pub use moretry::{
38    MoRetryConfig, MoRetryEntry, MoRetryResult, MultiObjective, WeightedObjective, moretry,
39    pareto_indices, scalarize,
40};
41pub use pgpe::{Pgpe, PgpeParams, PgpeResult};
42pub use retry::{
43    AdvancedRetryConfig, RetryBounds, RetryConfig, RetryContext, RetryEntry, RetryImprovement,
44    RetryResult, RetryRunResult, advanced_retry, retry,
45};
46pub use rng::Rng;
47
48/// Version string of the core crate, surfaced through the Python build-info.
49pub const CORE_VERSION: &str = env!("CARGO_PKG_VERSION");
50
51/// Sum a slice of `f64`.
52///
53/// This exists as an installation probe: it is the smallest call that proves
54/// the Python → PyO3 → Rust path is wired end to end, and it backs
55/// `fcmaes_rust._fcmaes_ext._phase1_probe_sum`. It is not a numerical
56/// reduction API — it performs no compensated summation and applications
57/// should use [`Iterator::sum`] directly.
58///
59/// # Examples
60///
61/// ```
62/// assert_eq!(fcmaes_core::probe_sum(&[1.0, 2.0, 3.5]), 6.5);
63/// assert_eq!(fcmaes_core::probe_sum(&[]), 0.0);
64/// ```
65pub fn probe_sum(values: &[f64]) -> f64 {
66    values.iter().sum()
67}
68
69#[cfg(test)]
70mod tests {
71    use super::*;
72
73    #[test]
74    fn probe_sum_adds_values() {
75        assert_eq!(probe_sum(&[1.0, 2.0, 3.5]), 6.5);
76    }
77
78    #[test]
79    fn probe_sum_empty_is_zero() {
80        assert_eq!(probe_sum(&[]), 0.0);
81    }
82}