pub struct HogwildArray<A, D>(/* private fields */);
Expand description
Array for Hogwild parallel optimization.
This array type can be used for the Hogwild (Niu, et al. 2011) method of parallel Stochastic Gradient descent. In Hogwild different threads share the same parameters without locking. If SGD is performed on a sparse optimization problem, where only a small subset of parameters is updated in each gradient descent, the impact of data races is negligible.
In order to use Hogwild in Rust, we have to subvert the ownership
system. This is what the HogwildArray
type does. It uses reference
counting to share an ndarray Array
type between multiple
HogwildArray
instances. Views of the underling Array
can be borrowed
mutably from each instance, without mutual exclusion between mutable
borrows in different HogwildArray
instances.
§Example
use hogwild::HogwildArray2;
use ndarray::Array2;
let mut a1: HogwildArray2<f32> = Array2::zeros((2, 2)).into();
let mut a2 = a1.clone();
let mut a1_view = a1.view_mut();
let c00 = &mut a1_view[(0, 0)];
*c00 = 1.0;
// Two simultaneous mutable borrows of the underlying array.
a2.view_mut()[(1, 1)] = *c00 * 2.0;
assert_eq!(&[1.0, 0.0, 0.0, 2.0], a2.as_slice().unwrap());
Implementations§
Source§impl<A, D> HogwildArray<A, D>
impl<A, D> HogwildArray<A, D>
pub fn into_inner(self) -> Arc<UnsafeCell<Array<A, D>>>
Source§impl<A, D> HogwildArray<A, D>where
D: Dimension + RemoveAxis,
impl<A, D> HogwildArray<A, D>where
D: Dimension + RemoveAxis,
Source§impl<A, D> HogwildArray<A, D>where
D: Dimension,
impl<A, D> HogwildArray<A, D>where
D: Dimension,
Trait Implementations§
Source§impl<A: Clone, D: Clone> Clone for HogwildArray<A, D>
impl<A: Clone, D: Clone> Clone for HogwildArray<A, D>
Source§fn clone(&self) -> HogwildArray<A, D>
fn clone(&self) -> HogwildArray<A, D>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreimpl<A, D> Send for HogwildArray<A, D>
impl<A, D> Sync for HogwildArray<A, D>
Auto Trait Implementations§
impl<A, D> Freeze for HogwildArray<A, D>
impl<A, D> !RefUnwindSafe for HogwildArray<A, D>
impl<A, D> Unpin for HogwildArray<A, D>
impl<A, D> !UnwindSafe for HogwildArray<A, D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more