topos 0.13.1

An autodiff compiler stack in Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use crate::{Shape, Tensor};

/// A leaf node: a network input or constant supplied at recording time.
///
/// It holds its payload directly. It is supplied rather than computed —
/// `Op`'s dispatch reproduces the payload during forward and
/// routes no gradients back, since leaves are where gradients stop and
/// get read out.
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct Leaf<Data>(pub(crate) Data);

impl<E> Leaf<Tensor<E>> {
    /// Infers the shape of the result: the payload's own shape.
    pub(crate) fn infer_shape(&self) -> Shape {
        self.0.shape()
    }
}