class

Num::Grad::Context(T)

Inherits Reference / Object

Constructors

new

Contexts can only be initialized as empty, and a generic type must be provided

Source

Instance methods

last
Source
no_grad

If no_grad is set to true, operations will not be cached, and backpropogation will not be possible

Source
nodes

A list of all variables present in an operation. This list can contain duplicates

Source
variable(value : Number, requires_grad : Bool = true) : Num::Grad::Variable(T)

Creates a new variable within the Context. This variable must be able to be cast to a Tensor of type T.

Arguments

  • value : Number - Number to be monitored
  • requires_grad : Bool - Flag to indicate if operations should be cached for this variable

Examples

ctx = Context(Tensor(Float64)).new
ctx.variable(3.0)
Source
variable(value : Array, requires_grad : Bool = true) : Num::Grad::Variable(T)

Creates a new variable within the Context. This variable must be able to be cast to a Tensor of type T.

Arguments

  • value : Array - Array to be monitored
  • requires_grad : Bool - Flag to indicate if operations should be cached for this variable

Examples

ctx = Context(Tensor(Float64)).new
ctx.variable([1.0, 2.0, 3.0])
Source
variable(value : T, requires_grad : Bool = true) : Num::Grad::Variable(T)

Creates a new variable within the Context. This variable must be able to be cast to a Tensor of type T.

Arguments

  • value : Tensor - Tensor to be monitored
  • requires_grad : Bool - Flag to indicate if operations should be cached for this variable

Examples

ctx = Context(Tensor(Float64)).new
ctx.variable([1.0, 2.0, 3.0].to_tensor)
Source