pub struct TensorShapeInference { /* private fields */ }Expand description
Static shape inference engine for tensor operation graphs.
Tracks how many rules have been applied and how many errors occurred.
Implementations§
Source§impl TensorShapeInference
impl TensorShapeInference
Sourcepub fn infer(&mut self, rule: &InferenceRule) -> Result<TensorShape, String>
pub fn infer(&mut self, rule: &InferenceRule) -> Result<TensorShape, String>
Infer the output shape for a given inference rule.
Sourcepub fn broadcast_shape(
a: &TensorShape,
b: &TensorShape,
) -> Result<TensorShape, String>
pub fn broadcast_shape( a: &TensorShape, b: &TensorShape, ) -> Result<TensorShape, String>
Compute the broadcast-compatible output shape of two tensors following NumPy broadcasting rules.
Rules:
- Shapes are right-aligned.
- Dimensions are compatible when they are equal, or one of them is 1.
- The output dimension is the maximum of the two.
Sourcepub fn matmul_shape(
a: &TensorShape,
b: &TensorShape,
) -> Result<TensorShape, String>
pub fn matmul_shape( a: &TensorShape, b: &TensorShape, ) -> Result<TensorShape, String>
Compute the output shape of a matrix multiplication.
For 2-D inputs (M, K) and (K, N), the output is (M, N).
For higher-rank inputs the batch dimensions must be broadcast-compatible
and the last two dimensions follow the matrix multiplication rule.
Sourcepub fn reshape_shape(
input: &TensorShape,
new_dims: &[usize],
) -> Result<TensorShape, String>
pub fn reshape_shape( input: &TensorShape, new_dims: &[usize], ) -> Result<TensorShape, String>
Verify that new_dims has the same total number of elements as input
and return the reshaped tensor shape.
Sourcepub fn transpose_shape(input: &TensorShape) -> TensorShape
pub fn transpose_shape(input: &TensorShape) -> TensorShape
Return the shape with dimensions reversed (general transpose).
Sourcepub fn concat_shape(
inputs: &[TensorShape],
axis: usize,
) -> Result<TensorShape, String>
pub fn concat_shape( inputs: &[TensorShape], axis: usize, ) -> Result<TensorShape, String>
Concatenate inputs along axis. All dimensions except axis must
match across all inputs.
Sourcepub fn slice_shape(
input: &TensorShape,
axis: usize,
start: usize,
end: usize,
) -> Result<TensorShape, String>
pub fn slice_shape( input: &TensorShape, axis: usize, start: usize, end: usize, ) -> Result<TensorShape, String>
Slice input along axis from start (inclusive) to end
(exclusive).
Sourcepub fn total_elements(shape: &TensorShape) -> usize
pub fn total_elements(shape: &TensorShape) -> usize
Total number of elements in a shape (product of dimensions). Returns 1 for a scalar (empty dims).
Sourcepub fn is_scalar(shape: &TensorShape) -> bool
pub fn is_scalar(shape: &TensorShape) -> bool
Whether the shape represents a scalar: either empty dims or every dimension is 1.
Sourcepub fn stats(&self) -> ShapeInferenceStats
pub fn stats(&self) -> ShapeInferenceStats
Return collected statistics.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TensorShapeInference
impl RefUnwindSafe for TensorShapeInference
impl Send for TensorShapeInference
impl Sync for TensorShapeInference
impl Unpin for TensorShapeInference
impl UnsafeUnpin for TensorShapeInference
impl UnwindSafe for TensorShapeInference
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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>
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