Skip to main content

radiate_gp/
lib.rs

1pub mod collections;
2pub mod ops;
3pub mod regression;
4
5pub use collections::*;
6pub use ops::{Op, OperationMutator, activation_ops, all_ops, math_ops};
7pub use regression::{Accuracy, AccuracyResult, DataSet, Loss, Regression};
8
9#[cfg(feature = "serde")]
10use serde::{Deserialize, Serialize};
11use std::fmt::Display;
12use std::ops::Deref;
13
14/// Arity is a way to describe how many inputs an operation expects.
15/// It can be zero, a specific number, or any number.
16#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy, Default)]
17#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
18pub enum Arity {
19    Zero,
20    Exact(usize),
21    #[default]
22    Any,
23}
24
25impl From<usize> for Arity {
26    fn from(value: usize) -> Self {
27        match value {
28            0 => Arity::Zero,
29            n => Arity::Exact(n),
30        }
31    }
32}
33
34impl Deref for Arity {
35    type Target = usize;
36
37    fn deref(&self) -> &Self::Target {
38        match self {
39            Arity::Zero => &0,
40            Arity::Exact(n) => n,
41            Arity::Any => &0,
42        }
43    }
44}
45
46impl Display for Arity {
47    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48        match self {
49            Arity::Zero => write!(f, "{:<5}", "Zero"),
50            Arity::Exact(n) => write!(f, "{:<5}", n),
51            Arity::Any => write!(f, "{:<5}", "Any"),
52        }
53    }
54}