From cd12422d6ffc95010bd0fe433f9e2cd6053e07c2 Mon Sep 17 00:00:00 2001 From: Avi Weinstock Date: Fri, 27 Nov 2020 15:58:48 -0500 Subject: [PATCH] Change `zero_or_uninitialized_generic` to `unimplemented_or_uninitialized_generic`, and use it instead of manually dispatching on `feature=no_unsound_assume_init` in functions without `N: Zero`. --- src/base/blas.rs | 10 ++---- src/base/construction.rs | 25 +++++++------- src/base/conversion.rs | 10 ++---- src/base/edition.rs | 19 +++-------- src/base/matrix.rs | 52 ++++++----------------------- src/base/ops.rs | 13 +++----- src/base/statistics.rs | 10 ++---- src/geometry/point.rs | 5 +-- src/geometry/point_construction.rs | 5 +-- src/linalg/bidiagonal.rs | 12 +++---- src/linalg/cholesky.rs | 4 +-- src/linalg/hessenberg.rs | 4 +-- src/linalg/permutation_sequence.rs | 5 +-- src/linalg/qr.rs | 2 +- src/linalg/schur.rs | 12 +++---- src/linalg/symmetric_tridiagonal.rs | 4 +-- 16 files changed, 62 insertions(+), 130 deletions(-) diff --git a/src/base/blas.rs b/src/base/blas.rs index ea56c620..111c6dd1 100644 --- a/src/base/blas.rs +++ b/src/base/blas.rs @@ -1328,10 +1328,7 @@ where ShapeConstraint: DimEq + DimEq + DimEq, DefaultAllocator: Allocator, { - #[cfg(feature="no_unsound_assume_init")] - let mut work = Vector::zeros_generic(self.data.shape().0, U1); - #[cfg(not(feature="no_unsound_assume_init"))] - let mut work = unsafe { Vector::new_uninitialized_generic(self.data.shape().0, U1).assume_init() }; + let mut work = unsafe { crate::unimplemented_or_uninitialized_generic!(self.data.shape().0, U1) }; self.quadform_tr_with_workspace(&mut work, alpha, lhs, mid, beta) } @@ -1424,10 +1421,7 @@ where ShapeConstraint: DimEq + DimEq + AreMultipliable, DefaultAllocator: Allocator, { - #[cfg(feature="no_unsound_assume_init")] - let mut work = Vector::zeros_generic(mid.data.shape().0, U1); - #[cfg(not(feature="no_unsound_assume_init"))] - let mut work = unsafe { Vector::new_uninitialized_generic(mid.data.shape().0, U1).assume_init() }; + let mut work = unsafe { crate::unimplemented_or_uninitialized_generic!(mid.data.shape().0, U1) }; self.quadform_with_workspace(&mut work, alpha, mid, rhs, beta) } } diff --git a/src/base/construction.rs b/src/base/construction.rs index 722bef75..e0464a02 100644 --- a/src/base/construction.rs +++ b/src/base/construction.rs @@ -26,12 +26,19 @@ use crate::base::dimension::{Dim, DimName, Dynamic, U1, U2, U3, U4, U5, U6}; use crate::base::storage::Storage; use crate::base::{DefaultAllocator, Matrix, MatrixMN, MatrixN, Scalar, Unit, Vector, VectorN}; -/// When "no_unsound_assume_init" is enabled, expands to `zeros_generic()` instead of `new_uninitialized_generic().assume_init()`. -/// Intended for use in contexts where the `Scalar` type implements `num_traits::Zero`, to check whether uninitialized memory is actually performance-critical. +/// When "no_unsound_assume_init" is enabled, expands to `unimplemented!()` instead of `new_uninitialized_generic().assume_init()`. +/// Intended as a placeholder, each callsite should be refactored to use uninitialized memory soundly #[macro_export] -macro_rules! zero_or_uninitialized_generic { +macro_rules! unimplemented_or_uninitialized_generic { ($nrows:expr, $ncols:expr) => {{ - #[cfg(feature="no_unsound_assume_init")] { crate::base::Matrix::zeros_generic($nrows, $ncols) } + #[cfg(feature="no_unsound_assume_init")] { + // Some of the call sites need the number of rows and columns from this to infer a type, so + // uninitialized memory is used to infer the type, as `N: Zero` isn't available at all callsites. + // This may technically still be UB even though the assume_init is dead code, but all callsites should be fixed before #556 is closed. + let typeinference_helper = crate::base::Matrix::new_uninitialized_generic($nrows, $ncols); + unimplemented!(); + typeinference_helper.assume_init() + } #[cfg(not(feature="no_unsound_assume_init"))] { crate::base::Matrix::new_uninitialized_generic($nrows, $ncols).assume_init() } }} } @@ -99,10 +106,7 @@ where "Matrix init. error: the slice did not contain the right number of elements." ); - #[cfg(feature="no_unsound_assume_init")] - let mut res: Self = unimplemented!(); - #[cfg(not(feature="no_unsound_assume_init"))] - let mut res = unsafe { Self::new_uninitialized_generic(nrows, ncols).assume_init() }; + let mut res = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, ncols) }; let mut iter = slice.iter(); for i in 0..nrows.value() { @@ -128,10 +132,7 @@ where where F: FnMut(usize, usize) -> N, { - #[cfg(feature="no_unsound_assume_init")] - let mut res: Self = unimplemented!(); - #[cfg(not(feature="no_unsound_assume_init"))] - let mut res = unsafe { Self::new_uninitialized_generic(nrows, ncols).assume_init() }; + let mut res: Self = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, ncols) }; for j in 0..ncols.value() { for i in 0..nrows.value() { diff --git a/src/base/conversion.rs b/src/base/conversion.rs index 97f8ff27..e7a52d1f 100644 --- a/src/base/conversion.rs +++ b/src/base/conversion.rs @@ -50,10 +50,7 @@ where let nrows2 = R2::from_usize(nrows); let ncols2 = C2::from_usize(ncols); - #[cfg(feature="no_unsound_assume_init")] - let mut res: MatrixMN = unimplemented!(); - #[cfg(not(feature="no_unsound_assume_init"))] - let mut res = unsafe { MatrixMN::::new_uninitialized_generic(nrows2, ncols2).assume_init() }; + let mut res: MatrixMN = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows2, ncols2) }; for i in 0..nrows { for j in 0..ncols { unsafe { @@ -76,10 +73,7 @@ where let nrows = R1::from_usize(nrows2); let ncols = C1::from_usize(ncols2); - #[cfg(feature="no_unsound_assume_init")] - let mut res: Self = unimplemented!(); - #[cfg(not(feature="no_unsound_assume_init"))] - let mut res = unsafe { Self::new_uninitialized_generic(nrows, ncols).assume_init() }; + let mut res: Self = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, ncols) }; for i in 0..nrows2 { for j in 0..ncols2 { unsafe { diff --git a/src/base/edition.rs b/src/base/edition.rs index 40ac5e0e..c2a0595e 100644 --- a/src/base/edition.rs +++ b/src/base/edition.rs @@ -54,7 +54,7 @@ impl> Matrix { { let irows = irows.into_iter(); let ncols = self.data.shape().1; - let mut res = unsafe { crate::zero_or_uninitialized_generic!(Dynamic::new(irows.len()), ncols) }; + let mut res = unsafe { crate::unimplemented_or_uninitialized_generic!(Dynamic::new(irows.len()), ncols) }; // First, check that all the indices from irows are valid. // This will allow us to use unchecked access in the inner loop. @@ -89,7 +89,7 @@ impl> Matrix { let icols = icols.into_iter(); let nrows = self.data.shape().0; let mut res = - unsafe { crate::zero_or_uninitialized_generic!(nrows, Dynamic::new(icols.len())) }; + unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, Dynamic::new(icols.len())) }; for (destination, source) in icols.enumerate() { res.column_mut(destination).copy_from(&self.column(*source)) @@ -895,10 +895,7 @@ impl DMatrix { where DefaultAllocator: Reallocator, { - #[cfg(feature="no_unsound_assume_init")] - let placeholder = unimplemented!(); - #[cfg(not(feature="no_unsound_assume_init"))] - let placeholder = unsafe { Self::new_uninitialized(0, 0).assume_init() }; + let placeholder = unsafe { crate::unimplemented_or_uninitialized_generic!(Dynamic::new(0), Dynamic::new(0)) }; let old = mem::replace(self, placeholder); let new = old.resize(new_nrows, new_ncols, val); let _ = mem::replace(self, new); @@ -921,10 +918,7 @@ where where DefaultAllocator: Reallocator, { - #[cfg(feature="no_unsound_assume_init")] - let placeholder = unimplemented!(); - #[cfg(not(feature="no_unsound_assume_init"))] - let placeholder = unsafe { Self::new_uninitialized_generic(Dynamic::new(0), self.data.shape().1).assume_init() }; + let placeholder = unsafe { crate::unimplemented_or_uninitialized_generic!(Dynamic::new(0), self.data.shape().1) }; let old = mem::replace(self, placeholder); let new = old.resize_vertically(new_nrows, val); let _ = mem::replace(self, new); @@ -947,10 +941,7 @@ where where DefaultAllocator: Reallocator, { - #[cfg(feature="no_unsound_assume_init")] - let placeholder = unimplemented!(); - #[cfg(not(feature="no_unsound_assume_init"))] - let placeholder = unsafe { Self::new_uninitialized_generic(self.data.shape().0, Dynamic::new(0)).assume_init() }; + let placeholder = unsafe { crate::unimplemented_or_uninitialized_generic!(self.data.shape().0, Dynamic::new(0)) }; let old = mem::replace(self, placeholder); let new = old.resize_horizontally(new_ncols, val); let _ = mem::replace(self, new); diff --git a/src/base/matrix.rs b/src/base/matrix.rs index eb5aa316..b5fc169e 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -507,10 +507,7 @@ impl> Matrix { let nrows: SameShapeR = Dim::from_usize(nrows); let ncols: SameShapeC = Dim::from_usize(ncols); - #[cfg(feature="no_unsound_assume_init")] - let mut res: MatrixSum = unimplemented!(); - #[cfg(not(feature="no_unsound_assume_init"))] - let mut res: MatrixSum = unsafe { Matrix::new_uninitialized_generic(nrows, ncols).assume_init() }; + let mut res: MatrixSum = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, ncols) }; // TODO: use copy_from for j in 0..res.ncols() { @@ -559,10 +556,7 @@ impl> Matrix { let (nrows, ncols) = self.data.shape(); unsafe { - #[cfg(feature="no_unsound_assume_init")] - let mut res = unimplemented!(); - #[cfg(not(feature="no_unsound_assume_init"))] - let mut res = Matrix::new_uninitialized_generic(ncols, nrows).assume_init(); + let mut res = crate::unimplemented_or_uninitialized_generic!(ncols, nrows); self.transpose_to(&mut res); res @@ -580,10 +574,7 @@ impl> Matrix { { let (nrows, ncols) = self.data.shape(); - #[cfg(feature="no_unsound_assume_init")] - let mut res: MatrixMN = unimplemented!(); - #[cfg(not(feature="no_unsound_assume_init"))] - let mut res = unsafe { MatrixMN::new_uninitialized_generic(nrows, ncols).assume_init() }; + let mut res: MatrixMN = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, ncols) }; for j in 0..ncols.value() { for i in 0..nrows.value() { @@ -627,10 +618,7 @@ impl> Matrix { { let (nrows, ncols) = self.data.shape(); - #[cfg(feature="no_unsound_assume_init")] - let mut res: MatrixMN = unimplemented!(); - #[cfg(not(feature="no_unsound_assume_init"))] - let mut res = unsafe { MatrixMN::new_uninitialized_generic(nrows, ncols).assume_init() }; + let mut res: MatrixMN = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, ncols) }; for j in 0..ncols.value() { for i in 0..nrows.value() { @@ -657,10 +645,7 @@ impl> Matrix { { let (nrows, ncols) = self.data.shape(); - #[cfg(feature="no_unsound_assume_init")] - let mut res: MatrixMN = unimplemented!(); - #[cfg(not(feature="no_unsound_assume_init"))] - let mut res = unsafe { MatrixMN::new_uninitialized_generic(nrows, ncols).assume_init() }; + let mut res: MatrixMN = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, ncols) }; assert_eq!( (nrows.value(), ncols.value()), @@ -701,10 +686,7 @@ impl> Matrix { { let (nrows, ncols) = self.data.shape(); - #[cfg(feature="no_unsound_assume_init")] - let mut res: MatrixMN = unimplemented!(); - #[cfg(not(feature="no_unsound_assume_init"))] - let mut res = unsafe { MatrixMN::new_uninitialized_generic(nrows, ncols).assume_init() }; + let mut res: MatrixMN = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, ncols) }; assert_eq!( (nrows.value(), ncols.value()), @@ -1198,10 +1180,7 @@ impl> Matrix = Matrix::new_uninitialized_generic(ncols, nrows).assume_init(); + let mut res: MatrixMN<_, C, R> = crate::unimplemented_or_uninitialized_generic!(ncols, nrows); self.adjoint_to(&mut res); res @@ -1342,10 +1321,7 @@ impl> SquareMatrix { ); let dim = self.data.shape().0; - #[cfg(feature="no_unsound_assume_init")] - let mut res: VectorN = unimplemented!(); - #[cfg(not(feature="no_unsound_assume_init"))] - let mut res = unsafe { VectorN::new_uninitialized_generic(dim, U1).assume_init() }; + let mut res: VectorN = unsafe { crate::unimplemented_or_uninitialized_generic!(dim, U1) }; for i in 0..dim.value() { unsafe { @@ -1472,7 +1448,7 @@ impl, S: Storage> Vector { { let len = self.len(); let hnrows = DimSum::::from_usize(len + 1); - let mut res: VectorN:: = unsafe { crate::zero_or_uninitialized_generic!(hnrows, U1) }; + let mut res: VectorN:: = unsafe { crate::unimplemented_or_uninitialized_generic!(hnrows, U1) }; res.generic_slice_mut((0, 0), self.data.shape()) .copy_from(self); res[(len, 0)] = element; @@ -1817,10 +1793,7 @@ impl::from_usize(3); let ncols = SameShapeC::::from_usize(1); - #[cfg(feature="no_unsound_assume_init")] - let mut res: MatrixCross = unimplemented!(); - #[cfg(not(feature="no_unsound_assume_init"))] - let mut res = Matrix::new_uninitialized_generic(nrows, ncols).assume_init(); + let mut res: MatrixCross = crate::unimplemented_or_uninitialized_generic!(nrows, ncols); let ax = self.get_unchecked((0, 0)); let ay = self.get_unchecked((1, 0)); @@ -1844,10 +1817,7 @@ impl::from_usize(1); let ncols = SameShapeC::::from_usize(3); - #[cfg(feature="no_unsound_assume_init")] - let mut res: MatrixCross = unimplemented!(); - #[cfg(not(feature="no_unsound_assume_init"))] - let mut res = Matrix::new_uninitialized_generic(nrows, ncols).assume_init(); + let mut res: MatrixCross = crate::unimplemented_or_uninitialized_generic!(nrows, ncols); let ax = self.get_unchecked((0, 0)); let ay = self.get_unchecked((0, 1)); diff --git a/src/base/ops.rs b/src/base/ops.rs index 37d18827..93ca3b8e 100644 --- a/src/base/ops.rs +++ b/src/base/ops.rs @@ -331,10 +331,7 @@ macro_rules! componentwise_binop_impl( let (nrows, ncols) = self.shape(); let nrows: SameShapeR = Dim::from_usize(nrows); let ncols: SameShapeC = Dim::from_usize(ncols); - #[cfg(feature="no_unsound_assume_init")] - { unimplemented!() } - #[cfg(not(feature="no_unsound_assume_init"))] - { Matrix::new_uninitialized_generic(nrows, ncols).assume_init() } + crate::unimplemented_or_uninitialized_generic!(nrows, ncols) }; self.$method_to_statically_unchecked(rhs, &mut res); @@ -576,7 +573,7 @@ where #[inline] fn mul(self, rhs: &'b Matrix) -> Self::Output { - let mut res = unsafe { crate::zero_or_uninitialized_generic!(self.data.shape().0, rhs.data.shape().1) }; + let mut res = unsafe { crate::unimplemented_or_uninitialized_generic!(self.data.shape().0, rhs.data.shape().1) }; self.mul_to(rhs, &mut res); res } @@ -685,7 +682,7 @@ where DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows, { - let mut res = unsafe { crate::zero_or_uninitialized_generic!(self.data.shape().1, rhs.data.shape().1) }; + let mut res = unsafe { crate::unimplemented_or_uninitialized_generic!(self.data.shape().1, rhs.data.shape().1) }; self.tr_mul_to(rhs, &mut res); res @@ -700,7 +697,7 @@ where DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows, { - let mut res = unsafe { crate::zero_or_uninitialized_generic!(self.data.shape().1, rhs.data.shape().1) }; + let mut res = unsafe { crate::unimplemented_or_uninitialized_generic!(self.data.shape().1, rhs.data.shape().1) }; self.ad_mul_to(rhs, &mut res); res @@ -814,7 +811,7 @@ where let (nrows1, ncols1) = self.data.shape(); let (nrows2, ncols2) = rhs.data.shape(); - let mut res = unsafe { crate::zero_or_uninitialized_generic!(nrows1.mul(nrows2), ncols1.mul(ncols2)) }; + let mut res = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows1.mul(nrows2), ncols1.mul(ncols2)) }; { let mut data_res = res.data.ptr_mut(); diff --git a/src/base/statistics.rs b/src/base/statistics.rs index 6ac826bf..7ee5a9c9 100644 --- a/src/base/statistics.rs +++ b/src/base/statistics.rs @@ -17,10 +17,7 @@ impl> Matrix { DefaultAllocator: Allocator, { let ncols = self.data.shape().1; - #[cfg(feature="no_unsound_assume_init")] - let mut res: RowVectorN = unimplemented!(); - #[cfg(not(feature="no_unsound_assume_init"))] - let mut res = unsafe { RowVectorN::new_uninitialized_generic(U1, ncols).assume_init() }; + let mut res: RowVectorN = unsafe { crate::unimplemented_or_uninitialized_generic!(U1, ncols) }; for i in 0..ncols.value() { // TODO: avoid bound checking of column. @@ -45,10 +42,7 @@ impl> Matrix { DefaultAllocator: Allocator, { let ncols = self.data.shape().1; - #[cfg(feature="no_unsound_assume_init")] - let mut res: VectorN = unimplemented!(); - #[cfg(not(feature="no_unsound_assume_init"))] - let mut res = unsafe { VectorN::new_uninitialized_generic(ncols, U1).assume_init() }; + let mut res: VectorN = unsafe { crate::unimplemented_or_uninitialized_generic!(ncols, U1) }; for i in 0..ncols.value() { // TODO: avoid bound checking of column. diff --git a/src/geometry/point.rs b/src/geometry/point.rs index f5151d9a..d668e804 100644 --- a/src/geometry/point.rs +++ b/src/geometry/point.rs @@ -181,10 +181,7 @@ where D: DimNameAdd, DefaultAllocator: Allocator>, { - #[cfg(feature="no_unsound_assume_init")] - let mut res: VectorN> = unimplemented!(); - #[cfg(not(feature="no_unsound_assume_init"))] - let mut res = unsafe { VectorN::<_, DimNameSum>::new_uninitialized().assume_init() }; + let mut res = unsafe { crate::unimplemented_or_uninitialized_generic!( as DimName>::name(), U1) }; res.fixed_slice_mut::(0, 0).copy_from(&self.coords); res[(D::dim(), 0)] = N::one(); diff --git a/src/geometry/point_construction.rs b/src/geometry/point_construction.rs index ddf453dd..48c4a71c 100644 --- a/src/geometry/point_construction.rs +++ b/src/geometry/point_construction.rs @@ -24,10 +24,7 @@ where /// Creates a new point with uninitialized coordinates. #[inline] pub unsafe fn new_uninitialized() -> Self { - #[cfg(feature="no_unsound_assume_init")] - { unimplemented!() } - #[cfg(not(feature="no_unsound_assume_init"))] - { Self::from(VectorN::new_uninitialized().assume_init()) } + Self::from(crate::unimplemented_or_uninitialized_generic!(D::name(), U1)) } /// Creates a new point with all coordinates equal to zero. diff --git a/src/linalg/bidiagonal.rs b/src/linalg/bidiagonal.rs index 66957251..0202eb68 100644 --- a/src/linalg/bidiagonal.rs +++ b/src/linalg/bidiagonal.rs @@ -81,11 +81,11 @@ where "Cannot compute the bidiagonalization of an empty matrix." ); - let mut diagonal = unsafe { crate::zero_or_uninitialized_generic!(min_nrows_ncols, U1) }; + let mut diagonal = unsafe { crate::unimplemented_or_uninitialized_generic!(min_nrows_ncols, U1) }; let mut off_diagonal = - unsafe { crate::zero_or_uninitialized_generic!(min_nrows_ncols.sub(U1), U1) }; - let mut axis_packed = unsafe { crate::zero_or_uninitialized_generic!(ncols, U1) }; - let mut work = unsafe { crate::zero_or_uninitialized_generic!(nrows, U1) }; + unsafe { crate::unimplemented_or_uninitialized_generic!(min_nrows_ncols.sub(U1), U1) }; + let mut axis_packed = unsafe { crate::unimplemented_or_uninitialized_generic!(ncols, U1) }; + let mut work = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, U1) }; let upper_diagonal = nrows.value() >= ncols.value(); if upper_diagonal { @@ -239,8 +239,8 @@ where let min_nrows_ncols = nrows.min(ncols); let mut res = Matrix::identity_generic(min_nrows_ncols, ncols); - let mut work = unsafe { crate::zero_or_uninitialized_generic!(min_nrows_ncols, U1) }; - let mut axis_packed = unsafe { crate::zero_or_uninitialized_generic!(ncols, U1) }; + let mut work = unsafe { crate::unimplemented_or_uninitialized_generic!(min_nrows_ncols, U1) }; + let mut axis_packed = unsafe { crate::unimplemented_or_uninitialized_generic!(ncols, U1) }; let shift = self.axis_shift().1; diff --git a/src/linalg/cholesky.rs b/src/linalg/cholesky.rs index 134c9aa3..a6757b08 100644 --- a/src/linalg/cholesky.rs +++ b/src/linalg/cholesky.rs @@ -223,7 +223,7 @@ where // loads the data into a new matrix with an additional jth row/column let mut chol = unsafe { - crate::zero_or_uninitialized_generic!( + crate::unimplemented_or_uninitialized_generic!( self.chol.data.shape().0.add(U1), self.chol.data.shape().1.add(U1) ) @@ -288,7 +288,7 @@ where // loads the data into a new matrix except for the jth row/column let mut chol = unsafe { - crate::zero_or_uninitialized_generic!( + crate::unimplemented_or_uninitialized_generic!( self.chol.data.shape().0.sub(U1), self.chol.data.shape().1.sub(U1) ) diff --git a/src/linalg/hessenberg.rs b/src/linalg/hessenberg.rs index 979ddfd8..c6103ffd 100644 --- a/src/linalg/hessenberg.rs +++ b/src/linalg/hessenberg.rs @@ -48,7 +48,7 @@ where { /// Computes the Hessenberg decomposition using householder reflections. pub fn new(hess: MatrixN) -> Self { - let mut work = unsafe { crate::zero_or_uninitialized_generic!(hess.data.shape().0, U1) }; + let mut work = unsafe { crate::unimplemented_or_uninitialized_generic!(hess.data.shape().0, U1) }; Self::new_with_workspace(hess, &mut work) } @@ -74,7 +74,7 @@ where "Hessenberg: invalid workspace size." ); - let mut subdiag = unsafe { crate::zero_or_uninitialized_generic!(dim.sub(U1), U1) }; + let mut subdiag = unsafe { crate::unimplemented_or_uninitialized_generic!(dim.sub(U1), U1) }; if dim.value() == 0 { return Hessenberg { hess, subdiag }; diff --git a/src/linalg/permutation_sequence.rs b/src/linalg/permutation_sequence.rs index 75dae37d..dd389188 100644 --- a/src/linalg/permutation_sequence.rs +++ b/src/linalg/permutation_sequence.rs @@ -70,12 +70,9 @@ where #[inline] pub fn identity_generic(dim: D) -> Self { unsafe { - #[cfg(feature="no_unsound_assume_init")] - unimplemented!(); - #[cfg(not(feature="no_unsound_assume_init"))] Self { len: 0, - ipiv: VectorN::new_uninitialized_generic(dim, U1).assume_init(), + ipiv: crate::unimplemented_or_uninitialized_generic!(dim, U1), } } } diff --git a/src/linalg/qr.rs b/src/linalg/qr.rs index 191ccfbe..063cad0d 100644 --- a/src/linalg/qr.rs +++ b/src/linalg/qr.rs @@ -54,7 +54,7 @@ where let (nrows, ncols) = matrix.data.shape(); let min_nrows_ncols = nrows.min(ncols); - let mut diag = unsafe { crate::zero_or_uninitialized_generic!(min_nrows_ncols, U1) }; + let mut diag = unsafe { crate::unimplemented_or_uninitialized_generic!(min_nrows_ncols, U1) }; if min_nrows_ncols.value() == 0 { return QR { qr: matrix, diag }; diff --git a/src/linalg/schur.rs b/src/linalg/schur.rs index b9229047..820c0e21 100644 --- a/src/linalg/schur.rs +++ b/src/linalg/schur.rs @@ -71,7 +71,7 @@ where /// number of iteration is exceeded, `None` is returned. If `niter == 0`, then the algorithm /// continues indefinitely until convergence. pub fn try_new(m: MatrixN, eps: N::RealField, max_niter: usize) -> Option { - let mut work = unsafe { crate::zero_or_uninitialized_generic!(m.data.shape().0, U1) }; + let mut work = unsafe { crate::unimplemented_or_uninitialized_generic!(m.data.shape().0, U1) }; Self::do_decompose(m, &mut work, eps, max_niter, true) .map(|(q, t)| Schur { q: q.unwrap(), t }) @@ -378,7 +378,7 @@ where /// /// Return `None` if some eigenvalues are complex. pub fn eigenvalues(&self) -> Option> { - let mut out = unsafe { crate::zero_or_uninitialized_generic!(self.t.data.shape().0, U1) }; + let mut out = unsafe { crate::unimplemented_or_uninitialized_generic!(self.t.data.shape().0, U1) }; if Self::do_eigenvalues(&self.t, &mut out) { Some(out) } else { @@ -392,7 +392,7 @@ where N: RealField, DefaultAllocator: Allocator, D>, { - let mut out = unsafe { crate::zero_or_uninitialized_generic!(self.t.data.shape().0, U1) }; + let mut out = unsafe { crate::unimplemented_or_uninitialized_generic!(self.t.data.shape().0, U1) }; Self::do_complex_eigenvalues(&self.t, &mut out); out } @@ -503,7 +503,7 @@ where "Unable to compute eigenvalues of a non-square matrix." ); - let mut work = unsafe { crate::zero_or_uninitialized_generic!(self.data.shape().0, U1) }; + let mut work = unsafe { crate::unimplemented_or_uninitialized_generic!(self.data.shape().0, U1) }; // Special case for 2x2 matrices. if self.nrows() == 2 { @@ -544,7 +544,7 @@ where DefaultAllocator: Allocator, D>, { let dim = self.data.shape().0; - let mut work = unsafe { crate::zero_or_uninitialized_generic!(dim, U1) }; + let mut work = unsafe { crate::unimplemented_or_uninitialized_generic!(dim, U1) }; let schur = Schur::do_decompose( self.clone_owned(), @@ -554,7 +554,7 @@ where false, ) .unwrap(); - let mut eig = unsafe { crate::zero_or_uninitialized_generic!(dim, U1) }; + let mut eig = unsafe { crate::unimplemented_or_uninitialized_generic!(dim, U1) }; Schur::do_complex_eigenvalues(&schur.1, &mut eig); eig } diff --git a/src/linalg/symmetric_tridiagonal.rs b/src/linalg/symmetric_tridiagonal.rs index c34a60da..ba47724e 100644 --- a/src/linalg/symmetric_tridiagonal.rs +++ b/src/linalg/symmetric_tridiagonal.rs @@ -61,8 +61,8 @@ where "Unable to compute the symmetric tridiagonal decomposition of an empty matrix." ); - let mut off_diagonal = unsafe { crate::zero_or_uninitialized_generic!(dim.sub(U1), U1) }; - let mut p = unsafe { crate::zero_or_uninitialized_generic!(dim.sub(U1), U1) }; + let mut off_diagonal = unsafe { crate::unimplemented_or_uninitialized_generic!(dim.sub(U1), U1) }; + let mut p = unsafe { crate::unimplemented_or_uninitialized_generic!(dim.sub(U1), U1) }; for i in 0..dim.value() - 1 { let mut m = m.rows_range_mut(i + 1..);