Constant

Struct Constant 

Source
pub struct Constant<S: Shaped + IntoSpec>(pub S);
Expand description

Source node for numerical constants.

This node implements both Function and Differentiable. The former simply returns the wrapped value, and the latter returns an instance of ConstantAdjoint that handles (empty) buffer shaping.

§Examples

let cns = Constant([10.0, 10.0]);
let jac = cns.adjoint(X);

assert_eq!(cns.evaluate(ctx!{X = [1.0, 2.0]}).unwrap(), [10.0, 10.0]);
assert_eq!(jac.evaluate(ctx!{X = [1.0, 2.0]}).unwrap(), [
    [0.0, 0.0],
    [0.0, 0.0]
]);

Tuple Fields§

§0: S

Trait Implementations§

Source§

impl<S: Clone + Shaped + IntoSpec> Clone for Constant<S>

Source§

fn clone(&self) -> Constant<S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, S> Contains<T> for Constant<S>
where T: Identifier, S: Shaped + IntoSpec,

Source§

fn contains(&self, _: T) -> bool

Returns true if the identifier is present in the expression.
Source§

impl<B> Debug for Constant<B>
where B: Buffer + Debug, B::Field: Debug, B::Shape: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, B> Differentiable<T> for Constant<B>
where T: Identifier, B: Buffer, FieldOf<B>: Zero,

Source§

type Adjoint = ConstantAdjoint<Constant<B>, T>

The adjoint operator; i.e. the gradient.
Source§

fn adjoint(&self, ident: T) -> Self::Adjoint

Transform the node into its Adjoint operator tree. Read more
Source§

fn evaluate_adjoint<C: Context, CR: AsRef<C>>( &self, target: T, ctx: CR, ) -> AegirResult<Self::Adjoint, C>
where Self: Function<C>, Self::Adjoint: Function<C>,

Helper method that computes the adjoint and evaluates its value. Read more
Source§

fn evaluate_dual<C: Context, CR: AsRef<C>>( &self, target: T, ctx: CR, ) -> Result<DualOf<Self, C, T>, BinaryError<Self::Error, <AdjointOf<Self, T> as Function<C>>::Error, NoError>>
where Self: Function<C>, Self::Adjoint: Function<C>,

Helper method that evaluates the function and its adjoint, wrapping up in a Dual.
Source§

impl<B: Buffer + ToString> Display for Constant<B>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C, S> Function<C> for Constant<S>
where C: Context, S: Clone + Shaped + IntoSpec, S::Buffer: Shaped<Shape = S::Shape>,

Source§

type Error = SourceError<()>

The error type of the function.
Source§

type Value = <S as IntoSpec>::Buffer

The codomain of the function.
Source§

fn evaluate<CR: AsRef<C>>(&self, ctx: CR) -> Result<S::Buffer, Self::Error>

Evaluate the function and return its Value. Read more
Source§

fn evaluate_spec<CR: AsRef<C>>( &self, _: CR, ) -> Result<Spec<S::Buffer>, Self::Error>

Evaluate the function and return its lifted Value. Read more
Source§

fn evaluate_shape<CR: AsRef<C>>(&self, _: CR) -> Result<S::Shape, Self::Error>

Evaluate the function and return the shape of the Value. Read more
Source§

impl<S: Shaped + IntoSpec> Node for Constant<S>

Source§

fn add<N: Node>(self, other: N) -> Add<Self, N>
where Self: Sized,

Source§

fn sub<N: Node>(self, other: N) -> Sub<Self, N>
where Self: Sized,

Source§

fn mul<N: Node>(self, other: N) -> Mul<Self, N>
where Self: Sized,

Source§

fn div<N: Node>(self, other: N) -> Div<Self, N>
where Self: Sized,

Source§

fn dot<N: Node>(self, other: N) -> TensorDot<Self, N>
where Self: Sized,

Source§

fn abs(self) -> Abs<Self>
where Self: Sized,

Source§

fn neg(self) -> Negate<Self>
where Self: Sized,

Source§

fn pow<P>(self, power: P) -> Power<Self, P>
where Self: Sized,

Source§

fn ln(self) -> Ln<Self>
where Self: Sized,

Source§

fn squared(self) -> Square<Self>
where Self: Sized,

Source§

fn sum(self) -> Sum<Self>
where Self: Sized,

Source§

fn sigmoid(self) -> Sigmoid<Self>
where Self: Sized,

Source§

impl<S: PartialEq + Shaped + IntoSpec> PartialEq for Constant<S>

Source§

fn eq(&self, other: &Constant<S>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<B: Buffer + ToString> ToExpr for Constant<B>

Source§

fn to_expr(&self) -> Expr

Convert the node to an expression string. Read more
Source§

impl<S: Copy + Shaped + IntoSpec> Copy for Constant<S>

Source§

impl<S: Eq + Shaped + IntoSpec> Eq for Constant<S>

Source§

impl<S: Shaped + IntoSpec> StructuralPartialEq for Constant<S>

Auto Trait Implementations§

§

impl<S> Freeze for Constant<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for Constant<S>
where S: RefUnwindSafe,

§

impl<S> Send for Constant<S>
where S: Send,

§

impl<S> Sync for Constant<S>
where S: Sync,

§

impl<S> Unpin for Constant<S>
where S: Unpin,

§

impl<S> UnwindSafe for Constant<S>
where S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.