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§
Sourcefn new<F>(bounds: AddressBound<A>, address_value_converter: F) -> Selfwhere
F: Fn(A) -> T,
fn new<F>(bounds: AddressBound<A>, address_value_converter: F) -> Selfwhere
F: Fn(A) -> T,
Creates a new instance of a tensor with the given inclusive bounds and an address value mapper closure
Sourcefn get(&self, address: &A) -> Option<&T>
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
fn get_mut(&mut self, address: &A) -> Option<&mut T>
Sourcefn set(&mut self, address: &A, value: T) -> Result<(), Error>
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.
Sourcefn bounds(&self) -> &AddressBound<A>
fn bounds(&self) -> &AddressBound<A>
Returns a reference to the bounds of the tensor
Provided Methods§
Sourcefn address_iterator<'a>(&'a self) -> AddressIterator<A> ⓘwhere
T: 'a,
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.
Sourcefn transform<F, TNew, TENew>(&self, mapping_function: F) -> TENew
fn transform<F, TNew, TENew>(&self, mapping_function: F) -> TENew
Returns a new tensor, which is a copy of this tensor with the values mapped by the given function.
Sourcefn transform_by_address<F, TNew, TENew>(&self, mapping_function: F) -> TENew
fn transform_by_address<F, TNew, TENew>(&self, mapping_function: F) -> TENew
Returns a new tensor, which is a copy of this tensor with the values mapped by the given function.
Sourcefn transform_in_place<F>(&mut self, mapping_function: F)
fn transform_in_place<F>(&mut self, mapping_function: F)
Alters every value in the tensor by some mapping function. Note: the mapping function must have the same input value and output value type.
Sourcefn transform_by_address_in_place<F>(&mut self, mapping_function: F)
fn transform_by_address_in_place<F>(&mut self, mapping_function: F)
Alters every value in the tensor by some mapping function. Note: the mapping function must have the same input value and output value type.
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.