Graph Framework
Loading...
Searching...
No Matches
graph::leaf_node< T, SAFE_MATH > Class Template Referenceabstract

Class representing a node leaf. More...

#include <node.hpp>

Inheritance diagram for graph::leaf_node< T, SAFE_MATH >:
graph::branch_node< T, SAFE_MATH > graph::constant_node< T, SAFE_MATH > graph::random_state_node< T, SAFE_MATH > graph::straight_node< T, SAFE_MATH > graph::variable_node< T, SAFE_MATH > graph::add_node< T, SAFE_MATH > graph::arctan_node< T, SAFE_MATH > graph::divide_node< T, SAFE_MATH > graph::multiply_node< T, SAFE_MATH > graph::piecewise_2D_node< T, SAFE_MATH > graph::pow_node< T, SAFE_MATH > graph::subtract_node< T, SAFE_MATH > graph::triple_node< T, SAFE_MATH > graph::cosine_node< T, SAFE_MATH > graph::erfi_node< T, SAFE_MATH > graph::exp_node< T, SAFE_MATH > graph::log_node< T, SAFE_MATH > graph::piecewise_1D_node< T, SAFE_MATH > graph::pseudo_variable_node< T, SAFE_MATH > graph::random_node< T, SAFE_MATH > graph::sine_node< T, SAFE_MATH > graph::sqrt_node< T, SAFE_MATH >

Classes

struct  caches_t
 Data structure to contain the two caches. More...
 

Public Types

typedefbase
 Type def to retrieve the backend type.
 

Public Member Functions

 leaf_node (const std::string s, const size_t count, const bool pseudo)
 Construct a basic node.
 
virtual ~leaf_node ()
 Destructor.
 
virtual backend::buffer< T > evaluate ()=0
 Evaluate method.
 
virtual std::shared_ptr< leaf_nodereduce ()=0
 Reduction method.
 
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > df (std::shared_ptr< leaf_node< T, SAFE_MATH > > x)=0
 Transform node to derivative.
 
virtual void compile_preamble (std::ostringstream &stream, jit::register_map &registers, jit::visiter_map &visited, jit::register_usage &usage, jit::texture1d_list &textures1d, jit::texture2d_list &textures2d, int &avail_const_mem)
 Compile preamble.
 
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > compile (std::ostringstream &stream, jit::register_map &registers, jit::register_map &indices, const jit::register_usage &usage)=0
 Compile the node.
 
virtual bool is_match (std::shared_ptr< leaf_node< T, SAFE_MATH > > x)
 Querey if the nodes match.
 
bool is_power_base_match (std::shared_ptr< leaf_node< T, SAFE_MATH > > x)
 Check if the base of the powers match.
 
virtual void set (const T d)
 Set the value of variable data.
 
virtual void set (const size_t index, const T d)
 Set the value of variable data.
 
virtual void set (const std::vector< T > &d)
 Set the value of variable data.
 
virtual void set (const backend::buffer< T > &d)
 Set the value of variable data.
 
virtual void to_latex () const =0
 Convert the node to latex.
 
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > to_vizgraph (std::stringstream &stream, jit::register_map &registers)=0
 Convert the node to vizgraph.
 
virtual bool is_constant () const
 Test if node is a constant.
 
virtual bool has_constant_zero () const
 Test the constant node has a zero.
 
bool is_normal ()
 Test if the result is normal.
 
virtual bool is_all_variables () const =0
 Test if all the subnodes terminate in variables.
 
virtual bool is_power_like () const
 Test if the node acts like a power of variable.
 
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > get_power_base ()
 Get the base of a power.
 
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > get_power_exponent () const =0
 Get the exponent of a power.
 
size_t get_hash () const
 Get the hash for the node.
 
size_t get_complexity () const
 Get the number of nodes in the subgraph.
 
virtual bool has_pseudo () const
 Query if the node contains pseudo variables.
 
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > remove_pseudo ()
 Remove pseudo variable nodes.
 
