Turi Create  4.0
turi::lazy_eval_operation_dag< T > Class Template Reference

#include <core/storage/lazy_eval/lazy_eval_operation_dag.hpp>

Public Member Functions

future_typeadd_value (value_type *value)
 
future_typeadd_operation (operation_type *operation, const std::vector< future_type *> &parents)
 
std::shared_ptr< value_type > make_eager (size_t vertex_id)
 
void mark_for_deletion (size_t vertex_id)
 
void uncache (size_t vertex_id)
 
void cleanup (bool avoid_instantiation=false)
 
 ~lazy_eval_operation_dag ()
 destructor
 

Detailed Description

template<typename T>
class turi::lazy_eval_operation_dag< T >

The Lazy Evaluation Operation DAG is a directed acyclic graph connecting immutable objects of type T with operations, and also provide lazy evaluation primitives to provide object computation at any point in the tree.

Using the lazy_eval_operation_dag system simply requires the user to implement a collection of operations, each inheriting from lazy_eval_operation_base<T>. For instance, we can define the following multiply, increment, and set_val lazy operations on integers.

struct multiplier: lazy_eval_operation_base<int> {
virtual size_t num_arguments() { return 2; }
virtual void execute(int& output,
const std::vector<int*>& parents) {
output *= *(parents[0]);
}
};
struct increment: lazy_eval_operation_base<int> {
virtual size_t num_arguments() { return 1; }
virtual void execute(int& output,
const std::vector<int*>& parents) {
output++;
}
};
struct set_val: lazy_eval_operation_base<int> {
set_val(int i): val(i) { }
size_t val;
virtual size_t num_arguments() { return 0; }
virtual void execute(int& output,
const std::vector<int*>& parents) {
output = val;
}
};

To create a sequence of lazy operations simply involves the use of the add_operation() function. Each call to add_operation is lazy, and returns a future object.

lazy_eval_operation_dag<int> dag;
lazy_eval_future<int>* five = dag.add_operation(new set_val(5), {});
lazy_eval_future<int>* two = dag.add_operation(new set_val(2), {});
lazy_eval_future<int>* seven = dag.add_operation(new adder, {five, two});
lazy_eval_future<int>* nine = dag.add_operation(new adder, {seven, two});

We can then evaluate values with the operator() to compute the DAG.

int val = (*nine)();

Definition at line 21 of file lazy_eval_operation_dag.hpp.

Member Function Documentation

◆ add_operation()

template<typename T>
future_type* turi::lazy_eval_operation_dag< T >::add_operation ( operation_type operation,
const std::vector< future_type *> &  parents 
)
inline

Creates a new entry in the dependency tree by creating a future which corresponds to calling the provided operation on the parents.

Deleting the returned future pointer will mark the corresponding entry in the DAG for deletion.

Definition at line 213 of file lazy_eval_operation_dag.hpp.

◆ add_value()

template<typename T>
future_type* turi::lazy_eval_operation_dag< T >::add_value ( value_type *  value)
inline

Adds a fixed value to the DAG. The returned future pointer will always be available efficiently, Deleting the returned future pointer will mark the corresponding entry in the DAG for deletion.

Definition at line 190 of file lazy_eval_operation_dag.hpp.

◆ cleanup()

template<typename T>
void turi::lazy_eval_operation_dag< T >::cleanup ( bool  avoid_instantiation = false)
inline

Attempts to delete all vertices that were marked for deletion (see mark_for_deletion()). Note that not all marked vertices may be deleted as some vertices (for instance, in the middle of a chain of operations) cannot be deleted safely. This may result in the making eager of certain vertices to ensure that referenced vertices can always be constructed.

Parameters
avoid_instantiationCancel the deletion if it involves instantiating an as yet, uninstantiated vertex.

Definition at line 303 of file lazy_eval_operation_dag.hpp.

◆ make_eager()

template<typename T>
std::shared_ptr<value_type> turi::lazy_eval_operation_dag< T >::make_eager ( size_t  vertex_id)
inline

Computes and caches a particular entry in the graph

Definition at line 236 of file lazy_eval_operation_dag.hpp.

◆ mark_for_deletion()

template<typename T>
void turi::lazy_eval_operation_dag< T >::mark_for_deletion ( size_t  vertex_id)
inline

Marks the vertex for deletion. Deletion will only occur on a call to cleanup()

Definition at line 271 of file lazy_eval_operation_dag.hpp.

◆ uncache()

template<typename T>
void turi::lazy_eval_operation_dag< T >::uncache ( size_t  vertex_id)
inline

If the vertex value is cached, this will force it to be uncached.

Definition at line 284 of file lazy_eval_operation_dag.hpp.


The documentation for this class was generated from the following file: