[−][src]Struct hogwild::HogwildArray
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]
D: Dimension + RemoveAxis,
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]
&mut self,
axis: Axis,
index: Ix
) -> ArrayViewMut<A, D::Smaller>
Get a mutable subview of the Hogwild array.
impl<A, D> HogwildArray<A, D> where
D: Dimension,
[src]
D: Dimension,
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(&self) -> 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]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,