pub struct BroadcastShape {
pub shape: Vec<usize>,
}Expand description
NumPy-style broadcast compatibility checker and stride generator.
§Examples
use ipfrs_tensorlogic::slice_view::BroadcastShape;
let bs = BroadcastShape { shape: vec![1, 3] };
assert!(bs.compatible_with(&[4, 3]));
let strides = bs.broadcast_to(&[4, 3]).expect("example: should succeed in docs");
assert_eq!(strides, vec![0, 1]);Fields§
§shape: Vec<usize>The source shape to be broadcast.
Implementations§
Source§impl BroadcastShape
impl BroadcastShape
Sourcepub fn compatible_with(&self, other: &[usize]) -> bool
pub fn compatible_with(&self, other: &[usize]) -> bool
Check NumPy-style broadcast compatibility with other.
Dimensions are aligned from the right. Each pair (a, b) must satisfy:
a == b, a == 1, or b == 1.
Sourcepub fn broadcast_to(&self, target: &[usize]) -> Option<Vec<usize>>
pub fn broadcast_to(&self, target: &[usize]) -> Option<Vec<usize>>
Compute the broadcast strides needed to view self as target.
A source dimension of size 1 gets stride 0 (it is repeated along
that axis without touching memory). Equal dimensions get the natural
row-major stride computed from the source shape.
Returns None if the shapes are not compatible.
Trait Implementations§
Source§impl Clone for BroadcastShape
impl Clone for BroadcastShape
Source§fn clone(&self) -> BroadcastShape
fn clone(&self) -> BroadcastShape
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for BroadcastShape
impl Debug for BroadcastShape
impl Eq for BroadcastShape
Source§impl PartialEq for BroadcastShape
impl PartialEq for BroadcastShape
Source§fn eq(&self, other: &BroadcastShape) -> bool
fn eq(&self, other: &BroadcastShape) -> bool
Tests for
self and other values to be equal, and is used by ==.impl StructuralPartialEq for BroadcastShape
Auto Trait Implementations§
impl Freeze for BroadcastShape
impl RefUnwindSafe for BroadcastShape
impl Send for BroadcastShape
impl Sync for BroadcastShape
impl Unpin for BroadcastShape
impl UnsafeUnpin for BroadcastShape
impl UnwindSafe for BroadcastShape
Blanket Implementations§
impl<T> Allocation 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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
Converts
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>
Converts
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