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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Storage formats.

#[cfg(debug_assertions)]
trait Validate {
    fn validate(&self);
}

macro_rules! buffer(
    ($capacity:expr) => ({
        let capacity = $capacity as usize;
        let mut buffer = Vec::with_capacity(capacity);
        buffer.set_len(capacity);
        buffer
    });
);

macro_rules! min(
    ($left:expr, $right:expr) => ({
        let (left, right) = ($left, $right);
        if left > right { right } else { left }
    });
);

macro_rules! size(
    ($kind:ident, $rows:ident, $columns:ident) => (
        impl<T: ::Element> ::Size for $kind<T> {
            #[inline(always)]
            fn rows(&self) -> usize {
                self.$rows
            }

            #[inline(always)]
            fn columns(&self) -> usize {
                self.$columns
            }
        }
    );
    ($kind:ident) => (
        size!($kind, rows, columns);
    );
);

#[cfg(debug_assertions)]
macro_rules! validate(
    ($matrix:expr) => ({
        use ::format::Validate;
        let matrix = $matrix;
        matrix.validate();
        matrix
    });
);

#[cfg(not(debug_assertions))]
macro_rules! validate(
    ($matrix:expr) => ($matrix);
);

pub mod banded;
pub mod compressed;
pub mod conventional;
pub mod diagonal;
pub mod packed;

pub use self::banded::Banded;
pub use self::compressed::Compressed;
pub use self::conventional::Conventional;
pub use self::diagonal::Diagonal;
pub use self::packed::Packed;