feature gate functionality
This commit is contained in:
parent
8638b796ac
commit
85e7551c81
|
@ -61,7 +61,7 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: test
|
- name: test
|
||||||
run: cargo test --features arbitrary,rand,serde-serialize,sparse,debug,io,compare,libm,proptest-support,slow-tests,rkyv-safe-deser;
|
run: cargo test --features arbitrary,rand,serde-serialize,sparse,debug,io,compare,libm,proptest-support,slow-tests,rkyv-safe-deser,rayon;
|
||||||
test-nalgebra-glm:
|
test-nalgebra-glm:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|
|
@ -33,6 +33,7 @@ libm = [ "simba/libm" ]
|
||||||
libm-force = [ "simba/libm_force" ]
|
libm-force = [ "simba/libm_force" ]
|
||||||
macros = [ "nalgebra-macros" ]
|
macros = [ "nalgebra-macros" ]
|
||||||
cuda = [ "cust_core", "simba/cuda" ]
|
cuda = [ "cust_core", "simba/cuda" ]
|
||||||
|
rayon = [ "dep:rayon" ]
|
||||||
|
|
||||||
# Conversion
|
# Conversion
|
||||||
convert-mint = [ "mint" ]
|
convert-mint = [ "mint" ]
|
||||||
|
@ -101,7 +102,7 @@ glam020 = { package = "glam", version = "0.20", optional = true }
|
||||||
glam021 = { package = "glam", version = "0.21", optional = true }
|
glam021 = { package = "glam", version = "0.21", optional = true }
|
||||||
glam022 = { package = "glam", version = "0.22", optional = true }
|
glam022 = { package = "glam", version = "0.22", optional = true }
|
||||||
cust_core = { version = "0.1", optional = true }
|
cust_core = { version = "0.1", optional = true }
|
||||||
rayon = "1.5" # TODO make this feature gated
|
rayon = { version = "1.5", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
|
|
@ -6,8 +6,6 @@ use std::iter::FusedIterator;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
use rayon::iter::plumbing::Producer;
|
|
||||||
|
|
||||||
use crate::base::dimension::{Dim, U1};
|
use crate::base::dimension::{Dim, U1};
|
||||||
use crate::base::storage::{RawStorage, RawStorageMut};
|
use crate::base::storage::{RawStorage, RawStorageMut};
|
||||||
use crate::base::{Matrix, MatrixView, MatrixViewMut, Scalar};
|
use crate::base::{Matrix, MatrixView, MatrixViewMut, Scalar};
|
||||||
|
@ -365,34 +363,6 @@ impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + RawStorage<T, R, C>> ExactSizeIterat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T, R: Dim, Cols: Dim, S: RawStorage<T, R, Cols>> Producer for ColumnIter<'a, T, R, Cols, S>
|
|
||||||
where
|
|
||||||
T: Send + Sync + Debug + PartialEq + Clone + 'static,
|
|
||||||
S: Sync,
|
|
||||||
{
|
|
||||||
type Item = MatrixSlice<'a, T, R, U1, S::RStride, S::CStride>;
|
|
||||||
type IntoIter = ColumnIter<'a, T, R, Cols, S>;
|
|
||||||
|
|
||||||
fn split_at(self, index: usize) -> (Self, Self) {
|
|
||||||
// the index is relative to the size of this current iterator
|
|
||||||
// it will always start at zero so it serves as an offset
|
|
||||||
let left = Self {
|
|
||||||
mat: self.mat,
|
|
||||||
range: self.range.start..(self.range.start + index),
|
|
||||||
};
|
|
||||||
|
|
||||||
let right = Self {
|
|
||||||
mat: self.mat,
|
|
||||||
range: (self.range.start + index)..self.range.end,
|
|
||||||
};
|
|
||||||
(left, right)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn into_iter(self) -> Self::IntoIter {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An iterator through the mutable columns of a matrix.
|
/// An iterator through the mutable columns of a matrix.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ColumnIterMut<'a, T, R: Dim, C: Dim, S: RawStorageMut<T, R, C>> {
|
pub struct ColumnIterMut<'a, T, R: Dim, C: Dim, S: RawStorageMut<T, R, C>> {
|
||||||
|
@ -469,6 +439,40 @@ impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + RawStorageMut<T, R, C>> DoubleEndedI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// implementations for parallel iteration with rayon
|
||||||
|
#[cfg(feature = "rayon")]
|
||||||
|
mod parallel {
|
||||||
|
use super::*;
|
||||||
|
use rayon::iter::plumbing::Producer;
|
||||||
|
|
||||||
|
impl<'a, T, R: Dim, Cols: Dim, S: RawStorage<T, R, Cols>> Producer for ColumnIter<'a, T, R, Cols, S>
|
||||||
|
where
|
||||||
|
T: Send + Sync + Debug + PartialEq + Clone + 'static,
|
||||||
|
S: Sync,
|
||||||
|
{
|
||||||
|
type Item = MatrixSlice<'a, T, R, U1, S::RStride, S::CStride>;
|
||||||
|
type IntoIter = ColumnIter<'a, T, R, Cols, S>;
|
||||||
|
|
||||||
|
fn split_at(self, index: usize) -> (Self, Self) {
|
||||||
|
// the index is relative to the size of this current iterator
|
||||||
|
// it will always start at zero so it serves as an offset
|
||||||
|
let left = Self {
|
||||||
|
mat: self.mat,
|
||||||
|
range: self.range.start..(self.range.start + index),
|
||||||
|
};
|
||||||
|
|
||||||
|
let right = Self {
|
||||||
|
mat: self.mat,
|
||||||
|
range: (self.range.start + index)..self.range.end,
|
||||||
|
};
|
||||||
|
(left, right)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + RawStorageMut<T, R, C>> Producer
|
impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + RawStorageMut<T, R, C>> Producer
|
||||||
for ColumnIterMut<'a, T, R, C, S>
|
for ColumnIterMut<'a, T, R, C, S>
|
||||||
where
|
where
|
||||||
|
@ -501,7 +505,10 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// this implementation is safe because we are enforcing exclusive access
|
||||||
|
/// to the columns through the active range of the iterator
|
||||||
unsafe impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + RawStorageMut<T, R, C>> Send
|
unsafe impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + RawStorageMut<T, R, C>> Send
|
||||||
for ColumnIterMut<'a, T, R, C, S>
|
for ColumnIterMut<'a, T, R, C, S>
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ mod min_max;
|
||||||
/// Mechanisms for working with values that may not be initialized.
|
/// Mechanisms for working with values that may not be initialized.
|
||||||
pub mod uninit;
|
pub mod uninit;
|
||||||
|
|
||||||
|
#[cfg(feature = "rayon")]
|
||||||
pub mod par_iter;
|
pub mod par_iter;
|
||||||
|
|
||||||
#[cfg(feature = "rkyv-serialize-no-std")]
|
#[cfg(feature = "rkyv-serialize-no-std")]
|
||||||
|
|
|
@ -1200,6 +1200,7 @@ fn column_iteration_double_ended() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg(feature = "rayon")]
|
||||||
fn parallel_column_iteration() {
|
fn parallel_column_iteration() {
|
||||||
use nalgebra::dmatrix;
|
use nalgebra::dmatrix;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
@ -1221,6 +1222,7 @@ fn parallel_column_iteration() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg(feature = "rayon")]
|
||||||
fn colum_iteration_mut_double_ended() {
|
fn colum_iteration_mut_double_ended() {
|
||||||
let dmat = nalgebra::dmatrix![
|
let dmat = nalgebra::dmatrix![
|
||||||
13,14,15,16,17;
|
13,14,15,16,17;
|
||||||
|
@ -1239,6 +1241,7 @@ fn colum_iteration_mut_double_ended() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[cfg(feature = "rayon")]
|
||||||
fn parallel_column_iteration_mut() {
|
fn parallel_column_iteration_mut() {
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
let mut first = DMatrix::<f32>::zeros(400, 300);
|
let mut first = DMatrix::<f32>::zeros(400, 300);
|
||||||
|
|
|
@ -9,6 +9,10 @@ compile_error!(
|
||||||
Example: `cargo test --features debug,compare,rand,macros`"
|
Example: `cargo test --features debug,compare,rand,macros`"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// make sure to test the parallel iterators for all builds that do not require no_std
|
||||||
|
#[cfg(all(feature = "std", not(feature = "rayon")))]
|
||||||
|
compile_error!("Please additionally enable the `rayon` feature to compile and run the tests");
|
||||||
|
|
||||||
#[cfg(all(feature = "debug", feature = "compare", feature = "rand"))]
|
#[cfg(all(feature = "debug", feature = "compare", feature = "rand"))]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate approx;
|
extern crate approx;
|
||||||
|
|
Loading…
Reference in New Issue