Skip to content

Commit b5fcdc2

Browse files
authored
Merge pull request #269 from lcpp-org/par_rot_functions
Par rot functions
2 parents 3b92bab + 4f08820 commit b5fcdc2

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ rand_distr = "0.4.3"
2020
toml = "0.7.4"
2121
anyhow = "1.0.71"
2222
itertools = "0.10.5"
23-
rayon = "1.7.0"
23+
rayon = "1.10.0"
2424
geo = {version = "0.25", optional = false}
2525
indicatif = {version = "0.15.0", features=["rayon"]}
2626
serde = { version = "1.0.163", features = ["derive"] }

src/lib.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use std::slice;
3939
use std::sync::Mutex;
4040

4141
//itertools
42-
use itertools::izip;
42+
use itertools::{izip};
4343

4444
//Math
4545
use std::f64::consts::FRAC_2_SQRT_PI;
@@ -1682,22 +1682,15 @@ pub fn rotate_back_py(nx: f64, ny: f64, nz: f64, ux: f64, uy: f64, uz: f64) -> (
16821682
/// direction (list(f64), list(f64), list(f64)): direction vector of particle in simulation coordinates.
16831683
pub fn rotate_back_vec_py(nx: Vec<f64>, ny: Vec<f64>, nz: Vec<f64>, ux: Vec<f64>, uy: Vec<f64>, uz: Vec<f64>) -> (Vec<f64>, Vec<f64>, Vec<f64>) {
16841684

1685-
let length = nx.len();
1685+
let (ux_new, (uy_new, uz_new)) = (nx, ny, nz, ux, uy, uz).into_par_iter().map(|(nx_, ny_, nz_, ux_, uy_, uz_)| {
16861686

1687-
let mut ux_new = Vec::with_capacity(length);
1688-
let mut uy_new = Vec::with_capacity(length);
1689-
let mut uz_new = Vec::with_capacity(length);
1687+
let mut ux_mut = ux_;
1688+
let mut uy_mut = uy_;
1689+
let mut uz_mut = uz_;
1690+
rotate_back(nx_, ny_, nz_, &mut ux_mut, &mut uy_mut, &mut uz_mut);
16901691

1691-
(0..length).into_iter().for_each(|index| {
1692-
1693-
let mut ux_ = ux[index];
1694-
let mut uy_ = uy[index];
1695-
let mut uz_ = uz[index];
1696-
rotate_back(nx[index], ny[index], nz[index], &mut ux_, &mut uy_, &mut uz_);
1697-
ux_new.push(ux_);
1698-
uy_new.push(uy_);
1699-
uz_new.push(uz_);
1700-
});
1692+
(ux_mut, (uy_mut, uz_mut))
1693+
}).unzip();
17011694

17021695
(ux_new, uy_new, uz_new)
17031696
}

0 commit comments

Comments
 (0)