Skip to content

Instantly share code, notes, and snippets.

@ryanrhymes
Created November 24, 2017 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanrhymes/c31dc124814a7549df3abdad904272bf to your computer and use it in GitHub Desktop.
Save ryanrhymes/c31dc124814a7549df3abdad904272bf to your computer and use it in GitHub Desktop.
(* find the root inputs of [x] *)
let find_roots x =
let s = Owl_utils.Stack.make () in
let rec _find x =
Array.iter (fun n ->
if n.op = Noop then Owl_utils.Stack.push s n
else _find n
) x.prev
in
_find x;
Owl_utils.Stack.to_array s
(* update [x]'s dependency graph by invalidating stale nodes *)
let update_graph x =
let rec _update x =
let valid = ref (is_valid x) in
Array.iter (fun n ->
valid := !valid || _update n
) x.prev;
if !valid = false then invalidate x;
!valid
in
_update x |> ignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment