Skip to content

Commit 3207564

Browse files
Merge #333 #334
333: Remove remaining debug_assert calls r=samueltardieu a=samueltardieu 334: Remove unused uninit/assume_init on Matrix r=samueltardieu a=samueltardieu The `Vec<C>` and `Vec<MaybeUninit<C>>` don't have any long-term guarantee of having the same in-memory representation. Co-authored-by: Samuel Tardieu <[email protected]>
3 parents 0b44f86 + 0b6d16c + 5d57d46 commit 3207564

File tree

3 files changed

+0
-52
lines changed

3 files changed

+0
-52
lines changed

src/kuhn_munkres.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ where
128128
y = yy;
129129
}
130130
}
131-
debug_assert!(s.contains(x));
132131
// If some slack has been found, remove it from x nodes in the
133132
// alternating path, and add it to y nodes in the alternating path.
134133
// The slack of y nodes outside the alternating path will be reduced
@@ -145,7 +144,6 @@ where
145144
}
146145
}
147146
}
148-
debug_assert!(lx[x] + ly[y] == weights.at(x, y));
149147
// Add (x, y) to the alternating path.
150148
alternating[y] = Some(x);
151149
if yx[y].is_none() {
@@ -155,7 +153,6 @@ where
155153
// This y node had a predecessor, add it to the set of x nodes
156154
// in the augmenting path.
157155
let x = yx[y].unwrap();
158-
debug_assert!(!s.contains(x));
159156
s.insert(x);
160157
// Update slack because of the added vertex in s might contain a
161158
// greater slack than with previously inserted x nodes in the augmenting

src/matrix.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use itertools::Itertools;
88
use num_traits::Signed;
99
use std::collections::BTreeSet;
1010
use std::iter::FusedIterator;
11-
use std::mem::MaybeUninit;
1211
use std::ops::{Deref, DerefMut, Index, IndexMut, Neg, Range};
1312
use std::slice::{Iter, IterMut};
1413
use thiserror::Error;
@@ -232,20 +231,6 @@ impl<C> Matrix<C> {
232231
})
233232
}
234233

235-
/// Construct a new Matrix with uninitialized content.
236-
pub fn new_uninit(rows: usize, columns: usize) -> Matrix<MaybeUninit<C>> {
237-
let data_len = rows * columns;
238-
let mut data = Vec::with_capacity(data_len);
239-
unsafe {
240-
data.set_len(data_len);
241-
}
242-
Matrix {
243-
rows,
244-
columns,
245-
data,
246-
}
247-
}
248-
249234
/// Create new square matrix from vector values. The first value
250235
/// will be assigned to index (0, 0), the second one to index (0, 1),
251236
/// and so on. An error is returned if the number of values is not a
@@ -636,23 +621,6 @@ impl<C> Matrix<C> {
636621
}
637622
}
638623

639-
impl<C> Matrix<MaybeUninit<C>> {
640-
/// Convert to `Matrix<C>`.
641-
///
642-
/// # Safety
643-
///
644-
/// As with [`MaybeUninit::assume_init()`], it is up to the caller to guarantee
645-
/// that the value really is in an initialized state. Calling this when the content
646-
/// is not yet fully initialized causes immediate undefined behavior.
647-
pub unsafe fn assume_init(self) -> Matrix<C> {
648-
Matrix {
649-
rows: self.rows,
650-
columns: self.columns,
651-
data: std::mem::transmute(self.data),
652-
}
653-
}
654-
}
655-
656624
impl<C> Index<(usize, usize)> for Matrix<C> {
657625
type Output = C;
658626

tests/matrix.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -574,23 +574,6 @@ fn in_direction() {
574574
);
575575
}
576576

577-
#[test]
578-
fn uninit() {
579-
struct NonClonable(usize);
580-
let mut mat = Matrix::<NonClonable>::new_uninit(3, 3);
581-
for row in 0..mat.rows {
582-
for column in 0..mat.columns {
583-
mat[(row, column)].write(NonClonable(3 * row + column));
584-
}
585-
}
586-
let mat = unsafe { mat.assume_init() };
587-
for row in 0..mat.rows {
588-
for column in 0..mat.columns {
589-
assert_eq!(mat[(row, column)].0, row * 3 + column);
590-
}
591-
}
592-
}
593-
594577
#[test]
595578
fn map() {
596579
let m = Matrix::new(3, 3, 10);

0 commit comments

Comments
 (0)