single_utilities/types/mod.rs
1use std::hash::Hash;
2
3/// Represents the direction of operations in matrix or array computations.
4///
5/// This enum is used to specify whether operations should be performed
6/// along rows or columns of a data structure.
7pub enum Direction {
8 /// Operations performed along columns (vertical direction)
9 COLUMN,
10 /// Operations performed along rows (horizontal direction)
11 ROW,
12}
13
14impl Clone for Direction {
15 fn clone(&self) -> Self {
16 match self {
17 Self::ROW => Self::ROW,
18 Self::COLUMN => Self::COLUMN,
19 }
20 }
21}
22
23impl Direction {
24 /// Checks if the direction is row-wise.
25 ///
26 /// # Returns
27 /// `true` if the direction is `ROW`, `false` if it's `COLUMN`
28 pub fn is_row(&self) -> bool {
29 match self {
30 Self::ROW => true,
31 Self::COLUMN => false,
32 }
33 }
34}
35
36/// A trait for types that can serve as batch identifiers.
37///
38/// This trait is used to identify and group data in batch processing operations.
39/// Types implementing this trait must be cloneable, comparable for equality,
40/// and hashable for efficient lookup operations.
41pub trait BatchIdentifier: Clone + Eq + Hash {}
42
43// Implement BatchIdentifier for common types
44impl BatchIdentifier for String {}
45impl BatchIdentifier for &str {}
46impl BatchIdentifier for i32 {}
47impl BatchIdentifier for u32 {}
48impl BatchIdentifier for usize {}
49
50/// Enumeration of distance metrics for mathematical computations.
51///
52/// This enum defines common distance metrics used in machine learning,
53/// clustering, and similarity calculations. Each variant represents
54/// a different approach to measuring the distance between points or vectors.
55#[derive(Debug, Clone, Copy)]
56pub enum DistanceMetric {
57 /// Euclidean distance (L2 norm) - straight-line distance between points
58 Euclidean,
59 /// Manhattan distance (L1 norm) - sum of absolute differences along each dimension
60 Manhattan,
61 /// Cosine distance - measures the cosine of the angle between vectors
62 Cosine,
63}