fenris_traits/
allocators.rs

1//! Helper traits for allocator trait bounds.
2use nalgebra::allocator::Allocator;
3use nalgebra::{DefaultAllocator, DimName, Scalar, U1};
4
5/// An allocator for a single dimension.
6pub trait DimAllocator<T: Scalar, D: DimName>:
7Allocator<T, D>
8+ Allocator<T, D, D>
9+ Allocator<T, U1, D>
10// Used for various functionality like decompositions
11+ Allocator<usize, D>
12+ Allocator<(usize, usize), D>
13// Provide allocators for built-in types so that we don't need separate traits to use these
14// if we already have Allocator<T, D>
15+ Allocator<f32, D>
16+ Allocator<f64, D>
17+ Allocator<i8, D>
18+ Allocator<i32, D>
19+ Allocator<i64, D>
20+ Allocator<u8, D>
21+ Allocator<u16, D>
22+ Allocator<u32, D>
23+ Allocator<u64, D>
24+ Allocator<isize, D>
25+ Allocator<bool, D>
26{}
27
28impl<T, D> DimAllocator<T, D> for DefaultAllocator
29where
30    T: Scalar,
31    D: DimName,
32    DefaultAllocator: Allocator<T, D>
33        + Allocator<T, D, D>
34        + Allocator<T, U1, D>
35        + Allocator<usize, D>
36        + Allocator<(usize, usize), D>
37        + Allocator<f32, D>
38        + Allocator<f64, D>
39        + Allocator<i8, D>
40        + Allocator<i32, D>
41        + Allocator<i64, D>
42        + Allocator<u8, D>
43        + Allocator<u16, D>
44        + Allocator<u32, D>
45        + Allocator<u64, D>
46        + Allocator<isize, D>
47        + Allocator<bool, D>,
48{
49}
50
51/// An allocator for two dimensions.
52pub trait BiDimAllocator<T: Scalar, D1: DimName, D2: DimName>:
53    DimAllocator<T, D1> + DimAllocator<T, D2> + Allocator<T, D1, D2> + Allocator<T, D2, D1>
54{
55}
56
57impl<T: Scalar, D1: DimName, D2: DimName> BiDimAllocator<T, D1, D2> for DefaultAllocator where
58    DefaultAllocator: DimAllocator<T, D1> + DimAllocator<T, D2> + Allocator<T, D1, D2> + Allocator<T, D2, D1>
59{
60}
61
62/// An allocator for three dimensions.
63pub trait TriDimAllocator<T: Scalar, D1: DimName, D2: DimName, D3: DimName>:
64    BiDimAllocator<T, D1, D2> + BiDimAllocator<T, D1, D3> + BiDimAllocator<T, D2, D3>
65{
66}
67
68impl<T: Scalar, D1: DimName, D2: DimName, D3: DimName> TriDimAllocator<T, D1, D2, D3> for DefaultAllocator where
69    DefaultAllocator: BiDimAllocator<T, D1, D2> + BiDimAllocator<T, D1, D3> + BiDimAllocator<T, D2, D3>
70{
71}
72
73pub trait QuadDimAllocator<T: Scalar, D1: DimName, D2: DimName, D3: DimName, D4: DimName>:
74    TriDimAllocator<T, D1, D2, D3>
75    + TriDimAllocator<T, D1, D2, D4>
76    + TriDimAllocator<T, D1, D3, D4>
77    + TriDimAllocator<T, D2, D3, D4>
78{
79}
80
81impl<T: Scalar, D1: DimName, D2: DimName, D3: DimName, D4: DimName> QuadDimAllocator<T, D1, D2, D3, D4>
82    for DefaultAllocator
83where
84    DefaultAllocator: TriDimAllocator<T, D1, D2, D3>
85        + TriDimAllocator<T, D1, D2, D4>
86        + TriDimAllocator<T, D1, D3, D4>
87        + TriDimAllocator<T, D2, D3, D4>,
88{
89}