Skip to content

class Num::Grad::Context(T)
inherits Reference #

Constructors#

.new #

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

View source

Methods#

#last : Num::Grad::Node(T) #

View source

#no_grad : Bool #

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

View source

#nodes : Array(Num::Grad::Node(T)) #

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

View 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)
View 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])
View 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)
View source