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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use core::fmt;
/// Any error related to Csl operations
#[derive(Debug, PartialEq)]
#[non_exhaustive]
pub enum CslError {
/// Data or indices length is greater than the product of all dimensions length
///
#[cfg_attr(feature = "alloc", doc = "```rust")]
#[cfg_attr(not(feature = "alloc"), doc = "```ignore")]
/// use ndsparse::csl::{CslError, CslVec};
/// let csl = CslVec::new([3], vec![8, 9, 9, 9, 9], vec![0, 5, 5, 5, 5], vec![0, 2]);
/// assert_eq!(csl, Err(ndsparse::Error::Csl(CslError::DataIndcsLengthGreaterThanDimsLength)));
/// ```
DataIndcsLengthGreaterThanDimsLength,
/// The data length is different than the indices length
///
#[cfg_attr(feature = "alloc", doc = "```rust")]
#[cfg_attr(not(feature = "alloc"), doc = "```ignore")]
/// use ndsparse::csl::{ CslError, CslVec};
/// let csl = CslVec::new([10], vec![8, 9], vec![0], vec![0, 2]);
/// assert_eq!(csl, Err(ndsparse::Error::Csl(CslError::DiffDataIndcsLength)));
/// ```
DiffDataIndcsLength,
/// Duplicated indices in a line
/// ```rust
/// use ndsparse::csl::{CslArray, CslError};
/// let csl = CslArray::new([10], [8, 9], [0, 0], [0, 2]);
/// assert_eq!(csl, Err(ndsparse::Error::Csl(CslError::DuplicatedIndices)));
/// ```
DuplicatedIndices,
/// A index is greater or equal to the innermost dimension length
///
/// ```rust
/// use ndsparse::csl::{CslArray, CslError};
/// let csl = CslArray::new([10], [8, 9], [0, 10], [0, 2]);
/// assert_eq!(csl, Err(ndsparse::Error::Csl(CslError::IndcsGreaterThanEqualDimLength)));
/// ```
IndcsGreaterThanEqualDimLength,
/// Some innermost dimension length is equal to zero
#[cfg_attr(feature = "alloc", doc = "```rust")]
#[cfg_attr(not(feature = "alloc"), doc = "```ignore")]
/// use ndsparse::csl::{CslError, CslVec};
/// let csl: ndsparse::Result<CslVec<i32, 5>>;
/// csl = CslVec::new([1, 2, 3, 0, 5], vec![], vec![], vec![]);
/// assert_eq!(csl, Err(ndsparse::Error::Csl(CslError::InnermostDimsZero)));
/// ```
InnermostDimsZero,
/// Line iterator must deal with non-empty dimensions
#[cfg_attr(feature = "alloc", doc = "```rust")]
#[cfg_attr(not(feature = "alloc"), doc = "```ignore")]
/// use ndsparse::csl::{CslVec, CslError};
/// let csl = CslVec::<i32, 0>::default();
/// assert_eq!(csl.outermost_line_iter(), Err(ndsparse::Error::Csl(CslError::InvalidIterDim)));
/// ```
InvalidIterDim,
/// Offsets length is different than the dimensions product
/// (without the innermost dimension) plus one.
/// This rule doesn't not apply to an empty dimension.
#[cfg_attr(feature = "alloc", doc = "```rust")]
#[cfg_attr(not(feature = "alloc"), doc = "```ignore")]
/// use ndsparse::csl::{CslError, CslVec};
/// let csl = CslVec::new([10], vec![8, 9], vec![0, 5], vec![0, 2, 4]);
/// assert_eq!(csl, Err(ndsparse::Error::Csl(CslError::InvalidOffsetsLength)));
/// ```
InvalidOffsetsLength,
/// Offsets aren't in ascending order
///
/// ```rust
/// use ndsparse::csl::{CslArray, CslError};
/// let csl = CslArray::new([10], [8, 9], [0, 5], [2, 0]);
/// assert_eq!(csl, Err(ndsparse::Error::Csl(CslError::InvalidOffsetsOrder)));
/// ```
InvalidOffsetsOrder,
/// Last offset is not equal to the nnz
///
/// ```rust
/// use ndsparse::csl::{CslArray, CslError};
/// let csl = CslArray::new([10], [8, 9], [0, 5], [0, 4]);
/// assert_eq!(csl, Err(ndsparse::Error::Csl(CslError::LastOffsetDifferentNnz)));
/// ```
LastOffsetDifferentNnz,
/// nnz is greater than the maximum permitted number of nnz
#[cfg_attr(all(feature = "alloc", feature = "with-rand"), doc = "```rust")]
#[cfg_attr(not(all(feature = "alloc", feature = "with-rand")), doc = "```ignore")]
/// use ndsparse::csl::CslVec;
/// use rand::{Rng, rngs::mock::StepRng};
/// let mut rng = StepRng::new(0, 1);
/// let dims = [1, 2, 3]; // Max of 6 elements (1 * 2 * 3)
/// let csl: ndsparse::Result<CslVec<i32, 3>>;
/// csl = CslVec::new_controlled_random_rand(dims, 7, &mut rng, |r, _| r.gen());
/// assert_eq!(csl, Err(ndsparse::Error::Csl(ndsparse::csl::CslError::NnzGreaterThanMaximumNnz)));
/// ```
#[cfg(feature = "with-rand")]
NnzGreaterThanMaximumNnz,
/// It isn't possible to have more lines than usize::MAX - 2
///
/// ```rust
/// use ndsparse::csl::{CslArray, CslError};
/// let csl = CslArray::new([18446744073709551295, 255, 3026418949592973312], [0], [0], [0, 1]);
/// assert_eq!(csl, Err(ndsparse::Error::Csl(CslError::OffsLengthOverflow)));
/// ```
OffsLengthOverflow,
}
impl fmt::Display for CslError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match *self {
Self::DataIndcsLengthGreaterThanDimsLength => "DataIndcsLengthGreaterThanDimsLength",
Self::DiffDataIndcsLength => "DiffDataIndcsLength",
Self::DuplicatedIndices => "DuplicatedIndices",
Self::IndcsGreaterThanEqualDimLength => "IndcsGreaterThanEqualDimLength",
Self::InnermostDimsZero => "InnermostDimsZero",
Self::InvalidIterDim => "InvalidIterDim",
Self::InvalidOffsetsLength => "InvalidOffsetsLength",
Self::InvalidOffsetsOrder => "InvalidOffsetsOrder",
Self::LastOffsetDifferentNnz => "LastOffsetDifferentNnz",
#[cfg(feature = "with-rand")]
Self::NnzGreaterThanMaximumNnz => "NnzGreaterThanMaximumNnz",
Self::OffsLengthOverflow => "OffsLengthOverflowb",
};
write!(f, "{}", s)
}
}
#[cfg(feature = "std")]
impl std::error::Error for CslError {}