Skip to content

Commit

Permalink
switch from assert2 to equator
Browse files Browse the repository at this point in the history
  • Loading branch information
sarah committed Nov 30, 2023
1 parent d106907 commit 6a882d5
Show file tree
Hide file tree
Showing 27 changed files with 695 additions and 303 deletions.
1 change: 1 addition & 0 deletions faer-libs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ bytemuck = { version = "1", default-features = false }
rand = { version = "0.8", default-features = false }
rayon = "1"
assert2 = "0.3"
equator = "0.1.5"
log = { version = "0.4", default-features = false }

criterion = { git = "https://github.com/sarah-ek/criterion.rs" }
Expand Down
24 changes: 14 additions & 10 deletions faer-libs/faer-cholesky/src/bunch_kaufman/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,11 +785,13 @@ pub mod compute {
let mut regularization = regularization;

let n = matrix.nrows();
assert!(matrix.nrows() == matrix.ncols());
assert!(subdiag.nrows() == n);
assert!(subdiag.ncols() == 1);
assert!(perm.len() == n);
assert!(perm_inv.len() == n);
assert!(all(
matrix.nrows() == matrix.ncols(),
subdiag.nrows() == n,
subdiag.ncols() == 1,
perm.len() == n,
perm_inv.len() == n
));

#[cfg(feature = "perf-warn")]
if matrix.row_stride().unsigned_abs() != 1 && faer_core::__perf_warn!(CHOLESKY_WARN) {
Expand Down Expand Up @@ -922,11 +924,13 @@ pub mod solve {
let n = lb_factors.nrows();
let k = rhs.ncols();

assert!(lb_factors.nrows() == lb_factors.ncols());
assert!(rhs.nrows() == n);
assert!(subdiag.nrows() == n);
assert!(subdiag.ncols() == 1);
assert!(perm.len() == n);
assert!(all(
lb_factors.nrows() == lb_factors.ncols(),
rhs.nrows() == n,
subdiag.nrows() == n,
subdiag.ncols() == 1,
perm.len() == n
));

let a = lb_factors;
let par = parallelism;
Expand Down
6 changes: 4 additions & 2 deletions faer-libs/faer-cholesky/src/ldlt_diagonal/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ pub fn solve_in_place_with_conj<E: ComplexField>(
let k = rhs.ncols();
let _ = &stack;

assert!(cholesky_factors.nrows() == cholesky_factors.ncols());
assert!(rhs.nrows() == n);
assert!(all(
cholesky_factors.nrows() == cholesky_factors.ncols(),
rhs.nrows() == n,
));

let mut rhs = rhs;

Expand Down
7 changes: 5 additions & 2 deletions faer-libs/faer-cholesky/src/llt/inverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ pub fn invert_lower<E: ComplexField>(
parallelism: Parallelism,
stack: PodStack,
) {
assert!(cholesky_factor.nrows() == cholesky_factor.ncols());
assert!((dst.nrows(), dst.ncols()) == (cholesky_factor.nrows(), cholesky_factor.ncols()));
assert!(all(
cholesky_factor.nrows() == cholesky_factor.ncols(),
dst.nrows() == cholesky_factor.nrows(),
dst.ncols() == cholesky_factor.ncols(),
));
invert_lower_impl(dst, Some(cholesky_factor), parallelism, stack);
}
6 changes: 4 additions & 2 deletions faer-libs/faer-cholesky/src/llt/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ pub fn solve_in_place_with_conj<E: ComplexField>(
let _ = &stack;
let n = cholesky_factor.nrows();

assert!(cholesky_factor.nrows() == cholesky_factor.ncols());
assert!(rhs.nrows() == n);
assert!(all(
cholesky_factor.nrows() == cholesky_factor.ncols(),
rhs.nrows() == n,
));

let mut rhs = rhs;

Expand Down
3 changes: 1 addition & 2 deletions faer-libs/faer-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bytemuck = { workspace = true }

rand = { workspace = true, optional = true, default-features = false }
rayon = { workspace = true, optional = true }
assert2 = { workspace = true, optional = true }
equator = { workspace = true }
log = { workspace = true, optional = true, default-features = false }
matrixcompare-core = { version = "0.1.0", optional = true }

Expand All @@ -39,7 +39,6 @@ std = [
"faer-entity/std",
"gemm/std",
"pulp/std",
"assert2",
"matrixcompare-core",
]
rayon = [
Expand Down
23 changes: 14 additions & 9 deletions faer-libs/faer-core/src/householder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
//! documentation of the QR module.

use crate::{
assert,
group_helpers::*,
join_raw,
mul::{
Expand All @@ -38,8 +39,6 @@ use crate::{
solve, temp_mat_req, temp_mat_uninit, unzipped, zipped, ComplexField, Conj, DivCeil, Entity,
MatMut, MatRef, Parallelism,
};
#[cfg(feature = "std")]
use assert2::assert;
use dyn_stack::{PodStack, SizeOverflow, StackReq};
use faer_entity::*;
use num_complex::Complex;
Expand Down Expand Up @@ -160,8 +159,10 @@ pub fn upgrade_householder_factor<E: ComplexField>(
let block_count = householder_factor.nrows().msrv_div_ceil(blocksize);

if block_count > 1 {
assert!(blocksize > prev_blocksize);
assert!(blocksize % prev_blocksize == 0);
assert!(all(
blocksize > prev_blocksize,
blocksize % prev_blocksize == 0,
));
let idx = (block_count / 2) * blocksize;
let (tau_tl, _, _, tau_br) = householder_factor.split_at_mut(idx, idx);
let (basis_left, basis_right) = essentials.split_at_col(idx);
Expand Down Expand Up @@ -379,9 +380,11 @@ fn apply_block_householder_on_the_left_in_place_generic<E: ComplexField>(
parallelism: Parallelism,
stack: PodStack<'_>,
) {
assert!(householder_factor.nrows() == householder_factor.ncols());
assert!(householder_basis.ncols() == householder_factor.nrows());
assert!(matrix.nrows() == householder_basis.nrows());
assert!(all(
householder_factor.nrows() == householder_factor.ncols(),
householder_basis.ncols() == householder_factor.nrows(),
matrix.nrows() == householder_basis.nrows(),
));

let bs = householder_factor.nrows();
if householder_basis.row_stride() == 1 && matrix.row_stride() == 1 && bs == 1 {
Expand Down Expand Up @@ -746,8 +749,10 @@ pub fn apply_block_householder_sequence_transpose_on_the_left_in_place_with_conj
let mut matrix = matrix;
let mut stack = stack;
let blocksize = householder_factor.nrows();
assert!(blocksize > 0);
assert!(matrix.nrows() == householder_basis.nrows());
assert!(all(
blocksize > 0,
matrix.nrows() == householder_basis.nrows()
));
let m = householder_basis.nrows();
let k = matrix.ncols();

Expand Down
23 changes: 12 additions & 11 deletions faer-libs/faer-core/src/inverse.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
//! Triangular matrix inversion.

use crate::{
join_raw,
assert, join_raw,
mul::triangular::{self, BlockStructure},
solve, ComplexField, MatMut, MatRef, Parallelism,
};
#[cfg(feature = "std")]
use assert2::assert;
use reborrow::*;

unsafe fn invert_lower_triangular_impl_small<E: ComplexField>(
Expand Down Expand Up @@ -141,9 +139,11 @@ pub fn invert_unit_lower_triangular<E: ComplexField>(
src: MatRef<'_, E>,
parallelism: Parallelism,
) {
assert!(dst.nrows() == src.nrows());
assert!(dst.ncols() == src.ncols());
assert!(dst.nrows() == dst.ncols());
assert!(all(
dst.nrows() == src.nrows(),
dst.ncols() == src.ncols(),
dst.nrows() == dst.ncols()
));

unsafe { invert_unit_lower_triangular_impl(dst, src, parallelism) }
}
Expand All @@ -160,9 +160,11 @@ pub fn invert_lower_triangular<E: ComplexField>(
src: MatRef<'_, E>,
parallelism: Parallelism,
) {
assert!(dst.nrows() == src.nrows());
assert!(dst.ncols() == src.ncols());
assert!(dst.nrows() == dst.ncols());
assert!(all(
dst.nrows() == src.nrows(),
dst.ncols() == src.ncols(),
dst.nrows() == dst.ncols()
));

unsafe { invert_lower_triangular_impl(dst, src, parallelism) }
}
Expand Down Expand Up @@ -208,8 +210,7 @@ pub fn invert_upper_triangular<E: ComplexField>(
#[cfg(test)]
mod tests {
use super::*;
use crate::Mat;
use assert2::assert;
use crate::{assert, Mat};
use assert_approx_eq::assert_approx_eq;
use rand::random;

Expand Down
6 changes: 2 additions & 4 deletions faer-libs/faer-core/src/jacobi.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{group_helpers::*, unzipped, zipped, MatMut, RealField};
use crate::{assert, group_helpers::*, unzipped, zipped, MatMut, RealField};
use faer_entity::{SimdCtx, SimdGroupFor};
use reborrow::*;

Expand Down Expand Up @@ -132,9 +132,7 @@ impl<E: RealField> JacobiRotation<E> {
#[inline(always)]
fn with_simd<S: pulp::Simd>(self, simd: S) -> Self::Output {
let Self { x, y, c, s } = self;
assert!(x.nrows() == 1);
assert!(y.nrows() == 1);
assert_eq!(x.ncols(), y.ncols());
assert!(all(x.nrows() == 1, y.nrows() == 1, x.ncols() == y.ncols()));

if c == E::faer_one() && s == E::faer_zero() {
return;
Expand Down
Loading

0 comments on commit 6a882d5

Please sign in to comment.