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::no_derivative< T, SAFE_MATH, BASE_NODE, N >

Classes

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

Public Types

typedef T base
 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_node< T, SAFE_MATH > > reduce ()
 Reduction method.
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > df (std::shared_ptr< leaf_node< T, SAFE_MATH > > x)
 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, jit::preamble_map &pre_funcs, int &avail_const_mem)
 Compile preamble.
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > compile (std::ostringstream &stream, jit::register_map &registers, const jit::register_map &thread_mem, const jit::register_usage &usage)=0
 Compile the node.
virtual bool is_match (std::shared_ptr< leaf_node< T, SAFE_MATH > > x)
 Query 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
 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
 Test if all the sub-nodes 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 char end=';') const
 End a line in the kernel source.

Static Public Attributes

static 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::unordered_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()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > graph::leaf_node< T, SAFE_MATH >::compile ( std::ostringstream & stream,
jit::register_map & registers,
const jit::register_map & thread_mem,
const jit::register_usage & usage )
pure virtual

Compile the node.

Parameters
[in,out]streamString buffer stream.
[in,out]registersList of defined registers.
[in]thread_memList of defined thread memory registers.
[in]usageList of register usage count.
Returns
The current node.

Implemented in dummy, graph::add_node< T, SAFE_MATH >, graph::and_node< T, SAFE_MATH >, graph::apply_u_node< T >, graph::apply_xi_node< T >, graph::arctan_node< T, SAFE_MATH >, graph::argument_node< T, SAFE_MATH >, graph::atomic_accumulate_1D_node< T, SAFE_MATH >, graph::constant_node< T, SAFE_MATH >, graph::copysign_node< T, SAFE_MATH >, graph::cosine_node< T, SAFE_MATH >, graph::divide_node< T, SAFE_MATH >, graph::equal_node< T, SAFE_MATH >, graph::erf_node< T, SAFE_MATH >, graph::erfi_node< T, SAFE_MATH >, graph::exp_node< T, SAFE_MATH >, graph::fma_node< T, SAFE_MATH >, graph::greater_than_equal_node< T, SAFE_MATH >, graph::greater_than_node< T, SAFE_MATH >, graph::hypot_node< T, SAFE_MATH >, graph::if_node< T, SAFE_MATH >, graph::index_1D_node< T, SAFE_MATH >, graph::index_2D_node< T, SAFE_MATH >, graph::index_node< T, SAFE_MATH >, graph::isinf_node< T, SAFE_MATH >, graph::isnan_node< T, SAFE_MATH >, graph::less_than_equal_node< T, SAFE_MATH >, graph::less_than_node< T, SAFE_MATH >, graph::log_node< T, SAFE_MATH >, graph::min_node< T, SAFE_MATH >, graph::modulo_node< T, SAFE_MATH >, graph::multiply_node< T, SAFE_MATH >, graph::not_equal_node< T, SAFE_MATH >, graph::not_node< T, SAFE_MATH >, graph::or_node< T, SAFE_MATH >, graph::piecewise_1D_node< T, SAFE_MATH >, graph::piecewise_2D_node< T, SAFE_MATH >, graph::pow_node< T, SAFE_MATH >, graph::random_node< T, SAFE_MATH >, graph::random_state_node< T, SAFE_MATH >, graph::sine_node< T, SAFE_MATH >, graph::sqrt_node< T, SAFE_MATH >, graph::straight_node< T, SAFE_MATH >, graph::straight_node< T, false >, graph::subtract_node< T, SAFE_MATH >, and graph::variable_node< T, SAFE_MATH >.

◆ 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,
jit::preamble_map & pre_funcs,
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]pre_funcsSet of preamble functions.
[in,out]avail_const_memAvailable constant memory.

Reimplemented in graph::apply_u_node< T >, graph::apply_xi_node< T >, graph::branch_node< T, SAFE_MATH >, graph::branch_node< T, false >, graph::branch_node< T, SAFE_MATH >, graph::n_branch_node< N, T, SAFE_MATH >, graph::n_branch_node< 4, T, false >, graph::n_branch_node< 7, T, false >, graph::piecewise_1D_node< T, SAFE_MATH >, graph::piecewise_2D_node< T, SAFE_MATH >, graph::random_node< T, SAFE_MATH >, graph::random_state_node< T, SAFE_MATH >, graph::straight_node< T, SAFE_MATH >, graph::straight_node< T, false >, graph::triple_node< T, SAFE_MATH >, graph::triple_node< T, false >, and graph::variable_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)
inlinevirtual

