Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions benches/common/angle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

//! Independently checked fixtures shared by angle benchmarks and their tests.

use core::array::from_fn;
use core::f64::consts::{FRAC_PI_2, FRAC_PI_4, PI};

use la_stack::{Vector, VectorAngle};
Expand Down Expand Up @@ -104,8 +105,8 @@ pub(crate) fn fixtures<const D: usize>() -> [AngleInput<D>; 14] {
let alternating_reference = (4.0 * (support - 1.0)).sqrt().atan2(support - 2.0);
// Deterministic varied dense coordinates, independently evaluated with
// integer Gram products (no production minor or compensated reduction).
let dense_left = core::array::from_fn(|i| i32::try_from(i + 1).or_abort("small dimension"));
let dense_varied = core::array::from_fn(|i| {
let dense_left = from_fn(|i| i32::try_from(i + 1).or_abort("small dimension"));
let dense_varied = from_fn(|i| {
i32::try_from(D - i).or_abort("small dimension") * if i % 2 == 0 { 1 } else { -1 }
});
let dot: i32 = dense_left
Expand Down
3 changes: 2 additions & 1 deletion benches/common/interval_solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

use std::array::from_fn;

use super::bench_utils::OrAbort;
use la_stack::{ArithmeticOperation, Interval, IntervalMatrix, LaError};

use super::bench_utils::OrAbort;

pub(crate) const CASES: usize = 32;

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
Expand Down
3 changes: 1 addition & 2 deletions benches/exact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ use std::hint::black_box;

use criterion::{BenchmarkGroup, Criterion, Throughput, measurement::WallTime};

use la_stack::ExactF64Conversion;
use la_stack::{Matrix, Vector};
use la_stack::{ExactF64Conversion, Matrix, Vector};

#[path = "common/bench_utils.rs"]
mod bench_utils;
Expand Down
5 changes: 3 additions & 2 deletions benches/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

//! Criterion coverage for conclusive and inconclusive interval determinants.

use core::array::from_fn;
use std::hint::black_box;

use criterion::Criterion;
Expand Down Expand Up @@ -108,8 +109,8 @@ fn dimension_benchmarks<const N: usize>(criterion: &mut Criterion) {
);
// I + 11ᵀ has determinant N+1. Widen a repeated row to obtain an
// inconclusive dense enclosure that still includes a singular matrix.
let dense_rows = core::array::from_fn(|row| {
core::array::from_fn(|column| {
let dense_rows = from_fn(|row| {
from_fn(|column| {
if row == column {
Interval::point(2.0).or_abort("dense diagonal")
} else {
Expand Down
3 changes: 2 additions & 1 deletion benches/interval_solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

//! Criterion diagnostics for interval reciprocal, division, and solution enclosures.

use std::hint::black_box;

use criterion::Criterion;
use la_stack::Interval;
use std::hint::black_box;

#[path = "common/bench_utils.rs"]
mod bench_utils;
Expand Down
3 changes: 1 addition & 2 deletions benches/public_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

use std::hint::black_box;

use criterion::measurement::WallTime;
use criterion::{BenchmarkGroup, Criterion};
use criterion::{BenchmarkGroup, Criterion, measurement::WallTime};
use la_stack::{Interval, IntervalMatrix, Matrix, Tolerance, Vector};

#[path = "common/bench_utils.rs"]
Expand Down
3 changes: 2 additions & 1 deletion benches/rational_solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

//! Focused structure-sensitive exact solve measurements, outside release reports.

use criterion::Criterion;
use std::hint::black_box;

use criterion::Criterion;

#[path = "common/bench_utils.rs"]
mod bench_utils;
#[path = "common/rational_solve.rs"]
Expand Down
16 changes: 7 additions & 9 deletions benches/vs_linalg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
//! - Matrix infinity norm is the maximum absolute row sum on all sides.
//! - Euclidean-norm rows include safe reference kernels as well as peer crates.

use std::hint::black_box;
use std::{array::from_fn, hint::black_box};

use criterion::measurement::WallTime;
use criterion::{BenchmarkGroup, Criterion};
use criterion::{BenchmarkGroup, Criterion, measurement::WallTime};
use faer::linalg::matmul::dot::inner_prod;
use faer::linalg::solvers::Solve;
use faer::mat::AsMatRef;
Expand All @@ -29,12 +28,11 @@ mod bench_utils;
pub mod vs_linalg_common;

use bench_utils::OrAbort;
use vs_linalg_common::norm_scenarios;
use vs_linalg_common::{LuSolveScenario, validated_lu_solve_input};
use vs_linalg_common::{
PreparedFaerLuDet, delaunay_scaled_norm, faer_det_from_ldlt, iterative_hypot,
LuSolveScenario, PreparedFaerLuDet, delaunay_scaled_norm, faer_det_from_ldlt, iterative_hypot,
make_balanced_dynamic_range_rows, make_ill_conditioned_matrix_rows, make_matrix_rows,
make_pivoting_matrix_rows, make_vector_array, matrix_entry, nalgebra_inf_norm, vector_entry,
make_pivoting_matrix_rows, make_vector_array, matrix_entry, nalgebra_inf_norm, norm_scenarios,
validated_lu_solve_input, vector_entry,
};

/// Build the deterministic la-stack matrix shared by a benchmark family.
Expand Down Expand Up @@ -671,12 +669,12 @@ where
let nrhs = SVector::<f64, D>::from_fn(|i, _| rhs.as_array()[i]);
let nlu = na.lu();
let nx = nlu.solve(&nrhs).or_abort("diagnostic nalgebra solve");
input.validate_solution(&std::array::from_fn(|i| nx[i]));
input.validate_solution(&from_fn(|i| nx[i]));
let fa = Mat::from_fn(D, D, |i, j| a.as_rows()[i][j]);
let frhs = Mat::from_fn(D, 1, |i, _| rhs.as_array()[i]);
let flu = fa.partial_piv_lu();
let fx = flu.solve(&frhs);
input.validate_solution(&std::array::from_fn(|i| fx[(i, 0)]));
input.validate_solution(&from_fn(|i| fx[(i, 0)]));

let mut group = c.benchmark_group(format!("lu_solve_{}_d{D}", scenario.name()));
group.bench_function("la_stack_lu_solve", |b| {
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ macro_rules! try_with_stack_matrix {
5 => $crate::try_with_stack_matrix!(@arm 5, $matrix, $ret, $body),
6 => $crate::try_with_stack_matrix!(@arm 6, $matrix, $ret, $body),
7 => $crate::try_with_stack_matrix!(@arm 7, $matrix, $ret, $body),
requested => Err(::core::convert::From::from(
requested => ::core::result::Result::Err(::core::convert::From::from(
$crate::LaError::unsupported_dimension(
requested,
$crate::MAX_STACK_MATRIX_DISPATCH_DIM,
Expand All @@ -1272,7 +1272,7 @@ macro_rules! try_with_stack_matrix {
5 => $crate::try_with_stack_matrix!(@arm_mut 5, $matrix, $ret, $body),
6 => $crate::try_with_stack_matrix!(@arm_mut 6, $matrix, $ret, $body),
7 => $crate::try_with_stack_matrix!(@arm_mut 7, $matrix, $ret, $body),
requested => Err(::core::convert::From::from(
requested => ::core::result::Result::Err(::core::convert::From::from(
$crate::LaError::unsupported_dimension(
requested,
$crate::MAX_STACK_MATRIX_DISPATCH_DIM,
Expand Down Expand Up @@ -1337,7 +1337,7 @@ macro_rules! try_with_interval_matrix {
5 => $crate::try_with_interval_matrix!(@arm 5, $matrix, $ret, $body),
6 => $crate::try_with_interval_matrix!(@arm 6, $matrix, $ret, $body),
7 => $crate::try_with_interval_matrix!(@arm 7, $matrix, $ret, $body),
requested => Err(::core::convert::From::from(
requested => ::core::result::Result::Err(::core::convert::From::from(
$crate::LaError::unsupported_dimension(
requested,
$crate::MAX_INTERVAL_MATRIX_DIM,
Expand All @@ -1356,7 +1356,7 @@ macro_rules! try_with_interval_matrix {
5 => $crate::try_with_interval_matrix!(@arm_mut 5, $matrix, $ret, $body),
6 => $crate::try_with_interval_matrix!(@arm_mut 6, $matrix, $ret, $body),
7 => $crate::try_with_interval_matrix!(@arm_mut 7, $matrix, $ret, $body),
requested => Err(::core::convert::From::from(
requested => ::core::result::Result::Err(::core::convert::From::from(
$crate::LaError::unsupported_dimension(
requested,
$crate::MAX_INTERVAL_MATRIX_DIM,
Expand Down Expand Up @@ -1425,7 +1425,7 @@ macro_rules! try_with_rational_matrix {
6 => $crate::try_with_rational_matrix!(@arm 6, $matrix, $ret, $body),
7 => $crate::try_with_rational_matrix!(@arm 7, $matrix, $ret, $body),
8 => $crate::try_with_rational_matrix!(@arm 8, $matrix, $ret, $body),
requested => Err(::core::convert::From::from(
requested => ::core::result::Result::Err(::core::convert::From::from(
$crate::LaError::unsupported_dimension(
requested,
$crate::MAX_RATIONAL_MATRIX_DISPATCH_DIM,
Expand All @@ -1445,7 +1445,7 @@ macro_rules! try_with_rational_matrix {
6 => $crate::try_with_rational_matrix!(@arm_mut 6, $matrix, $ret, $body),
7 => $crate::try_with_rational_matrix!(@arm_mut 7, $matrix, $ret, $body),
8 => $crate::try_with_rational_matrix!(@arm_mut 8, $matrix, $ret, $body),
requested => Err(::core::convert::From::from(
requested => ::core::result::Result::Err(::core::convert::From::from(
$crate::LaError::unsupported_dimension(
requested,
$crate::MAX_RATIONAL_MATRIX_DISPATCH_DIM,
Expand Down
5 changes: 3 additions & 2 deletions src/polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//! See the [invariant and resource contract](https://github.com/acgetchell/la-stack/blob/main/docs/mathematical_basis.md#exact-sparse-polynomial-determinants).

use std::collections::{BTreeMap, btree_map::Entry};
use std::mem::take;

use num_rational::BigRational;
use num_traits::{One, Zero};
Expand Down Expand Up @@ -193,7 +194,7 @@ pub fn polynomial_determinant<const D: usize>(
let mut products = 0;
for mask in 0..state_count - 1 {
let row = mask.count_ones() as usize;
let partial = std::mem::take(&mut partials[mask]);
let partial = take(&mut partials[mask]);
if partial.is_zero() {
continue;
}
Expand Down Expand Up @@ -228,5 +229,5 @@ pub fn polynomial_determinant<const D: usize>(
}
}
}
Ok(std::mem::take(&mut partials[state_count - 1]))
Ok(take(&mut partials[state_count - 1]))
}
Loading
Loading