pub struct Tensor<D: Scalar, Mapping: M> { /* private fields */ }Expand description
Tensor with scalar type D with axes determined by Mapping.
Implementations§
Source§impl<D: Scalar, Mapping: M> Tensor<D, Mapping>
impl<D: Scalar, Mapping: M> Tensor<D, Mapping>
Sourcepub fn to_buf(&self) -> Vec<Opt<D>>
pub fn to_buf(&self) -> Vec<Opt<D>>
Returns the tensor data as a flat vector in the physical layout order defined by Mapping.
Sourcepub fn rand(rng: &mut impl Rng) -> Selfwhere
StandardUniform: Distribution<D>,
pub fn rand(rng: &mut impl Rng) -> Selfwhere
StandardUniform: Distribution<D>,
Creates a random tensor.
Sourcepub fn view_mut<'l>(&'l mut self) -> TensorViewMut<'l, D, Mapping>
pub fn view_mut<'l>(&'l mut self) -> TensorViewMut<'l, D, Mapping>
Creates a mutable view of the tensor.
Sourcepub fn view<'l>(&'l self) -> TensorView<'l, D, Mapping>
pub fn view<'l>(&'l self) -> TensorView<'l, D, Mapping>
Creates an immutable view of the tensor.
Sourcepub fn data_mut(&mut self) -> &mut ArrayD<Opt<D>>
pub fn data_mut(&mut self) -> &mut ArrayD<Opt<D>>
Returns a mutable reference to the underlying data array.
Sourcepub unsafe fn transmute<Mapping2: M>(self) -> Tensor<D, Mapping2>
pub unsafe fn transmute<Mapping2: M>(self) -> Tensor<D, Mapping2>
Transmutes the tensor to a different mapping.
§Safety
The caller must ensure that the underlying data layout is compatible with the new mapping.
Sourcepub unsafe fn reshape<Src: M, Dst: M, Mapping2: M>(self) -> Tensor<D, Mapping2>
pub unsafe fn reshape<Src: M, Dst: M, Mapping2: M>(self) -> Tensor<D, Mapping2>
Reshapes the tensor to a different mapping. change Src into Dst, final mapping is Mapping2.
§Safety
TODO(jeongmin.park); document safety.
Sourcepub fn zip_with<D2: Scalar, D3: Scalar, F>(
&self,
other: &Tensor<D2, Mapping>,
f: F,
) -> Tensor<D3, Mapping>
pub fn zip_with<D2: Scalar, D3: Scalar, F>( &self, other: &Tensor<D2, Mapping>, f: F, ) -> Tensor<D3, Mapping>
Zips two tensors with a function.
Sourcepub fn reduce_add<Dst: M>(&self) -> Tensor<D, Dst>
pub fn reduce_add<Dst: M>(&self) -> Tensor<D, Dst>
Performs reduction (sum) over axes not present in Dst.
Sourcepub fn reduce<Dst: M>(
&self,
reduce_fn: impl Fn(Opt<D>, Opt<D>) -> Opt<D>,
identity: Opt<D>,
) -> Tensor<D, Dst>
pub fn reduce<Dst: M>( &self, reduce_fn: impl Fn(Opt<D>, Opt<D>) -> Opt<D>, identity: Opt<D>, ) -> Tensor<D, Dst>
Reduces axes present in self but absent in Dst, using a custom reduce function.
Sourcepub fn reduce_then_broadcast<Dst: M>(&self) -> Tensor<D, Dst>
pub fn reduce_then_broadcast<Dst: M>(&self) -> Tensor<D, Dst>
Performs reduction followed by broadcasting to match destination axes. This is useful when the destination has broadcast axes that should be preserved.
§Examples
let src: Tensor<f32, m![ABCD]> = Tensor::from_vec(...); // Shape: ABCD
let dst: Tensor<f32, m![ABE]> = src.reduce_then_broadcast(); // Reduces CD, broadcasts to ABESourcepub fn reduce_then_broadcast_with<Dst: M>(
&self,
reduce_fn: impl Fn(Opt<D>, Opt<D>) -> Opt<D>,
identity: Opt<D>,
) -> Tensor<D, Dst>
pub fn reduce_then_broadcast_with<Dst: M>( &self, reduce_fn: impl Fn(Opt<D>, Opt<D>) -> Opt<D>, identity: Opt<D>, ) -> Tensor<D, Dst>
Performs reduction with a custom function, followed by broadcasting to match destination axes.
Trait Implementations§
Auto Trait Implementations§
impl<D, Mapping> Freeze for Tensor<D, Mapping>
impl<D, Mapping> RefUnwindSafe for Tensor<D, Mapping>where
Mapping: RefUnwindSafe,
D: RefUnwindSafe,
impl<D, Mapping> Send for Tensor<D, Mapping>
impl<D, Mapping> Sync for Tensor<D, Mapping>
impl<D, Mapping> Unpin for Tensor<D, Mapping>
impl<D, Mapping> UnwindSafe for Tensor<D, Mapping>
Blanket Implementations§
§impl<T> AlignerFor<1> for T
impl<T> AlignerFor<1> for T
§impl<T> AlignerFor<1024> for T
impl<T> AlignerFor<1024> for T
§impl<T> AlignerFor<128> for T
impl<T> AlignerFor<128> for T
§impl<T> AlignerFor<16> for T
impl<T> AlignerFor<16> for T
§impl<T> AlignerFor<16384> for T
impl<T> AlignerFor<16384> for T
§impl<T> AlignerFor<2> for T
impl<T> AlignerFor<2> for T
§impl<T> AlignerFor<2048> for T
impl<T> AlignerFor<2048> for T
§impl<T> AlignerFor<256> for T
impl<T> AlignerFor<256> for T
§impl<T> AlignerFor<32> for T
impl<T> AlignerFor<32> for T
§impl<T> AlignerFor<32768> for T
impl<T> AlignerFor<32768> for T
§impl<T> AlignerFor<4> for T
impl<T> AlignerFor<4> for T
§impl<T> AlignerFor<4096> for T
impl<T> AlignerFor<4096> for T
§impl<T> AlignerFor<512> for T
impl<T> AlignerFor<512> for T
§impl<T> AlignerFor<64> for T
impl<T> AlignerFor<64> for T
§impl<T> AlignerFor<8> for T
impl<T> AlignerFor<8> for T
§impl<T> AlignerFor<8192> for T
impl<T> AlignerFor<8192> for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<'a, T> RCowCompatibleRef<'a> for Twhere
T: Clone + 'a,
impl<'a, T> RCowCompatibleRef<'a> for Twhere
T: Clone + 'a,
§impl<S> ROExtAcc for S
impl<S> ROExtAcc for S
§fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
offset. Read more§fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
offset. Read more§fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
offset. Read more§fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
offset. Read more§impl<S> ROExtOps<Aligned> for S
impl<S> ROExtOps<Aligned> for S
§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
offset) with value,
returning the previous value of the field. Read more§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
§impl<S> ROExtOps<Unaligned> for S
impl<S> ROExtOps<Unaligned> for S
§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
offset) with value,
returning the previous value of the field. Read more§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
§impl<T> SelfOps for Twhere
T: ?Sized,
impl<T> SelfOps for Twhere
T: ?Sized,
§fn piped<F, U>(self, f: F) -> U
fn piped<F, U>(self, f: F) -> U
§fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
piped except that the function takes &Self
Useful for functions that take &Self instead of Self. Read more§fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
piped, except that the function takes &mut Self.
Useful for functions that take &mut Self instead of Self.§fn mutated<F>(self, f: F) -> Self
fn mutated<F>(self, f: F) -> Self
§fn observe<F>(self, f: F) -> Self
fn observe<F>(self, f: F) -> Self
§fn as_ref_<T>(&self) -> &T
fn as_ref_<T>(&self) -> &T
AsRef,
using the turbofish .as_ref_::<_>() syntax. Read more