◆ 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 char end = ';' ) const
inlinevirtual

End a line in the kernel source.

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

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

◆ evaluate()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual backend::buffer< T > graph::leaf_node< T, SAFE_MATH >::evaluate ( )
pure virtual

Evaluate method.

Returns
The evaluated value of the node.

Implemented in dummy, graph::add_node< T, SAFE_MATH >, graph::and_node< T, SAFE_MATH >, graph::apply_u_node< T >, graph::apply_xi_node< T >, graph::arctan_node< T, SAFE_MATH >, graph::argument_node< T, SAFE_MATH >, graph::atomic_accumulate_1D_node< T, SAFE_MATH >, graph::constant_node< T, SAFE_MATH >, graph::copysign_node< T, SAFE_MATH >, graph::cosine_node< T, SAFE_MATH >, graph::divide_node< T, SAFE_MATH >, graph::equal_node< T, SAFE_MATH >, graph::erf_node< T, SAFE_MATH >, graph::erfi_node< T, SAFE_MATH >, graph::exp_node< T, SAFE_MATH >, graph::fma_node< T, SAFE_MATH >, graph::greater_than_equal_node< T, SAFE_MATH >, graph::greater_than_node< T, SAFE_MATH >, graph::hypot_node< T, SAFE_MATH >, graph::if_node< T, SAFE_MATH >, graph::index_1D_node< T, SAFE_MATH >, graph::index_2D_node< T, SAFE_MATH >, graph::index_node< T, SAFE_MATH >, graph::isinf_node< T, SAFE_MATH >, graph::isnan_node< T, SAFE_MATH >, graph::less_than_equal_node< T, SAFE_MATH >, graph::less_than_node< T, SAFE_MATH >, graph::log_node< T, SAFE_MATH >, graph::min_node< T, SAFE_MATH >, graph::modulo_node< T, SAFE_MATH >, graph::multiply_node< T, SAFE_MATH >, graph::not_equal_node< T, SAFE_MATH >, graph::not_node< T, SAFE_MATH >, graph::or_node< T, SAFE_MATH >, graph::piecewise_1D_node< T, SAFE_MATH >, graph::piecewise_2D_node< T, SAFE_MATH >, graph::pow_node< T, SAFE_MATH >, graph::random_node< T, SAFE_MATH >, graph::random_state_node< T, SAFE_MATH >, graph::sine_node< T, SAFE_MATH >, graph::sqrt_node< T, SAFE_MATH >, graph::straight_node< T, SAFE_MATH >, graph::straight_node< T, false >, graph::subtract_node< T, SAFE_MATH >, and graph::variable_node< T, SAFE_MATH >.

◆ 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

Query 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

◆ reduce()

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

◆ 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.

◆ 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 T d )
inlinevirtual

Set the value of variable data.

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

◆ 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.

◆ set() [4/4]

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

Set the value of variable data.

Parameters
[in]dScalar data to set.

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

◆ to_latex()

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

Convert the node to latex.

