class Num::Grad::Context(T)

Defined in:

grad/primitives/context.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new #

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


[View source]

Instance Method Detail

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

[View source]
def no_grad : Bool #

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


[View source]
def nodes : Array(Num::Grad::Node(T)) #

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


[View source]
def 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]
def 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]
def 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]