Skip to content
Open
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
27 changes: 14 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion benches/rcb_cartesian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn bench(c: &mut Criterion) {
})
.build()
.unwrap();
group.bench_function(&thread_count.to_string(), |b| {
group.bench_function(thread_count.to_string(), |b| {
pool.install(|| {
b.iter(|| grid.rcb(black_box(&mut partition), black_box(&weights), 12))
});
Expand Down
6 changes: 3 additions & 3 deletions ffi/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Constant {
Ok(v)
}

pub unsafe fn iter<'a, T>(&'a self) -> impl Iterator<Item = T> + ExactSizeIterator + 'a
pub unsafe fn iter<'a, T>(&'a self) -> impl ExactSizeIterator<Item = T> + 'a
where
T: 'a + Copy,
{
Expand Down Expand Up @@ -73,7 +73,7 @@ impl Array {
slice::from_raw_parts(self.array as *const T, self.len)
}

pub unsafe fn iter<'a, T>(&'a self) -> impl Iterator<Item = T> + ExactSizeIterator + 'a
pub unsafe fn iter<'a, T>(&'a self) -> impl ExactSizeIterator<Item = T> + 'a
where
T: 'a + Copy,
{
Expand Down Expand Up @@ -117,7 +117,7 @@ impl Fn {
Ok(v)
}

pub unsafe fn iter<'a, T>(&'a self) -> impl Iterator<Item = T> + ExactSizeIterator + 'a
pub unsafe fn iter<'a, T>(&'a self) -> impl ExactSizeIterator<Item = T> + 'a
where
T: 'a + Copy,
{
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/graph_growth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub struct GraphGrowth {
pub part_count: usize,
}

impl<'a, W> crate::Partition<(CsMatView<'a, f64>, W)> for GraphGrowth
impl<W> crate::Partition<(CsMatView<'_, f64>, W)> for GraphGrowth
where
W: AsRef<[f64]>,
{
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/hilbert_curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ fn encode_2d(x: u64, y: u64, order: usize) -> u64 {
order,
);

const LUT: [u16; 16_384] = {
static LUT: [u16; 16_384] = {
let mut lut = [0; 16_384];
let mut i: usize = 0;
while i < 16_384 {
Expand Down
15 changes: 4 additions & 11 deletions src/algorithms/k_means.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ fn imbalance(weights: &[f64]) -> f64 {
/// - `imbalance_tol`: the relative imbalance tolerance of the generated partitions, in `%` of the target weight of each partition.
/// - `delta_threshold`: the distance threshold for the cluster movements under which the algorithm stops.
/// - `max_iter`: the maximum number of times each cluster will move before stopping the algorithm
/// - `max_balance_iter`: the maximum number of iterations of the load balancing loop. It will limit how much each cluster
/// influence can grow between each cluster movement.
/// - `max_balance_iter`: the maximum number of iterations of the load balancing loop. It will limit how much each cluster influence can grow between each cluster movement.
/// - `erode`: sets whether or not cluster influence is modified according to errosion's rules between each cluster movement
/// - `hilbert`: sets wheter or not an Hilbert curve is used to create the initial partition. If false, a Z curve is used instead.
/// - `mbr_early_break`: sets whether or not bounding box optimization is enabled.
#[derive(Debug, Clone, Copy)]
pub struct BalancedKmeansSettings {
Expand All @@ -58,7 +56,6 @@ pub struct BalancedKmeansSettings {
pub max_iter: usize,
pub max_balance_iter: usize,
pub erode: bool,
pub hilbert: bool,
pub mbr_early_break: bool,
}

Expand All @@ -71,7 +68,6 @@ impl Default for BalancedKmeansSettings {
max_iter: 50,
max_balance_iter: 1, // for now, `max_balance_iter > 1` yields poor convergence time
erode: false, // for now, `erode` yields` enabled yields wrong results
hilbert: true,
mbr_early_break: false, // for now, `mbr_early_break` enabled yields wrong results
}
}
Expand Down Expand Up @@ -129,7 +125,7 @@ fn balanced_k_means_with_initial_partition<const D: usize>(
// Generate initial lower and upper bounds. These two variables represent bounds on
// the effective distance between an point and the cluster it is assigned to.
let mut lbs: Vec<_> = points.par_iter().map(|_| 0.).collect();
let mut ubs: Vec<_> = points.par_iter().map(|_| std::f64::MAX).collect(); // we use f64::MAX to represent infinity
let mut ubs: Vec<_> = points.par_iter().map(|_| f64::MAX).collect(); // we use f64::MAX to represent infinity

balanced_k_means_iter(
Inputs { points, weights },
Expand Down Expand Up @@ -480,8 +476,8 @@ fn best_values<const D: usize>(
f64, // new ub
Option<ClusterId>, // new cluster assignment for the current point (None if the same assignment is kept)
) {
let mut best_value = std::f64::MAX;
let mut snd_best_value = std::f64::MAX;
let mut best_value = f64::MAX;
let mut snd_best_value = f64::MAX;
let mut assignment = None;

for (((center, id), distance_to_mbr), influence) in centers
Expand Down Expand Up @@ -578,7 +574,6 @@ pub struct KMeans {
pub max_iter: usize,
pub max_balance_iter: usize,
pub erode: bool,
pub hilbert: bool,
pub mbr_early_break: bool,
}

Expand All @@ -590,7 +585,6 @@ impl Default for KMeans {
max_iter: 500,
max_balance_iter: 20, // for now, `max_balance_iter > 1` yields poor convergence time
erode: false, // for now, `erode` yields` enabled yields wrong results
hilbert: true,
mbr_early_break: false, // for now, `mbr_early_break` enabled yields wrong results
}
}
Expand Down Expand Up @@ -621,7 +615,6 @@ where
max_iter: self.max_iter,
max_balance_iter: self.max_balance_iter,
erode: self.erode,
hilbert: self.hilbert,
mbr_early_break: self.mbr_early_break,
};
balanced_k_means_with_initial_partition(points, weights, settings, part_ids);
Expand Down
3 changes: 1 addition & 2 deletions src/algorithms/kernighan_lin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ fn kernighan_lin_2_impl<T>(
let mut locks = vec![false; initial_partition.len()];

// pass loop
for _ in 0..(initial_partition.len() / 2).min(max_flips_per_pass.unwrap_or(std::usize::MAX))
{
for _ in 0..(initial_partition.len() / 2).min(max_flips_per_pass.unwrap_or(usize::MAX)) {
// construct gains
for (idx, gain) in gains.iter_mut().enumerate() {
for (j, w) in adjacency.neighbors(idx) {
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/multi_jagged.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ pub(crate) fn compute_split_positions(
let mut scan = permutation
.par_iter()
.enumerate()
.fold_with((std::usize::MAX, 0.), |(low, acc), (idx, val)| {
.fold_with((usize::MAX, 0.), |(low, acc), (idx, val)| {
(usize::min(idx, low), acc + weights[*val])
})
.collect::<Vec<_>>()
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/z_curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use std::sync::atomic::{self, AtomicPtr};
// in 2D, an order greater than 64 will overflow u128.
// maybe it would be more appropriate to use a BigInt
type HashType = u128;
const HASH_TYPE_MAX: HashType = std::u128::MAX;
const HASH_TYPE_MAX: HashType = u128::MAX;

fn z_curve_partition<const D: usize>(
partition: &mut [usize],
Expand Down
7 changes: 5 additions & 2 deletions src/cartesian/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<const D: usize> Grid<D> {
_ => {
for (s, p) in self.size.into_iter().zip(&mut pos) {
*p = i % s;
i = i / s;
i /= s;
}
}
}
Expand Down Expand Up @@ -265,7 +265,10 @@ impl<const D: usize, E> Topology<E> for Grid<D>
where
E: One,
{
type Neighbors<'a> = GridNeighbors<D, E> where Self: 'a;
type Neighbors<'a>
= GridNeighbors<D, E>
where
Self: 'a;

fn len(&self) -> usize {
self.len()
Expand Down
6 changes: 3 additions & 3 deletions src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ impl<const D: usize> BoundingBox<D> {
let (p_min, p_max) = points
.fold_with(
(
PointND::<D>::from_element(std::f64::MAX),
PointND::<D>::from_element(std::f64::MIN),
PointND::<D>::from_element(f64::MAX),
PointND::<D>::from_element(f64::MIN),
),
|(mut mins, mut maxs), vals| {
for ((min, max), val) in mins.iter_mut().zip(maxs.iter_mut()).zip(&vals) {
Expand Down Expand Up @@ -118,7 +118,7 @@ impl<const D: usize> BoundingBox<D> {
}

pub fn contains(&self, point: &PointND<D>) -> bool {
let eps = 10. * std::f64::EPSILON;
let eps = 10. * f64::EPSILON;
self.p_min
.iter()
.zip(self.p_max.iter())
Expand Down
12 changes: 6 additions & 6 deletions src/nextafter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@ pub fn nextafter(from: f64, to: f64) -> f64 {
mod tests {
use super::*;

const POS_INF: f64 = std::f64::INFINITY;
const NEG_INF: f64 = std::f64::NEG_INFINITY;
const POS_INF: f64 = f64::INFINITY;
const NEG_INF: f64 = f64::NEG_INFINITY;
const POS_ZERO: f64 = 0.0;
const NEG_ZERO: f64 = -0.0;

// Note: Not the same as f64::MIN_POSITIVE, because that is only the min *normal* number.
const SMALLEST_POS: f64 = 5e-324;
const SMALLEST_NEG: f64 = -5e-324;
const LARGEST_POS: f64 = std::f64::MAX;
const LARGEST_NEG: f64 = std::f64::MIN;
const LARGEST_POS: f64 = f64::MAX;
const LARGEST_NEG: f64 = f64::MIN;

const POS_ONE: f64 = 1.0;
const NEG_ONE: f64 = -1.0;
const NEXT_LARGER_THAN_ONE: f64 = 1.0 + std::f64::EPSILON;
const NEXT_LARGER_THAN_ONE: f64 = 1.0 + f64::EPSILON;
const NEXT_SMALLER_THAN_ONE: f64 = 0.999_999_999_999_999_9;

const SEQUENCE_BIG_NUM: (f64, f64) = (16_237_485_966.000_004, 16_237_485_966.000_006);

const NAN: f64 = std::f64::NAN;
const NAN: f64 = f64::NAN;

fn is_pos_zero(x: f64) -> bool {
x.to_bits() == POS_ZERO.to_bits()
Expand Down
8 changes: 5 additions & 3 deletions src/topology/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ pub trait Topology<E> {
}
}

impl<'a, T, E> Topology<E> for &'a T
impl<T, E> Topology<E> for &T
where
E: Copy,
T: Topology<E>,
{
type Neighbors<'n> = T::Neighbors<'n>
where Self: 'n;
type Neighbors<'n>
= T::Neighbors<'n>
where
Self: 'n;

fn len(&self) -> usize {
T::len(self)
Expand Down
8 changes: 5 additions & 3 deletions src/topology/sprs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ use std::iter::Sum;
use std::iter::Zip;
use std::ops::Mul;

impl<'a, E> Topology<E> for sprs::CsMatView<'a, E>
impl<E> Topology<E> for sprs::CsMatView<'_, E>
where
E: Copy + Sync,
{
type Neighbors<'n> = Zip<Cloned<std::slice::Iter<'n, usize>>, Cloned<std::slice::Iter<'n, E>>>
where Self: 'n;
type Neighbors<'n>
= Zip<Cloned<std::slice::Iter<'n, usize>>, Cloned<std::slice::Iter<'n, E>>>
where
Self: 'n;

fn len(&self) -> usize {
debug_assert_eq!(self.rows(), self.cols());
Expand Down
4 changes: 2 additions & 2 deletions src/work_share.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ pub fn work_share(total_work: usize, max_threads: usize) -> (usize, usize) {
let max_threads = usize::min(total_work, max_threads);

// ceil(total_work / max_threads)
let work_per_thread = (total_work + max_threads - 1) / max_threads;
let work_per_thread = total_work.div_ceil(max_threads);

// ceil(total_work / work_per_thread)
let thread_count = (total_work + work_per_thread - 1) / work_per_thread;
let thread_count = total_work.div_ceil(work_per_thread);

(work_per_thread, thread_count)
}
Expand Down
5 changes: 2 additions & 3 deletions tools/mesh-io/ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::ffi::c_int;
use std::fs;
use std::io;
use std::os::unix::io::FromRawFd as _;
use std::os::unix::io::IntoRawFd as _;
use std::ptr;

const ERROR_OTHER: c_int = -1;
Expand Down Expand Up @@ -50,8 +49,8 @@ pub unsafe extern "C" fn mio_partition_write(fd: c_int, size: u64, partition: *c
return ERROR_OTHER;
}
match w.into_inner() {
Ok(f) => {
f.into_raw_fd();
Ok(_) => {
//f.into_raw_fd();
0
}
Err(_) => ERROR_OTHER,
Expand Down
2 changes: 1 addition & 1 deletion tools/mesh-io/src/vtk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn add_piece(mesh: &mut Mesh, piece: UnstructuredGridPiece) {
mesh.coordinates.extend(piece.points.iter().unwrap());
// TODO extract attributes
mesh.node_refs
.extend(iter::repeat(1).take(piece.num_points()));
.extend(std::iter::repeat_n(1, piece.num_points()));
match piece.cells.cell_verts {
VertexNumbers::Legacy {
num_cells,
Expand Down
Loading
Loading