ndarray_parallel/lib.rs
1//! Parallelization features for ndarray.
2//!
3//! ***This crate is deprecated and was replaced by equivalent `rayon` support
4//! directly integrated to `ndarray`.***
5//!
6//! The array views and references to owned arrays all implement
7//! `NdarrayIntoParallelIterator` (*); the default parallel iterators (each element
8//! by reference or mutable reference) have no ordering guarantee in their
9//! parallel implementations.
10//!
11//! `.axis_iter()` and `.axis_iter_mut()` also have parallel counterparts,
12//! and their parallel iterators are indexed (and thus ordered) and exact length.
13//!
14//! `Zip` also implements `NdarrayIntoParallelIterator`, and there is an
15//! extension trait so that it can use a method `.par_apply` directly.
16//!
17//! (*) This regime of a custom trait instead of rayon’s own is since we
18//! use this intermediate ndarray-parallel crate.
19//!
20//! # Examples
21//!
22//!
23//! ## Arrays and array views
24//!
25//! Compute the exponential of each element in an array, parallelized.
26//!
27//! ```
28//! extern crate ndarray;
29//! extern crate ndarray_parallel;
30//!
31//! use ndarray::Array2;
32//! use ndarray_parallel::prelude::*;
33//!
34//! fn main() {
35//! let mut a = Array2::<f64>::zeros((128, 128));
36//!
37//! // Parallel versions of regular array methods (ParMap trait)
38//! a.par_map_inplace(|x| *x = x.exp());
39//! a.par_mapv_inplace(f64::exp);
40//!
41//! // You can also use the parallel iterator directly
42//! a.par_iter_mut().for_each(|x| *x = x.exp());
43//! }
44//! ```
45//!
46//! ## Axis iterators
47//!
48//! Use the parallel `.axis_iter()` to compute the sum of each row.
49//!
50//! ```
51//! extern crate ndarray;
52//! extern crate ndarray_parallel;
53//!
54//! use ndarray::Array;
55//! use ndarray::Axis;
56//! use ndarray_parallel::prelude::*;
57//!
58//! fn main() {
59//! let a = Array::linspace(0., 63., 64).into_shape((4, 16)).unwrap();
60//! let mut sums = Vec::new();
61//! a.axis_iter(Axis(0))
62//! .into_par_iter()
63//! .map(|row| row.scalar_sum())
64//! .collect_into_vec(&mut sums);
65//!
66//! assert_eq!(sums, [120., 376., 632., 888.]);
67//! }
68//! ```
69//!
70//! ## Zip
71//!
72//! Use zip for lock step function application across several arrays
73//!
74//! ```
75//! extern crate ndarray;
76//! extern crate ndarray_parallel;
77//!
78//! use ndarray::Array3;
79//! use ndarray::Zip;
80//! use ndarray_parallel::prelude::*;
81//!
82//! type Array3f64 = Array3<f64>;
83//!
84//! fn main() {
85//! const N: usize = 128;
86//! let a = Array3f64::from_elem((N, N, N), 1.);
87//! let b = Array3f64::from_elem(a.dim(), 2.);
88//! let mut c = Array3f64::zeros(a.dim());
89//!
90//! Zip::from(&mut c)
91//! .and(&a)
92//! .and(&b)
93//! .par_apply(|c, &a, &b| {
94//! *c += a - b;
95//! });
96//! }
97//! ```
98#![doc(html_root_url = "http://docs.rs/ndarray-parallel/0.9/")]
99
100
101pub extern crate ndarray;
102pub extern crate rayon;
103
104/// Into- traits for creating parallelized iterators.
105pub mod prelude {
106 // happy and insane; ignorance is bluss
107 pub use NdarrayIntoParallelIterator;
108 pub use NdarrayIntoParallelRefIterator;
109 pub use NdarrayIntoParallelRefMutIterator;
110
111 #[doc(no_inline)]
112 pub use rayon::prelude::{ParallelIterator, IndexedParallelIterator};
113
114 pub use ext_traits::{
115 ParApply1,
116 ParApply2,
117 ParApply3,
118 ParApply4,
119 ParApply5,
120 ParApply6,
121 };
122 pub use ext_traits::ParMap;
123}
124
125pub use par::Parallel;
126pub use into_traits::{
127 NdarrayIntoParallelIterator,
128 NdarrayIntoParallelRefIterator,
129 NdarrayIntoParallelRefMutIterator,
130};
131
132mod par;
133mod ext_traits;
134mod into_traits;
135mod into_impls;
136mod zipmacro;