-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] clarify ordering of nonlinear tape (#2401)
- Loading branch information
Showing
1 changed file
with
12 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -487,12 +487,14 @@ julia> struct Expression | |
``` | ||
|
||
For each node `node` in the `.nodes` field, if `node.type` is: | ||
|
||
* `NODE_CALL_MULTIVARIATE`, we look up | ||
`MULTIVARIATE_OPERATORS[node.index]` to retrieve the operator | ||
* `NODE_CALL_UNIVARIATE`, we look up | ||
`UNIVARIATE_OPERATORS[node.index]` to retrieve the operator | ||
* `NODE_VARIABLE`, we create `MOI.VariableIndex(node.index)` | ||
* `NODE_VALUE`, we look up `values[node.index]` | ||
|
||
The `.parent` field of each node is the integer index of the parent node in | ||
`.nodes`. For the first node, the parent is `-1` by convention. | ||
|
||
|
@@ -511,6 +513,16 @@ julia> expr = Expression( | |
); | ||
``` | ||
|
||
The ordering of the nodes in the tape must satisfy two rules: | ||
|
||
* The children of a node must appear after the parent. This means that the tape | ||
is ordered topologically, so that a reverse pass of the nodes evaluates all | ||
children nodes before their parent | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
odow
Author
Member
|
||
* The arguments for a `CALL` node are ordered in the tape based on the order in | ||
which they appear in the function call. | ||
|
||
#### Design goals | ||
|
||
This is less readable than the other options, but does this data structure meet | ||
our design goals? | ||
|
||
|
@@ -524,9 +536,6 @@ easy to identify the _parent_ of any node. Therefore, we can use | |
[`Nonlinear.adjacency_matrix`](@ref) to compute a sparse matrix that maps | ||
parents to their children. | ||
|
||
The tape is also ordered topologically, so that a reverse pass of the nodes | ||
evaluates all children nodes before their parent. | ||
|
||
### The design in practice | ||
|
||
In practice, `Node` and `Expression` are exactly [`Nonlinear.Node`](@ref) | ||
|
Maybe it's just semantics, but I think saying "The children of a node must appear directly after the parent" is a tad more accurate. Without "directly", you'd give room to intersperse some other node between the node and its children.