virtual void endline (std::ostringstream &stream, const jit::register_usage &usage) const final
 End a line in the kernel source.
 

Static Public Attributes

static thread_local caches_t caches
 A per thread instance of the cache structure.
 

Protected Attributes

const size_t hash
 Hash for node.
 
const size_t complexity
 Graph complexity.
 
std::map< size_t, std::shared_ptr< leaf_node< T, SAFE_MATH > > > df_cache
 Cache derivative terms.
 
const bool contains_pseudo
 Node contains pseudo variables.
 

Detailed Description

template<jit::float_scalar T, bool SAFE_MATH = false>
class graph::leaf_node< T, SAFE_MATH >

Class representing a node leaf.

Template Parameters
TBase type of the calculation.
SAFE_MATHUse Safe Math operations.

Constructor & Destructor Documentation

◆ leaf_node()

template<jit::float_scalar T, bool SAFE_MATH = false>
graph::leaf_node< T, SAFE_MATH >::leaf_node ( const std::string  s,
const size_t  count,
const bool  pseudo 
)
inline

Construct a basic node.

Parameters
[in]sNode string to hash.
[in]countNumber of nodes in the subgraph.
[in]pseudoNode contains pseudo variable.

Member Function Documentation

◆ compile()

◆ compile_preamble()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual void graph::leaf_node< T, SAFE_MATH >::compile_preamble ( std::ostringstream &  stream,
jit::register_map registers,
jit::visiter_map visited,
jit::register_usage usage,
jit::texture1d_list textures1d,
jit::texture2d_list textures2d,
int avail_const_mem 
)
inlinevirtual

Compile preamble.

Some nodes require additions to the preamble however most don't so define a generic method that does nothing.

Parameters
[in,out]streamString buffer stream.
[in,out]registersList of defined registers.
[in,out]visitedList of visited nodes.
[in,out]usageList of register usage count.
[in,out]textures1dList of 1D textures.
[in,out]textures2dList of 2D textures.
[in,out]avail_const_memAvailable constant memory.

Reimplemented in graph::straight_node< T, SAFE_MATH >, graph::straight_node< T, false >, graph::branch_node< T, SAFE_MATH >, graph::branch_node< T, false >, graph::branch_node< T, SAFE_MATH >, graph::triple_node< T, SAFE_MATH >, graph::triple_node< T, false >, graph::variable_node< T, SAFE_MATH >, graph::piecewise_1D_node< T, SAFE_MATH >, graph::piecewise_2D_node< T, SAFE_MATH >, graph::random_state_node< T, SAFE_MATH >, and graph::random_node< T, SAFE_MATH >.

◆ df()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > graph::leaf_node< T, SAFE_MATH >::df ( std::shared_ptr< leaf_node< T, SAFE_MATH > >  x)
pure virtual

Transform node to derivative.

Parameters
[in]xThe variable to take the derivative to.
Returns
The derivative of the node.

◆ endline()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual void graph::leaf_node< T, SAFE_MATH >::endline ( std::ostringstream &  stream,
const jit::register_usage usage 
) const
inlinefinalvirtual

End a line in the kernel source.

Parameters
[in,out]streamString buffer stream.
[in]usageList of register usage count.

◆ evaluate()

◆ get_complexity()

template<jit::float_scalar T, bool SAFE_MATH = false>
size_t graph::leaf_node< T, SAFE_MATH >::get_complexity ( ) const
inline

Get the number of nodes in the subgraph.

Returns
The complexity count.

◆ get_hash()

template<jit::float_scalar T, bool SAFE_MATH = false>
size_t graph::leaf_node< T, SAFE_MATH >::get_hash ( ) const
inline

Get the hash for the node.

Returns
The hash for the current node.

◆ get_power_base()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > graph::leaf_node< T, SAFE_MATH >::get_power_base ( )
inlinevirtual

◆ get_power_exponent()

◆ has_constant_zero()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual bool graph::leaf_node< T, SAFE_MATH >::has_constant_zero ( ) const
inlinevirtual

