1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use num::{Signed, FromPrimitive, Bounded};
use approx::AbsDiffEq;

use alga::general::{Ring, Lattice};
use na::{Scalar, DimName, DimMin, U1};
use na::allocator::Allocator;

/// A type-level number representing a vector, matrix row, or matrix column, dimension.
pub trait Dimension: DimName + DimMin<Self, Output = Self> {}
impl<D: DimName + DimMin<D, Output = Self>> Dimension for D {}


/// A number that can either be an integer or a float.
pub trait Number: Scalar + Ring + Lattice + AbsDiffEq<Epsilon = Self> + Signed + FromPrimitive + Bounded {
}

impl<T: Scalar + Ring + Lattice + AbsDiffEq<Epsilon = Self> + Signed + FromPrimitive + Bounded> Number for T {
}

#[doc(hidden)]
pub trait Alloc<N: Scalar, R: Dimension, C: Dimension = U1>:
Allocator<N, R> + Allocator<N, C> + Allocator<N, U1, R> + Allocator<N, U1, C> + Allocator<N, R, C> + Allocator<N, C, R> + Allocator<N, R, R> + Allocator<N, C, C> +
Allocator<bool, R> + Allocator<bool, C> +
Allocator<f32, R> + Allocator<f32, C> +
Allocator<u32, R> + Allocator<u32, C> +
Allocator<i32, R> + Allocator<i32, C> +
Allocator<f64, R> + Allocator<f64, C> +
Allocator<u64, R> + Allocator<u64, C> +
Allocator<i64, R> + Allocator<i64, C> +
Allocator<i16, R> + Allocator<i16, C> +
Allocator<(usize, usize), R> + Allocator<(usize, usize), C>
{
}

impl<N: Scalar, R: Dimension, C: Dimension, T>
    Alloc<N, R, C> for T
where T: Allocator<N, R> + Allocator<N, C> + Allocator<N, U1, R> + Allocator<N, U1, C> + Allocator<N, R, C> + Allocator<N, C, R> + Allocator<N, R, R> + Allocator<N, C, C> +
         Allocator<bool, R> + Allocator<bool, C> +
         Allocator<f32, R> + Allocator<f32, C> +
         Allocator<u32, R> + Allocator<u32, C> +
         Allocator<i32, R> + Allocator<i32, C> +
         Allocator<f64, R> + Allocator<f64, C> +
         Allocator<u64, R> + Allocator<u64, C> +
         Allocator<i64, R> + Allocator<i64, C> +
         Allocator<i16, R> + Allocator<i16, C> +
         Allocator<(usize, usize), R> + Allocator<(usize, usize), C>
{
}