@@ -6,6 +6,12 @@ use std::fmt::Debug;
66use std:: iter:: Sum ;
77use std:: ops:: { Add , AddAssign , MulAssign , SubAssign } ;
88
9+ /// A trait defining fundamental numeric operations and constraints.
10+ ///
11+ /// This trait bundles common numeric operations required for mathematical computations,
12+ /// including zero/one elements, numeric casting, assignment operations, ordering,
13+ /// bounds checking, and basic arithmetic. Types implementing this trait can be used
14+ /// in generic numeric algorithms.
915pub trait NumericOps :
1016 Zero
1117 + One
@@ -40,28 +46,55 @@ impl<
4046{
4147}
4248
49+ /// A thread-safe version of `NumericOps`.
50+ ///
51+ /// This trait extends `NumericOps` with `Send + Sync` bounds, making it suitable
52+ /// for use in concurrent and parallel computations where data needs to be
53+ /// safely shared across threads.
4354pub trait NumericOpsTS : NumericOps + Send + Sync { }
4455
4556impl < T : NumericOps + Send + Sync > NumericOpsTS for T { }
4657
58+ /// A trait for floating-point numeric operations.
59+ ///
60+ /// Extends `NumericOps` with floating-point specific operations from the `num_traits`
61+ /// crate, including floating-point arithmetic, primitive conversions, and core
62+ /// floating-point functionality. This trait is designed for types that represent
63+ /// real numbers with decimal precision.
4764pub trait FloatOps :
4865 NumericOps + num_traits:: Float + FromPrimitive + ToPrimitive + FloatCore
4966{
5067}
5168
5269impl < T : NumericOps + num_traits:: Float + FromPrimitive + ToPrimitive + FloatCore > FloatOps for T { }
5370
71+ /// A thread-safe version of `FloatOps`.
72+ ///
73+ /// This trait extends `FloatOps` with `Send + Sync` bounds for safe use in
74+ /// concurrent floating-point computations across multiple threads.
5475pub trait FloatOpsTS : FloatOps + Sync + Send { }
5576
5677impl < T : FloatOps + Send + Sync > FloatOpsTS for T { }
5778
5879#[ cfg( feature = "simd" ) ]
80+ /// A SIMD-enabled floating-point operations trait.
81+ ///
82+ /// Extends `FloatOpsTS` with SIMD (Single Instruction, Multiple Data) capabilities
83+ /// from the `simba` crate. This enables vectorized floating-point operations for
84+ /// improved performance in mathematical computations.
85+ ///
86+ /// Only available when the "simd" feature is enabled.
5987pub trait FloatOpsTSSimba : FloatOpsTS + SimdRealField + RealField { }
6088
6189#[ cfg( feature = "simd" ) ]
6290impl < T : FloatOpsTS + SimdRealField + RealField > FloatOpsTSSimba for T { }
6391
64- // Define a type alias for our numeric constraints
92+ /// A trait for numeric types suitable for normalization operations.
93+ ///
94+ /// This trait combines floating-point arithmetic with assignment operations,
95+ /// summation capabilities, and numeric casting. It's specifically designed
96+ /// for types that need to participate in normalization algorithms where
97+ /// values are scaled or adjusted relative to some total or maximum.
6598pub trait NumericNormalize :
6699 num_traits:: Float + std:: ops:: AddAssign + std:: iter:: Sum + num_traits:: NumCast
67100{
@@ -73,7 +106,16 @@ impl<T> NumericNormalize for T where
73106{
74107}
75108
109+ /// A trait for vectors that can be resized and filled with default values.
110+ ///
111+ /// Provides functionality to clear a vector and resize it to a specific length,
112+ /// filling all positions with the default value of the element type. This is
113+ /// useful for initializing or resetting vectors to a known state.
76114pub trait ZeroVec {
115+ /// Clears the vector and resizes it to the specified length, filling with default values.
116+ ///
117+ /// # Arguments
118+ /// * `len` - The desired length of the vector
77119 fn zero_len ( & mut self , len : usize ) ;
78120}
79121
@@ -85,6 +127,12 @@ impl<T: Default + Clone> ZeroVec for Vec<T> {
85127 }
86128}
87129
130+ /// A trait for unsigned integer types suitable for indexing operations.
131+ ///
132+ /// This trait combines unsigned integer properties with zero/one elements,
133+ /// ordering capabilities, and conversion to/from `usize`. It's designed for
134+ /// types that can be safely used as array or vector indices while providing
135+ /// mathematical operations and bounds checking.
88136pub trait UIndex :
89137 Unsigned + Zero + One + Copy + Eq + Ord + PartialOrd + From < usize > + Into < usize > + Bounded
90138{
@@ -95,6 +143,12 @@ impl<I: Unsigned + Zero + One + Copy + Eq + Ord + PartialOrd + From<usize> + Int
95143{
96144}
97145
146+ /// A trait for scalar values used in mathematical computations.
147+ ///
148+ /// This trait defines the minimal requirements for types that can be used as
149+ /// scalar values in mathematical operations. It requires static lifetime,
150+ /// cloning capability, equality comparison, and debug formatting. This is
151+ /// typically used as a constraint for generic mathematical algorithms.
98152pub trait Scalar : ' static + Clone + PartialEq + Debug { }
99153
100154impl < T : ' static + Clone + PartialEq + Debug > Scalar for T { }
0 commit comments