Struct hotg_rune_core::Tensor
source · [−]pub struct Tensor<T> { /* private fields */ }
Expand description
A multidimensional array with copy-on-write semantics.
Implementations
sourceimpl<T> Tensor<T>
impl<T> Tensor<T>
pub fn new_row_major(elements: Arc<[T]>, dimensions: Vec<usize>) -> Self
pub fn new_vector(iter: impl IntoIterator<Item = T>) -> Self
pub fn single(value: T) -> Self
pub fn zeroed(dimensions: Vec<usize>) -> Self where
T: Default,
pub fn filled_with<F>(dimensions: Vec<usize>, f: F) -> Self where
F: FnMut() -> T,
pub fn shape(&self) -> Shape<'_> where
T: AsElementType,
sourcepub fn elements(&self) -> &[T]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
pub fn elements(&self) -> &[T]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
Get an immutable reference to the underlying elements in this
Tensor
.
sourcepub fn get_elements_mut(&mut self) -> Option<&mut [T]>
pub fn get_elements_mut(&mut self) -> Option<&mut [T]>
Get a mutable reference to the underlying elements in this Tensor
.
sourcepub fn slice<const RANK: usize>(
&self,
leading_indices: &[usize]
) -> Option<TensorView<'_, T, RANK>>
pub fn slice<const RANK: usize>(
&self,
leading_indices: &[usize]
) -> Option<TensorView<'_, T, RANK>>
Try to get a contiguous sub-slice of this tensor.
Note
Due to the way tensors are laid out in memory, you can only slice off the leading dimensions.
In order to be well-formed, this requires that
RANK + leading_indices.len()
equals Tensor::rank()
, and that each
of the indices are within bounds.
Examples
Say you have a [3, 4, 2]
tensor, passing in [0, 1]
would
give you a 1D TensorView
that views the 3 elements at
[0, 1, ..]
.
let input = [
[[0, 1], [2, 3], [4, 5], [6, 7]],
[[8, 9], [10, 11], [12, 13], [14, 15]],
[[16, 17], [18, 19], [20, 21], [22, 23]],
];
let tensor: Tensor<i32> = input.into();
let got = tensor.slice::<1>(&[0, 1]).unwrap();
assert_eq!(got.dimensions(), [2]);
assert_eq!(got.elements(), &input[0][1]);
sourcepub fn slice_mut<const RANK: usize>(
&mut self,
leading_indices: &[usize]
) -> Option<TensorViewMut<'_, T, RANK>> where
T: Clone,
pub fn slice_mut<const RANK: usize>(
&mut self,
leading_indices: &[usize]
) -> Option<TensorViewMut<'_, T, RANK>> where
T: Clone,
A mutable version of Tensor::slice()
.
sourcepub fn view<const RANK: usize>(&self) -> Option<TensorView<'_, T, RANK>>
pub fn view<const RANK: usize>(&self) -> Option<TensorView<'_, T, RANK>>
Try to reinterpret this tensor as a RANK
-D tensor.
sourcepub fn view_mut<'a, 'this: 'a, const RANK: usize>(
&'this mut self
) -> Option<TensorViewMut<'a, T, RANK>> where
T: Clone,
pub fn view_mut<'a, 'this: 'a, const RANK: usize>(
&'this mut self
) -> Option<TensorViewMut<'a, T, RANK>> where
T: Clone,
The mutable version of Tensor::view()
.
pub fn as_ptr_and_byte_length(&self) -> (*const u8, usize)
sourcepub fn map<F, Out>(&self, map: F) -> Tensor<Out> where
F: FnMut(&[usize], &T) -> Out,
pub fn map<F, Out>(&self, map: F) -> Tensor<Out> where
F: FnMut(&[usize], &T) -> Out,
Create a new Tensor
by applying a function to every element in the
current tensor.
This is often an expensive operation.
Trait Implementations
sourceimpl<'de, T: Deserialize<'de>> Deserialize<'de> for Tensor<T>
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Tensor<T>
sourcefn deserialize<D>(de: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
fn deserialize<D>(de: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<Element: Clone, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize, const F: usize, const G: usize, const H: usize> From<[[[[[[[[Element; H]; G]; F]; E]; D]; C]; B]; A]> for Tensor<Element>
impl<Element: Clone, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize, const F: usize, const G: usize, const H: usize> From<[[[[[[[[Element; H]; G]; F]; E]; D]; C]; B]; A]> for Tensor<Element>
sourceimpl<Element: Clone, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize, const F: usize, const G: usize> From<[[[[[[[Element; G]; F]; E]; D]; C]; B]; A]> for Tensor<Element>
impl<Element: Clone, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize, const F: usize, const G: usize> From<[[[[[[[Element; G]; F]; E]; D]; C]; B]; A]> for Tensor<Element>
sourceimpl<Element: Clone, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize, const F: usize> From<[[[[[[Element; F]; E]; D]; C]; B]; A]> for Tensor<Element>
impl<Element: Clone, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize, const F: usize> From<[[[[[[Element; F]; E]; D]; C]; B]; A]> for Tensor<Element>
sourceimpl<Element: Clone, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize> From<[[[[[Element; E]; D]; C]; B]; A]> for Tensor<Element>
impl<Element: Clone, const A: usize, const B: usize, const C: usize, const D: usize, const E: usize> From<[[[[[Element; E]; D]; C]; B]; A]> for Tensor<Element>
sourceimpl<Element: Clone, const A: usize, const B: usize, const C: usize, const D: usize> From<[[[[Element; D]; C]; B]; A]> for Tensor<Element>
impl<Element: Clone, const A: usize, const B: usize, const C: usize, const D: usize> From<[[[[Element; D]; C]; B]; A]> for Tensor<Element>
sourceimpl<T: Clone, const WIDTH: usize, const HEIGHT: usize, const DEPTH: usize> From<[[[T; WIDTH]; HEIGHT]; DEPTH]> for Tensor<T>
impl<T: Clone, const WIDTH: usize, const HEIGHT: usize, const DEPTH: usize> From<[[[T; WIDTH]; HEIGHT]; DEPTH]> for Tensor<T>
sourceimpl<T: Clone, const WIDTH: usize, const HEIGHT: usize> From<[[T; WIDTH]; HEIGHT]> for Tensor<T>
impl<T: Clone, const WIDTH: usize, const HEIGHT: usize> From<[[T; WIDTH]; HEIGHT]> for Tensor<T>
sourceimpl<T> FromIterator<T> for Tensor<T>
impl<T> FromIterator<T> for Tensor<T>
sourcefn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Creates a value from an iterator. Read more
sourceimpl<'a, T> TensorList<'a> for &'a Tensor<T> where
T: AsElementType,
impl<'a, T> TensorList<'a> for &'a Tensor<T> where
T: AsElementType,
type ConstElementPtrBuffer = [*const u8; 1]
type ShapeBuffer = [Shape<'a>; 1]
sourcefn shape_list(&self) -> Self::ShapeBuffer
fn shape_list(&self) -> Self::ShapeBuffer
sourcefn element_ptr(&self) -> Self::ConstElementPtrBuffer
fn element_ptr(&self) -> Self::ConstElementPtrBuffer
sourceimpl<T> TensorListMut for Tensor<T> where
T: AsElementType + Default + Clone,
impl<T> TensorListMut for Tensor<T> where
T: AsElementType + Default + Clone,
type MutElementPtrBuffer = [*mut u8; 1]
sourcefn new_tensors(shape: &[Shape<'_>]) -> Self
fn new_tensors(shape: &[Shape<'_>]) -> Self
Create a new set of empty tensors with the specified shape. Read more
sourcefn element_ptr_mut(&mut self) -> Self::MutElementPtrBuffer
fn element_ptr_mut(&mut self) -> Self::MutElementPtrBuffer
Get a set of mutable pointers into each tensor’s backing buffer.
impl<T> StructuralPartialEq for Tensor<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for Tensor<T> where
T: RefUnwindSafe,
impl<T> Send for Tensor<T> where
T: Send + Sync,
impl<T> Sync for Tensor<T> where
T: Send + Sync,
impl<T> Unpin for Tensor<T>
impl<T> UnwindSafe for Tensor<T> where
T: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more