[][src]Struct hogwild::HogwildArray

pub struct HogwildArray<A, D>(_);

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());

Methods

impl<A, D> HogwildArray<A, D>[src]

pub fn into_inner(self) -> Arc<UnsafeCell<Array<A, D>>>[src]

impl<A, D> HogwildArray<A, D> where
    D: Dimension + RemoveAxis
[src]

pub fn subview(&self, axis: Axis, index: Ix) -> ArrayView<A, D::Smaller>[src]

Get an immutable subview of the Hogwild array.

pub fn subview_mut(
    &mut self,
    axis: Axis,
    index: Ix
) -> ArrayViewMut<A, D::Smaller>
[src]

Get a mutable subview of the Hogwild array.

impl<A, D> HogwildArray<A, D> where
    D: Dimension
[src]

pub fn as_slice(&self) -> Option<&[A]>[src]

Get a slice reference to the underlying data array.

pub fn view(&self) -> ArrayView<A, D>[src]

Get an immutable view of the Hogwild array.

pub fn view_mut(&mut self) -> ArrayViewMut<A, D>[src]

Get an mutable view of the Hogwild array.

Trait Implementations

impl<A, D> Send for HogwildArray<A, D>[src]

impl<A, D> Sync for HogwildArray<A, D>[src]

impl<A, D> From<ArrayBase<OwnedRepr<A>, D>> for HogwildArray<A, D>[src]

impl<A: Clone, D: Clone> Clone for HogwildArray<A, D>[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.