Struct HogwildArray

Source
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>

Source

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

Source§

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

Source

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

Get an immutable subview of the Hogwild array.

Source

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

Get a mutable subview of the Hogwild array.

Source§

impl<A, D> HogwildArray<A, D>
where D: Dimension,

Source

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

Get a slice reference to the underlying data array.

Source

pub fn view(&self) -> ArrayView<'_, A, D>

Get an immutable view of the Hogwild array.

Source

pub fn view_mut(&mut self) -> ArrayViewMut<'_, A, D>

Get an mutable view of the Hogwild array.

Trait Implementations§

Source§

impl<A: Clone, D: Clone> Clone for HogwildArray<A, D>

Source§

fn clone(&self) -> HogwildArray<A, D>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A, D> From<ArrayBase<OwnedRepr<A>, D>> for HogwildArray<A, D>

Source§

fn from(a: Array<A, D>) -> Self

Converts to this type from the input type.
Source§

impl<A, D> Send for HogwildArray<A, D>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.