scirs2_integrate/common.rs
1//! Common traits and types used throughout the crate
2//!
3//! This module defines common traits and types that are used by multiple
4//! parts of the code to ensure consistency and reduce duplication.
5
6use scirs2_core::ndarray::ScalarOperand;
7use scirs2_core::numeric::{Float, FromPrimitive};
8use std::fmt::{Debug, Display, LowerExp};
9
10/// A trait that bundles all the requirements for floating-point types
11/// used in the integration routines.
12///
13/// This trait simplifies type signatures by combining all the trait bounds
14/// that are commonly needed for the numeric operations performed in
15/// integration routines.
16pub trait IntegrateFloat:
17 Float
18 + FromPrimitive
19 + Debug
20 + 'static
21 + ScalarOperand
22 + std::ops::AddAssign
23 + std::ops::SubAssign
24 + std::ops::MulAssign
25 + std::ops::DivAssign
26 + Display
27 + LowerExp
28 + std::iter::Sum
29{
30 /// Convert to f64 for interfacing with GPU kernels
31 fn to_f64(self) -> Option<f64>;
32}
33
34// Specific implementations for common float types
35impl IntegrateFloat for f32 {
36 fn to_f64(self) -> Option<f64> {
37 Some(self as f64)
38 }
39}
40
41impl IntegrateFloat for f64 {
42 fn to_f64(self) -> Option<f64> {
43 Some(self)
44 }
45}