Enum drug::nodes::Node

source ·
pub enum Node {
    Input {
        it: Option<Box<dyn Iterator<Item = ArrayD<f32>>>>,
    },
    Parameter(Box<[usize]>),
    Conv {
        kernel: Idx,
        img: Idx,
        conv: Conv,
    },
    Add {
        xs: Vec<Idx>,
    },
    Mult {
        xs: Vec<Idx>,
    },
    MatMul {
        mat: Idx,
        v: Idx,
    },
    Activation {
        x: Idx,
        a: Activation,
    },
    Embedding {
        emb: Idx,
        code: Idx,
    },
    GlobalPool {
        pool: GlobalPool,
        x: Idx,
    },
    Operation {
        inputs: Box<[Idx]>,
        operation: Box<dyn Operation>,
    },
    Constant,
}
Expand description

Nodes are the building blocks of the computation graph. The variants of a node differ in how the value is produced and how loss is propagated back. Users typically interact with Nodes with their index :Idx which is returned by the graph when registered / created.

Variants§

§

Input

Fields

§it: Option<Box<dyn Iterator<Item = ArrayD<f32>>>>

Produce Value from beyond the graph.

  • In a forward pass, its value is updates by the iterator or panics if its None
  • In a backward pass, its losses are currently calculated but unused.
  • When serializing, the internal iterator is ignored. It deserializes to None.
§

Parameter(Box<[usize]>)

Parameter nodes only hold a shape. Its values are initialized when inserted into the graph using the graph’s initializer.

  • In a foward pass, parameters are ignored.
  • In a backward pass, their losses are applied by the graph’s optimizer.
§

Conv

Fields

§kernel: Idx
§img: Idx
§conv: Conv

See Conv for more.

§

Add

Fields

§xs: Vec<Idx>

See Add for more.

§

Mult

Fields

§xs: Vec<Idx>

See Mult for more.

§

MatMul

Fields

§mat: Idx
§v: Idx

See Matmul for more.

§

Activation

Fields

§x: Idx

See Activation for more.

§

Embedding

Fields

§emb: Idx
§code: Idx

See Embedding for more.

§

GlobalPool

Fields

§x: Idx

See GlobalPool for more.

§

Operation

Fields

§inputs: Box<[Idx]>
§operation: Box<dyn Operation>

An Operation node holds an Operation trait object and the indices referring to its input values.

  • In a forward pass, its value is updated by the operation and the values indexed by inputs.
  • In a backward pass, gradients are calculated and losses are propagated backwards and added to the losses indexed by inputs.
§

Constant

Ignored by the graph, you have to set the values yourself

Implementations§

Trait Implementations§

Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.