Got rid of the `unimplemented_or_uninitialized_generic` macro

This commit is contained in:
Violeta Hernández 2021-07-17 13:36:35 -05:00
parent 0687318c7a
commit fa1ed9683b
7 changed files with 15 additions and 27 deletions

View File

@ -140,6 +140,7 @@ impl ComplexHelper for Complex<f64> {
}
}
// This is UB.
unsafe fn uninitialized_vec<T: Copy>(n: usize) -> Vec<T> {
let mut res = Vec::new();
res.reserve_exact(n);

View File

@ -25,14 +25,6 @@ use crate::base::{
ArrayStorage, Const, DefaultAllocator, Matrix, OMatrix, OVector, Scalar, Unit, Vector,
};
/// OBJECTIVE: GET RID OF THIS!
#[macro_export]
macro_rules! unimplemented_or_uninitialized_generic {
($nrows:expr, $ncols:expr) => {{
crate::base::Matrix::new_uninitialized_generic($nrows, $ncols)
}};
}
/// # Generic constructors
/// This set of matrix and vector construction functions are all generic
/// with-regard to the matrix dimensions. They all expect to be given

View File

@ -279,7 +279,7 @@ where
CsMatrix {
data: CsVecStorage {
shape: (nrows, ncols),
p: OVector::zeros_generic(ncols, U1),
p: OVector::zeros_generic(ncols, Const::<1>),
i,
vals,
},
@ -429,7 +429,7 @@ impl<T: Scalar, R: Dim, C: Dim, S: CsStorage<T, R, C>> CsMatrix<T, R, C, S> {
let nvals = self.len();
let mut res = CsMatrix::new_uninitialized_generic(ncols, nrows, nvals);
let mut workspace = Vector::zeros_generic(nrows, U1);
let mut workspace = Vector::zeros_generic(nrows, Const::<1>);
// Compute p.
for i in 0..nvals {
@ -472,8 +472,7 @@ where
{
// Size = R
let nrows = self.data.shape().0;
let mut workspace =
unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, U1) };
let mut workspace = Matrix::new_uninitialized_generic(nrows, Const::<1>);
self.sort_with_workspace(workspace.as_mut_slice());
}

View File

@ -48,10 +48,8 @@ where
let (l, u) = Self::nonzero_pattern(m);
// Workspaces.
let work_x =
unsafe { crate::unimplemented_or_uninitialized_generic!(m.data.shape().0, U1) };
let work_c =
unsafe { crate::unimplemented_or_uninitialized_generic!(m.data.shape().1, U1) };
let work_x = Matrix::new_uninitialized_generic(m.data.shape().0, Const::<1>);
let work_c = Matrix::new_uninitialized_generic(m.data.shape().1, Const::<1>);
let mut original_p = m.data.p.as_slice().to_vec();
original_p.push(m.data.i.len());
@ -294,8 +292,7 @@ where
let etree = Self::elimination_tree(m);
let (nrows, ncols) = m.data.shape();
let mut rows = Vec::with_capacity(m.len());
let mut cols =
unsafe { crate::unimplemented_or_uninitialized_generic!(m.data.shape().0, U1) };
let mut cols = Matrix::new_uninitialized_generic(m.data.shape().0, Const::<1>);
let mut marks = Vec::new();
// NOTE: the following will actually compute the non-zero pattern of

View File

@ -148,7 +148,7 @@ where
);
let mut res = CsMatrix::new_uninitialized_generic(nrows1, ncols2, self.len() + rhs.len());
let mut workspace = OVector::<T, R1>::zeros_generic(nrows1, U1);
let mut workspace = OVector::<T, R1>::zeros_generic(nrows1, Const::<1>);
let mut nz = 0;
for j in 0..ncols2.value() {
@ -241,9 +241,9 @@ where
);
let mut res = CsMatrix::new_uninitialized_generic(nrows1, ncols2, self.len() + rhs.len());
let mut timestamps = OVector::zeros_generic(nrows1, U1);
let mut timestamps = OVector::zeros_generic(nrows1, Const::<1>);
let mut workspace =
unsafe { crate::unimplemented_or_uninitialized_generic!(nrows1, U1) };
Matrix::new_uninitialized_generic(nrows1, Const::<1>) ;
let mut nz = 0;
for j in 0..ncols2.value() {

View File

@ -152,8 +152,7 @@ impl<T: RealField, D: Dim, S: CsStorage<T, D, D>> CsMatrix<T, D, D, S> {
self.lower_triangular_reach(b, &mut reach);
// We sort the reach so the result matrix has sorted indices.
reach.sort_unstable();
let mut workspace =
unsafe { crate::unimplemented_or_uninitialized_generic!(b.data.shape().0, U1) };
let mut workspace = Matrix::new_uninitialized_generic(b.data.shape().0, Const::<1>);
for i in reach.iter().cloned() {
workspace[i] = T::zero();
@ -191,7 +190,7 @@ impl<T: RealField, D: Dim, S: CsStorage<T, D, D>> CsMatrix<T, D, D, S> {
// Copy the result into a sparse vector.
let mut result =
CsVector::new_uninitialized_generic(b.data.shape().0, U1, reach.len());
CsVector::new_uninitialized_generic(b.data.shape().0, Const::<1>, reach.len());
for (i, val) in reach.iter().zip(result.data.vals.iter_mut()) {
*val = workspace[*i];
@ -255,7 +254,7 @@ impl<T: RealField, D: Dim, S: CsStorage<T, D, D>> CsMatrix<T, D, D, S> {
S2: CsStorage<T, D2>,
DefaultAllocator: Allocator<bool, D>,
{
let mut visited = OVector::repeat_generic(self.data.shape().1, U1, false);
let mut visited = OVector::repeat_generic(self.data.shape().1, Const::<1>, false);
let mut stack = Vec::new();
for irow in b.data.column_row_indices(0) {

View File

@ -433,8 +433,8 @@ where
"Matrix meet/join error: mismatched dimensions."
);
let mut mres = unsafe { crate::unimplemented_or_uninitialized_generic!(shape.0, shape.1) };
let mut jres = unsafe { crate::unimplemented_or_uninitialized_generic!(shape.0, shape.1) };
let mut mres = Matrix::new_uninitialized_generic(shape.0, shape.1);
let mut jres = Matrix::new_uninitialized_generic(shape.0, shape.1);
for i in 0..shape.0.value() * shape.1.value() {
unsafe {