Skip to main content

diffusionx/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![doc = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/README.md"))]
3
4#[cfg(feature = "mimalloc")]
5#[global_allocator]
6static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
7
8/// Numeric bound used by simulations whose time and state values are floating point.
9///
10/// This trait is implemented automatically for any type that satisfies the required
11/// arithmetic, constant, formatting, and thread-safety bounds. Most continuous
12/// process APIs use `T: FloatExt` so they can work with `f32`, `f64`, or compatible
13/// numeric types without repeating the full bound list.
14pub trait FloatExt:
15    num_traits::Float
16    + num_traits::FloatConst
17    + std::fmt::Debug
18    + Send
19    + Sync
20    + std::ops::AddAssign<Self>
21    + std::ops::MulAssign<Self>
22    + std::iter::Sum
23{
24}
25
26impl<T> FloatExt for T where
27    T: num_traits::Float
28        + num_traits::FloatConst
29        + std::fmt::Debug
30        + Send
31        + Sync
32        + std::ops::AddAssign<Self>
33        + std::ops::MulAssign<Self>
34        + std::iter::Sum
35{
36}
37
38/// Numeric bound used by discrete processes for step counters and integer states.
39///
40/// This trait is implemented automatically for primitive integer-like types that
41/// are copyable, summable, debuggable, and safe to share across worker threads.
42pub trait IntExt: num_traits::PrimInt + std::fmt::Debug + Send + Sync + std::iter::Sum {}
43impl<T> IntExt for T where T: num_traits::PrimInt + std::fmt::Debug + Send + Sync + std::iter::Sum {}
44
45/// Numeric bound used by process state values that may be integer or floating point.
46///
47/// `RealExt` is intentionally less restrictive than [`FloatExt`]: it supports
48/// arithmetic, conversion to and from numeric types, ordering, copying, and
49/// summation, but does not require floating-point-only operations such as
50/// exponentials or square roots.
51pub trait RealExt:
52    num_traits::Num
53    + num_traits::NumCast
54    + std::fmt::Debug
55    + Send
56    + Sync
57    + Copy
58    + PartialOrd
59    + std::iter::Sum
60{
61}
62
63impl<T> RealExt for T where
64    T: num_traits::Num
65        + num_traits::NumCast
66        + std::fmt::Debug
67        + Send
68        + Sync
69        + Copy
70        + PartialOrd
71        + std::iter::Sum
72{
73}
74
75mod error;
76pub use error::*;
77
78/// Random number generation module
79pub mod random;
80
81/// Stochastic process simulation module
82pub mod simulation;
83
84/// Utility functions and algorithms
85pub mod utils;
86
87/// Visualization module
88#[cfg(feature = "visualize")]
89#[cfg_attr(docsrs, doc(cfg(feature = "visualize")))]
90pub mod visualize;
91
92/// GPU acceleration module
93#[cfg(any(feature = "cuda", feature = "metal"))]
94pub mod gpu;