Skip to content

Commit

Permalink
Updated autograd tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ulises-jeremias committed Jul 8, 2023
1 parent d3a915b commit 9eb16b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions autograd/context.v
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@ pub fn (mut ctx Context[T]) push[T](node &Node[T]) {
ctx.nodes << node
}

pub fn (ctx &Context[T]) last[T]() &Node[T] {
pub fn (ctx &Context[T]) last[T]() !&Node[T] {
if ctx.nodes.len == 0 {
return error(@FN + ': context is empty')
}
return ctx.nodes.last()
}

pub fn (mut ctx Context[T]) pop[T]() &Node[T] {
pub fn (mut ctx Context[T]) pop[T]() !&Node[T] {
if ctx.nodes.len == 0 {
return error(@FN + ': context is empty')
}
return ctx.nodes.pop()
}

Expand Down
6 changes: 3 additions & 3 deletions autograd/variable.v
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ pub fn (v &Variable[T]) str() string {
// Context
pub fn (mut v Variable[T]) backprop[T]() ! {
v.grad = vtl.ones_like[T](v.value)
for v.context.len() > 0 && v.context.last().payload.variable != v {
node := v.context.pop()
for v.context.len() > 0 && v.context.last()!.payload.variable != v {
node := v.context.pop()!
$if debug {
print(node.name)
}
}
for v.context.len() > 0 {
cur_node := v.context.pop()
cur_node := v.context.pop()!
$if debug {
print(cur_node.name)
}
Expand Down

0 comments on commit 9eb16b0

Please sign in to comment.