Struct hotg_rune_proc_blocks::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, Global>
) -> Tensor<T>
pub fn new_vector(iter: impl IntoIterator<Item = T>) -> Tensor<T>
pub fn single(value: T) -> Tensor<T>
pub fn zeroed(dimensions: Vec<usize, Global>) -> Tensor<T> where
T: Default,
pub fn filled_with<F>(dimensions: Vec<usize, Global>, f: F) -> Tensor<T> 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, const RANK: usize>(
&'this mut self
) -> Option<TensorViewMut<'a, T, RANK>> where
'this: 'a,
T: Clone,
pub fn view_mut<'a, 'this, const RANK: usize>(
&'this mut self
) -> Option<TensorViewMut<'a, T, RANK>> where
'this: 'a,
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> for Tensor<T> where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Tensor<T> where
T: Deserialize<'de>,
sourcepub fn deserialize<D>(
de: D
) -> Result<Tensor<T>, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
pub fn deserialize<D>(
de: D
) -> Result<Tensor<T>, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<Element, 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> where
Element: Clone,
impl<Element, 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> where
Element: Clone,
sourceimpl<Element, 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> where
Element: Clone,
impl<Element, 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> where
Element: Clone,
sourceimpl<Element, 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> where
Element: Clone,
impl<Element, 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> where
Element: Clone,
sourceimpl<Element, 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> where
Element: Clone,
impl<Element, 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> where
Element: Clone,
sourceimpl<Element, const A: usize, const B: usize, const C: usize, const D: usize> From<[[[[Element; D]; C]; B]; A]> for Tensor<Element> where
Element: Clone,
impl<Element, const A: usize, const B: usize, const C: usize, const D: usize> From<[[[[Element; D]; C]; B]; A]> for Tensor<Element> where
Element: Clone,
sourceimpl<T, const WIDTH: usize, const HEIGHT: usize, const DEPTH: usize> From<[[[T; WIDTH]; HEIGHT]; DEPTH]> for Tensor<T> where
T: Clone,
impl<T, const WIDTH: usize, const HEIGHT: usize, const DEPTH: usize> From<[[[T; WIDTH]; HEIGHT]; DEPTH]> for Tensor<T> where
T: Clone,
sourceimpl<T, const WIDTH: usize, const HEIGHT: usize> From<[[T; WIDTH]; HEIGHT]> for Tensor<T> where
T: Clone,
impl<T, const WIDTH: usize, const HEIGHT: usize> From<[[T; WIDTH]; HEIGHT]> for Tensor<T> where
T: Clone,
sourceimpl<T> FromIterator<T> for Tensor<T>
impl<T> FromIterator<T> for Tensor<T>
sourcepub fn from_iter<I>(iter: I) -> Tensor<T> where
I: IntoIterator<Item = T>,
pub fn from_iter<I>(iter: I) -> Tensor<T> where
I: IntoIterator<Item = T>,
Creates a value from an iterator. Read more
sourceimpl<T> Serialize for Tensor<T> where
T: Serialize,
impl<T> Serialize for Tensor<T> where
T: Serialize,
sourcepub fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
pub fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
Serialize this value into the given Serde serializer. 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]
sourcepub fn shape_list(&self) -> <&'a Tensor<T> as TensorList<'a>>::ShapeBuffer
pub fn shape_list(&self) -> <&'a Tensor<T> as TensorList<'a>>::ShapeBuffer
sourcepub fn element_ptr(
&self
) -> <&'a Tensor<T> as TensorList<'a>>::ConstElementPtrBuffer
pub fn element_ptr(
&self
) -> <&'a Tensor<T> as TensorList<'a>>::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]
sourcepub fn new_tensors(shape: &[Shape<'_>]) -> Tensor<T>
pub fn new_tensors(shape: &[Shape<'_>]) -> Tensor<T>
Create a new set of empty tensors with the specified shape. Read more
sourcepub fn element_ptr_mut(
&mut self
) -> <Tensor<T> as TensorListMut>::MutElementPtrBuffer
pub fn element_ptr_mut(
&mut self
) -> <Tensor<T> as TensorListMut>::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