Reimplemented in graph::add_node< T, SAFE_MATH >, graph::and_node< T, SAFE_MATH >, graph::apply_u_node< T >, graph::apply_xi_node< T >, graph::arctan_node< T, SAFE_MATH >, graph::atomic_accumulate_1D_node< T, SAFE_MATH >, graph::constant_node< T, SAFE_MATH >, graph::copysign_node< T, SAFE_MATH >, graph::cosine_node< T, SAFE_MATH >, graph::divide_node< T, SAFE_MATH >, graph::equal_node< T, SAFE_MATH >, graph::erf_node< T, SAFE_MATH >, graph::erfi_node< T, SAFE_MATH >, graph::exp_node< T, SAFE_MATH >, graph::fma_node< T, SAFE_MATH >, graph::greater_than_equal_node< T, SAFE_MATH >, graph::greater_than_node< T, SAFE_MATH >, graph::hypot_node< T, SAFE_MATH >, graph::if_node< T, SAFE_MATH >, graph::index_1D_node< T, SAFE_MATH >, graph::index_2D_node< T, SAFE_MATH >, graph::index_node< T, SAFE_MATH >, graph::isinf_node< T, SAFE_MATH >, graph::isnan_node< T, SAFE_MATH >, graph::less_than_equal_node< T, SAFE_MATH >, graph::less_than_node< T, SAFE_MATH >, graph::log_node< T, SAFE_MATH >, graph::min_node< T, SAFE_MATH >, graph::modulo_node< T, SAFE_MATH >, graph::multiply_node< T, SAFE_MATH >, graph::not_equal_node< T, SAFE_MATH >, graph::not_node< T, SAFE_MATH >, graph::or_node< T, SAFE_MATH >, graph::piecewise_1D_node< T, SAFE_MATH >, graph::piecewise_2D_node< T, SAFE_MATH >, graph::pow_node< T, SAFE_MATH >, graph::pseudo_variable_node< T, SAFE_MATH >, graph::random_node< T, SAFE_MATH >, graph::random_state_node< T, SAFE_MATH >, graph::sine_node< T, SAFE_MATH >, graph::sqrt_node< T, SAFE_MATH >, graph::subtract_node< T, SAFE_MATH >, and graph::variable_node< T, SAFE_MATH >.

◆ to_vizgraph()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > graph::leaf_node< T, SAFE_MATH >::to_vizgraph ( std::stringstream & stream,
jit::register_map & registers )
pure virtual

Convert the node to vizgraph.

Parameters
[in,out]streamString buffer stream.
[in,out]registersList of defined registers.
Returns
The current node.

Implemented in dummy, graph::add_node< T, SAFE_MATH >, graph::and_node< T, SAFE_MATH >, graph::apply_u_node< T >, graph::apply_xi_node< T >, graph::arctan_node< T, SAFE_MATH >, graph::argument_node< T, SAFE_MATH >, graph::atomic_accumulate_1D_node< T, SAFE_MATH >, graph::constant_node< T, SAFE_MATH >, graph::copysign_node< T, SAFE_MATH >, graph::cosine_node< T, SAFE_MATH >, graph::divide_node< T, SAFE_MATH >, graph::equal_node< T, SAFE_MATH >, graph::erf_node< T, SAFE_MATH >, graph::erfi_node< T, SAFE_MATH >, graph::exp_node< T, SAFE_MATH >, graph::fma_node< T, SAFE_MATH >, graph::greater_than_equal_node< T, SAFE_MATH >, graph::greater_than_node< T, SAFE_MATH >, graph::hypot_node< T, SAFE_MATH >, graph::if_node< T, SAFE_MATH >, graph::index_1D_node< T, SAFE_MATH >, graph::index_2D_node< T, SAFE_MATH >, graph::index_node< T, SAFE_MATH >, graph::isinf_node< T, SAFE_MATH >, graph::isnan_node< T, SAFE_MATH >, graph::less_than_equal_node< T, SAFE_MATH >, graph::less_than_node< T, SAFE_MATH >, graph::log_node< T, SAFE_MATH >, graph::min_node< T, SAFE_MATH >, graph::modulo_node< T, SAFE_MATH >, graph::multiply_node< T, SAFE_MATH >, graph::not_equal_node< T, SAFE_MATH >, graph::not_node< T, SAFE_MATH >, graph::or_node< T, SAFE_MATH >, graph::piecewise_1D_node< T, SAFE_MATH >, graph::piecewise_2D_node< T, SAFE_MATH >, graph::pow_node< T, SAFE_MATH >, graph::pseudo_variable_node< T, SAFE_MATH >, graph::random_node< T, SAFE_MATH >, graph::random_state_node< T, SAFE_MATH >, graph::sine_node< T, SAFE_MATH >, graph::sqrt_node< T, SAFE_MATH >, graph::subtract_node< T, SAFE_MATH >, and graph::variable_node< T, SAFE_MATH >.


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