Test the constant node has a zero.

Returns
True the node has a zero constant value.

Reimplemented in graph::constant_node< T, SAFE_MATH >, graph::piecewise_1D_node< T, SAFE_MATH >, and graph::piecewise_2D_node< T, SAFE_MATH >.

◆ has_pseudo()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual bool graph::leaf_node< T, SAFE_MATH >::has_pseudo ( ) const
inlinevirtual

Query if the node contains pseudo variables.

Returns
True if the node contains pseudo variables.

Reimplemented in graph::pseudo_variable_node< T, SAFE_MATH >.

◆ is_all_variables()

◆ is_constant()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual bool graph::leaf_node< T, SAFE_MATH >::is_constant ( ) const
inlinevirtual

Test if node is a constant.

Returns
True if the node is like a constant.

Reimplemented in graph::constant_node< T, SAFE_MATH >, graph::piecewise_1D_node< T, SAFE_MATH >, and graph::piecewise_2D_node< T, SAFE_MATH >.

◆ is_match()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual bool graph::leaf_node< T, SAFE_MATH >::is_match ( std::shared_ptr< leaf_node< T, SAFE_MATH > >  x)
inlinevirtual

Querey if the nodes match.

Parameters
[in]xOther graph to check if it is a match.
Returns
True if the nodes are a match.

◆ is_normal()

template<jit::float_scalar T, bool SAFE_MATH = false>
bool graph::leaf_node< T, SAFE_MATH >::is_normal ( )
inline

Test if the result is normal.

Returns
True if the node is normal.

◆ is_power_base_match()

template<jit::float_scalar T, bool SAFE_MATH = false>
bool graph::leaf_node< T, SAFE_MATH >::is_power_base_match ( std::shared_ptr< leaf_node< T, SAFE_MATH > >  x)
inline

Check if the base of the powers match.

Parameters
[in]xOther graph to check if the bases match.
Returns
True if the powers of the nodes match.

◆ is_power_like()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual bool graph::leaf_node< T, SAFE_MATH >::is_power_like ( ) const
inlinevirtual

Test if the node acts like a power of variable.

Most nodes are not so default to false.

Returns
True the node is power like and false otherwise.

Reimplemented in graph::sqrt_node< T, SAFE_MATH >, graph::pow_node< T, SAFE_MATH >, graph::constant_node< T, SAFE_MATH >, graph::variable_node< T, SAFE_MATH >, graph::pseudo_variable_node< T, SAFE_MATH >, graph::piecewise_1D_node< T, SAFE_MATH >, and graph::piecewise_2D_node< T, SAFE_MATH >.

◆ reduce()

◆ remove_pseudo()

◆ set() [1/4]

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual void graph::leaf_node< T, SAFE_MATH >::set ( const backend::buffer< T > &  d)
inlinevirtual

Set the value of variable data.

Parameters
[in]dBackend buffer data to set.

Reimplemented in graph::variable_node< T, SAFE_MATH >.

◆ set() [2/4]

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual void graph::leaf_node< T, SAFE_MATH >::set ( const size_t  index,
const d 
)
inlinevirtual

Set the value of variable data.

Parameters
[in]indexBuffer index to set value.
[in]dScalar data to set.

Reimplemented in graph::variable_node< T, SAFE_MATH >.

◆ set() [3/4]

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual void graph::leaf_node< T, SAFE_MATH >::set ( const std::vector< T > &  d)
inlinevirtual

Set the value of variable data.

Parameters
[in]dVector data to set.

Reimplemented in graph::variable_node< T, SAFE_MATH >.

◆ set() [4/4]

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual void graph::leaf_node< T, SAFE_MATH >::set ( const d)
inlinevirtual

Set the value of variable data.

Parameters
[in]dScalar data to set.

Reimplemented in graph::variable_node< T, SAFE_MATH >.

◆ to_latex()

◆ to_vizgraph()


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