diff --git a/nalgebra-lapack/src/eigen.rs b/nalgebra-lapack/src/eigen.rs index 9adbb26b..4347cb03 100644 --- a/nalgebra-lapack/src/eigen.rs +++ b/nalgebra-lapack/src/eigen.rs @@ -78,9 +78,11 @@ where let lda = n as i32; - let mut wr = unsafe { Matrix::new_uninitialized_generic(nrows, U1).assume_init() }; + // IMPORTANT TODO: this is still UB. + + let mut wr = unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() }; // TODO: Tap into the workspace. - let mut wi = unsafe { Matrix::new_uninitialized_generic(nrows, U1).assume_init() }; + let mut wi = unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() }; let mut info = 0; let mut placeholder1 = [T::zero()]; @@ -247,8 +249,8 @@ where let lda = n as i32; - let mut wr = unsafe { Matrix::new_uninitialized_generic(nrows, U1).assume_init() }; - let mut wi = unsafe { Matrix::new_uninitialized_generic(nrows, U1).assume_init() }; + let mut wr = unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() }; + let mut wi = unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() }; let mut info = 0; let mut placeholder1 = [T::zero()]; @@ -291,7 +293,7 @@ where ); lapack_panic!(info); - let mut res = unsafe { Matrix::new_uninitialized_generic(nrows, U1).assume_init() }; + let mut res = unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() }; for i in 0..res.len() { res[i] = Complex::new(wr[i], wi[i]); diff --git a/nalgebra-lapack/src/hessenberg.rs b/nalgebra-lapack/src/hessenberg.rs index bddd133f..b5d6648a 100644 --- a/nalgebra-lapack/src/hessenberg.rs +++ b/nalgebra-lapack/src/hessenberg.rs @@ -60,8 +60,9 @@ where "Unable to compute the hessenberg decomposition of an empty matrix." ); + // IMPORTANT TODO: this is still UB. let mut tau = unsafe { - Matrix::new_uninitialized_generic(nrows.sub(U1), U1).assume_init() + Matrix::new_uninitialized_generic(nrows.sub(Const::<1>), Const::<1>).assume_init() }; let mut info = 0; diff --git a/nalgebra-lapack/src/lu.rs b/nalgebra-lapack/src/lu.rs index 162b9ae7..2130fc7e 100644 --- a/nalgebra-lapack/src/lu.rs +++ b/nalgebra-lapack/src/lu.rs @@ -66,7 +66,7 @@ where let nrows = nrows.value() as i32; let ncols = ncols.value() as i32; - let mut ipiv: OVector = Matrix::zeros_generic(min_nrows_ncols, U1); + let mut ipiv: OVector = Matrix::zeros_generic(min_nrows_ncols, Const::<1>); let mut info = 0; diff --git a/nalgebra-lapack/src/schur.rs b/nalgebra-lapack/src/schur.rs index e5435dbf..35da8bec 100644 --- a/nalgebra-lapack/src/schur.rs +++ b/nalgebra-lapack/src/schur.rs @@ -78,8 +78,8 @@ where let mut info = 0; - let mut wr = unsafe { Matrix::new_uninitialized_generic(nrows, U1).assume_init() }; - let mut wi = unsafe { Matrix::new_uninitialized_generic(nrows, U1).assume_init() }; + let mut wr = unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() }; + let mut wi = unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() }; let mut q = unsafe { Matrix::new_uninitialized_generic(nrows, ncols).assume_init() }; // Placeholders: let mut bwork = [0i32]; @@ -154,7 +154,7 @@ where DefaultAllocator: Allocator, D>, { let mut out = - unsafe { OVector::new_uninitialized_generic(self.t.data.shape().0, U1) }; + unsafe { OVector::new_uninitialized_generic(self.t.data.shape().0, Const::<1>) }; for i in 0..out.len() { out[i] = MaybeUninit::new(Complex::new(self.re[i], self.im[i])); diff --git a/nalgebra-lapack/src/svd.rs b/nalgebra-lapack/src/svd.rs index 2321668d..5bf4758a 100644 --- a/nalgebra-lapack/src/svd.rs +++ b/nalgebra-lapack/src/svd.rs @@ -99,8 +99,9 @@ macro_rules! svd_impl( let lda = nrows.value() as i32; + // IMPORTANT TODO: this is still UB. let mut u = unsafe { Matrix::new_uninitialized_generic(nrows, nrows).assume_init() }; - let mut s = unsafe { Matrix::new_uninitialized_generic(nrows.min(ncols), U1).assume_init() }; + let mut s = unsafe { Matrix::new_uninitialized_generic(nrows.min(ncols), Const::<1>).assume_init() }; let mut vt = unsafe { Matrix::new_uninitialized_generic(ncols, ncols).assume_init() }; let ldu = nrows.value(); diff --git a/nalgebra-lapack/src/symmetric_eigen.rs b/nalgebra-lapack/src/symmetric_eigen.rs index cceca046..e2d9867b 100644 --- a/nalgebra-lapack/src/symmetric_eigen.rs +++ b/nalgebra-lapack/src/symmetric_eigen.rs @@ -93,9 +93,10 @@ where let n = nrows.value(); let lda = n as i32; - + + // IMPORTANT TODO: this is still UB. let mut values = - unsafe { Matrix::new_uninitialized_generic(nrows, U1).assume_init() }; + unsafe { Matrix::new_uninitialized_generic(nrows, Const::<1>).assume_init() }; let mut info = 0; let lwork = T::xsyev_work_size(jobz, b'L', n as i32, m.as_mut_slice(), lda, &mut info); diff --git a/tests/proptest/mod.rs b/tests/proptest/mod.rs index 60d32248..ec2e2c7b 100644 --- a/tests/proptest/mod.rs +++ b/tests/proptest/mod.rs @@ -180,11 +180,11 @@ macro_rules! generate_matrix_sanity_test { // Test all fixed-size matrices with row/col dimensions up to 3 generate_matrix_sanity_test!(test_matrix_u0_u0, Const::<0>, Const::<0>); -generate_matrix_sanity_test!(test_matrix_u1_u0, U1, Const::<0>); -generate_matrix_sanity_test!(test_matrix_u0_u1, Const::<0>, U1); -generate_matrix_sanity_test!(test_matrix_u1_u1, U1, U1); -generate_matrix_sanity_test!(test_matrix_u2_u1, Const::<2>, U1); -generate_matrix_sanity_test!(test_matrix_u1_u2, U1, Const::<2>); +generate_matrix_sanity_test!(test_matrix_u1_u0, Const::<1>, Const::<0>); +generate_matrix_sanity_test!(test_matrix_u0_u1, Const::<0>, Const::<1>); +generate_matrix_sanity_test!(test_matrix_u1_u1, Const::<1>, Const::<1>); +generate_matrix_sanity_test!(test_matrix_u2_u1, Const::<2>, Const::<1>); +generate_matrix_sanity_test!(test_matrix_u1_u2, Const::<1>, Const::<2>); generate_matrix_sanity_test!(test_matrix_u2_u2, Const::<2>, Const::<2>); generate_matrix_sanity_test!(test_matrix_u3_u2, Const::<3>, Const::<2>); generate_matrix_sanity_test!(test_matrix_u2_u3, Const::<2>, Const::<3>);