Trait Tensor

Source
pub trait Tensor<T, A: Addressable> {
    // Required methods
    fn new<F>(bounds: AddressBound<A>, address_value_converter: F) -> Self
       where F: Fn(A) -> T;
    fn get(&self, address: &A) -> Option<&T>;
    fn get_mut(&mut self, address: &A) -> Option<&mut T>;
    fn set(&mut self, address: &A, value: T) -> Result<(), Error>;
    fn bounds(&self) -> &AddressBound<A>;

    // Provided methods
    fn address_iterator<'a>(&'a self) -> AddressIterator<A> 
       where T: 'a { ... }
    fn transform<F, TNew, TENew>(&self, mapping_function: F) -> TENew
       where F: Fn(&T) -> TNew,
             TENew: Tensor<TNew, A> { ... }
    fn transform_by_address<F, TNew, TENew>(&self, mapping_function: F) -> TENew
       where F: Fn(&A, &T) -> TNew,
             TENew: Tensor<TNew, A> { ... }
    fn transform_in_place<F>(&mut self, mapping_function: F)
       where F: Fn(&mut T) { ... }
    fn transform_by_address_in_place<F>(&mut self, mapping_function: F)
       where F: Fn(&A, &mut T) { ... }
    fn eq(&self, other: &Self) -> bool
       where T: PartialEq { ... }
}
Expand description

The framework used to make a tensor or an N dimensional array

Required Methods§

Source

fn new<F>(bounds: AddressBound<A>, address_value_converter: F) -> Self
where F: Fn(A) -> T,

Creates a new instance of a tensor with the given inclusive bounds and an address value mapper closure

Source

fn get(&self, address: &A) -> Option<&T>

Attempts to retrieve a reference to the value at the address. Returns None if the address is outside the given bound

Source

fn get_mut(&mut self, address: &A) -> Option<&mut T>

Source

fn set(&mut self, address: &A, value: T) -> Result<(), Error>

Attempts to reassign the value at the given index. Returns Err if the given address is out of bounds.

Source

fn bounds(&self) -> &AddressBound<A>

Returns a reference to the bounds of the tensor

Provided Methods§

Source

fn address_iterator<'a>(&'a self) -> AddressIterator<A>
where T: 'a,

Returns an iterator who generates addresses in row-major order. Can’t give an address who is out of bounds.

Source

fn transform<F, TNew, TENew>(&self, mapping_function: F) -> TENew
where F: Fn(&T) -> TNew, TENew: Tensor<TNew, A>,

Returns a new tensor, which is a copy of this tensor with the values mapped by the given function.

Source

fn transform_by_address<F, TNew, TENew>(&self, mapping_function: F) -> TENew
where F: Fn(&A, &T) -> TNew, TENew: Tensor<TNew, A>,

Returns a new tensor, which is a copy of this tensor with the values mapped by the given function.

Source

fn transform_in_place<F>(&mut self, mapping_function: F)
where F: Fn(&mut T),

Alters every value in the tensor by some mapping function. Note: the mapping function must have the same input value and output value type.

Source

fn transform_by_address_in_place<F>(&mut self, mapping_function: F)
where F: Fn(&A, &mut T),

Alters every value in the tensor by some mapping function. Note: the mapping function must have the same input value and output value type.

Source

fn eq(&self, other: &Self) -> bool
where T: PartialEq,

A canonical means of testing equality. Implementors may choose to use other more efficient means, but this is always viable.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§