Skip to content

Commit

Permalink
Eliminate context_ptr::head()
Browse files Browse the repository at this point in the history
  • Loading branch information
bredelings committed Jul 3, 2024
1 parent 1175df5 commit 8dce993
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/computation/param.H
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public:
int size() const;
context_ptr operator[](int i) const;
expression_ref operator()(const expression_ref& x) const;
expression_ref head() const;
expression_ref value() const;
context_ptr list_element(int i) const;
EVector list_to_vector() const;
Expand Down
13 changes: 5 additions & 8 deletions src/computation/param.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ context_ptr context_ptr::list_element(int index) const

expression_ref context_ptr::value() const
{
return result().head();
// return result().head();

auto [_, r] = C.incremental_evaluate(reg);
assert(r>0);
return C.memory()->expression_at(r).head();
}

EVector context_ptr::list_to_vector() const
Expand Down Expand Up @@ -195,13 +199,6 @@ int context_ptr::size() const
return C.memory()->expression_at(r).size();
}

expression_ref context_ptr::head() const
{
auto [_, r] = C.incremental_evaluate(reg);
assert(r>0);
return C.memory()->expression_at(r).head();
}

context_ptr::context_ptr(const context_ref& c, int i)
:C(c)
{
Expand Down
16 changes: 8 additions & 8 deletions src/models/TreeInterface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,25 @@ tree_constants::tree_constants(context_ref& C, int tree_reg)

//------------------------- Create the tree structure -----------------------//

while(not has_constructor(tree.head(), "Graph.Graph"))
while(not has_constructor(tree.value(), "Graph.Graph"))
{
if (has_constructor(tree.head(), "Graph.WithBranchLengths"))
if (has_constructor(tree.value(), "Graph.WithBranchLengths"))
{
// We assume that the path to the array isn't changeable... ???
branch_durations_reg = tree[1].result().get_reg();

tree = tree[0];
}

if (has_constructor(tree.head(), "Forest.WithNodeTimes"))
if (has_constructor(tree.value(), "Forest.WithNodeTimes"))
{
// We assume that the path to the array isn't changeable... ???
node_times_reg = tree[1].result().get_reg();

tree = tree[0];
}

if (has_constructor(tree.head(), "Graph.WithLabels"))
if (has_constructor(tree.value(), "Graph.WithLabels"))
{
assert(tree.size() == 2);
// FIXME - set labels!
Expand All @@ -70,7 +70,7 @@ tree_constants::tree_constants(context_ref& C, int tree_reg)
tree = tree[0];
}

if (has_constructor(tree.head(), "Forest.WithRoots"))
if (has_constructor(tree.value(), "Forest.WithRoots"))
{
assert(tree.size() == 3);

Expand All @@ -83,18 +83,18 @@ tree_constants::tree_constants(context_ref& C, int tree_reg)
tree = tree[0];
}

if (has_constructor(tree.head(), "Tree.Tree"))
if (has_constructor(tree.value(), "Tree.Tree"))
{
tree = tree[0];
}

if (has_constructor(tree.head(), "Forest.Forest"))
if (has_constructor(tree.value(), "Forest.Forest"))
{
tree = tree[0];
}
}

assert(has_constructor(tree.head(),"Graph.Graph"));
assert(has_constructor(tree.value(),"Graph.Graph"));
assert(tree.size() == 5);

auto edges_out_of_node = tree[0];
Expand Down

0 comments on commit 8dce993

Please sign in to comment.