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

Class representing a 1D piecewise constant. More...

#include <piecewise.hpp>

Inheritance diagram for graph::piecewise_1D_node< T, SAFE_MATH >:
graph::straight_node< T, SAFE_MATH > graph::leaf_node< T, SAFE_MATH >

Public Member Functions

 piecewise_1D_node (const backend::buffer< T > &d, shared_leaf< T, SAFE_MATH > x, const T scale, const T offset)
 Construct 1D a piecewise constant node.
 
virtual backend::buffer< T > evaluate ()
 Evaluate the results of the piecewise constant.
 
virtual shared_leaf< T, SAFE_MATHreduce ()
 Reduction method.
 
virtual shared_leaf< T, SAFE_MATHdf (shared_leaf< 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, int &avail_const_mem)
 Compile preamble.
 
virtual shared_leaf< T, SAFE_MATHcompile (std::ostringstream &stream, jit::register_map &registers, jit::register_map &indices, const jit::register_usage &usage)
 Compile the node.
 
virtual bool is_match (shared_leaf< T, SAFE_MATH > x)
 Querey if the nodes match.
 
virtual void to_latex () const
 Convert the node to latex.
 
virtual shared_leaf< T, SAFE_MATHto_vizgraph (std::stringstream &stream, jit::register_map &registers)
 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.
 
virtual bool is_all_variables () const
 Test if node acts like a variable.
 
virtual bool is_power_like () const
 Test if the node acts like a power of variable.
 
virtual shared_leaf< T, SAFE_MATHget_power_base ()
 Get the base of a power.
 
virtual shared_leaf< T, SAFE_MATHget_power_exponent () const
 Get the exponent of a power.
 
bool is_arg_match (shared_leaf< T, SAFE_MATH > x)
 Check if the args match.
 
get_scale () const
 Get x argument scale.
 
get_offset () const
 Get x argument offset.
 
size_t get_size () const
 Get the size of the buffer.
 
- Public Member Functions inherited from graph::straight_node< T, SAFE_MATH >
 straight_node (shared_leaf< T, SAFE_MATH > a, const std::string s)
 Construct a straight node.
 
shared_leaf< T, SAFE_MATHget_arg ()
 Get the argument.
 
- Public Member Functions inherited from graph::leaf_node< T, SAFE_MATH >
 leaf_node (const std::string s, const size_t count, const bool pseudo)
 Construct a basic node.
 
virtual ~leaf_node ()
 Destructor.
 
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 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.
 
bool is_normal ()
 Test if the result is normal.
 
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.
 

Additional Inherited Members

- Public Types inherited from graph::leaf_node< T, SAFE_MATH >
typedefbase
 Type def to retrieve the backend type.
 
- Static Public Attributes inherited from graph::leaf_node< T, SAFE_MATH >
static thread_local caches_t caches
 A per thread instance of the cache structure.
 
- Protected Attributes inherited from graph::straight_node< T, SAFE_MATH >
shared_leaf< T, SAFE_MATHarg
 Argument.
 
- Protected Attributes inherited from graph::leaf_node< T, SAFE_MATH >
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::piecewise_1D_node< T, SAFE_MATH >

Class representing a 1D piecewise constant.

This class is used to impliment the coefficent terms of cubic spline interpolation. An function is interpolated using

y(x) = a_i + b_i*x +c_i*x^2 + d_i*x^3 (1)

The coeffients are defined as

a_i = y_i (2) b_i = D_i (3) c_i = 3*(y_i+1 - y_i) - 2*D_i - D_i+1 (4) d_i = 2*(y_i - y_i+1) + D_i + D_i+1 (5)

The agument x is assumed to be the normalized argument

x_norm = (x - xmin)/dx - i (6)

To avoid tracking the index i which normaizes x to a zero to one interval the coefficients should be normalized to

a'_i = a_i - b_i*i + c_i*i^2 - d_i*i^3 (7) b'_i = b_i - 2*c_i*i+3*d_i*i^2 (8) c'_i = c_i - 3*d_i*i (9) d'_i = d_i (10)

This makes the normalized argument (6) become

x_norm' = (x - xmin)/dx (11)

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

Constructor & Destructor Documentation

◆ piecewise_1D_node()

template<jit::float_scalar T, bool SAFE_MATH = false>
graph::piecewise_1D_node< T, SAFE_MATH >::piecewise_1D_node ( const backend::buffer< T > &  d,
shared_leaf< T, SAFE_MATH x,
const scale,
const offset 
)
inline

Construct 1D a piecewise constant node.

Parameters
[in]dData to initalize the piecewise constant.
[in]xArgument.
[in]scaleScale factor for the argument.
[in]offsetOffset factor for the argument.

Member Function Documentation

◆ compile()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual shared_leaf< T, SAFE_MATH > graph::piecewise_1D_node< T, SAFE_MATH >::compile ( std::ostringstream &  stream,
jit::register_map registers,
jit::register_map indices,
const jit::register_usage usage 
)
inlinevirtual

Compile the node.

This node first evaluates the value of the argument then chooses the correct piecewise index. This assumes that the argument is

x' = (x - xmin)/dx (1)

and the spline coefficients are of the form.

a'_i = a_i - b_i*i + c_i*i^2 - d_i*i^3 (2) b'_i = b_i - 2*c_i*i+3*d_i*i^2 (3) c'_i = c_i - 3*d_i*i (4) d'_i = d_i (5)

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

Reimplemented from graph::straight_node< T, SAFE_MATH >.

◆ compile_preamble()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual void graph::piecewise_1D_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.

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 from graph::straight_node< T, SAFE_MATH >.

◆ df()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual shared_leaf< T, SAFE_MATH > graph::piecewise_1D_node< T, SAFE_MATH >::df ( shared_leaf< T, SAFE_MATH x)
inlinevirtual

Transform node to derivative.

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

◆ evaluate()

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

Evaluate the results of the piecewise constant.

Evaluate functions are only used by the minimization. So this node does not evaluate the argument. Instead this only returs the data as if it were a constant.

Returns
The evaluated value of the node.

Reimplemented from graph::straight_node< T, SAFE_MATH >.

◆ get_offset()

template<jit::float_scalar T, bool SAFE_MATH = false>
T graph::piecewise_1D_node< T, SAFE_MATH >::get_offset ( ) const
inline

Get x argument offset.

Returns
The offset factor for x.

◆ get_power_base()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual shared_leaf< T, SAFE_MATH > graph::piecewise_1D_node< T, SAFE_MATH >::get_power_base ( )
inlinevirtual

Get the base of a power.

Returns
The base of a power like node.

Reimplemented from graph::leaf_node< T, SAFE_MATH >.

◆ get_power_exponent()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual shared_leaf< T, SAFE_MATH > graph::piecewise_1D_node< T, SAFE_MATH >::get_power_exponent ( ) const
inlinevirtual

Get the exponent of a power.

Returns
The exponent of a power like node.

Reimplemented from graph::straight_node< T, SAFE_MATH >.

◆ get_scale()

template<jit::float_scalar T, bool SAFE_MATH = false>
T graph::piecewise_1D_node< T, SAFE_MATH >::get_scale ( ) const
inline

Get x argument scale.

Returns
The scale factor for x.

◆ get_size()

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

Get the size of the buffer.

Returns
The size of the buffer.

◆ has_constant_zero()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual bool graph::piecewise_1D_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 from graph::leaf_node< T, SAFE_MATH >.

◆ is_all_variables()

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

Test if node acts like a variable.

Returns
True if the node acts like a variable.

Reimplemented from graph::straight_node< T, SAFE_MATH >.

◆ is_arg_match()

template<jit::float_scalar T, bool SAFE_MATH = false>
bool graph::piecewise_1D_node< T, SAFE_MATH >::is_arg_match ( shared_leaf< T, SAFE_MATH x)
inline

Check if the args match.

Parameters
[in]xNode to match.
Returns
True if the arguments match.

◆ is_constant()

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

Test if node is a constant.

Returns
True if the node is a constant.

Reimplemented from graph::leaf_node< T, SAFE_MATH >.

◆ is_match()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual bool graph::piecewise_1D_node< T, SAFE_MATH >::is_match ( shared_leaf< T, SAFE_MATH x)
inlinevirtual

Querey if the nodes match.

The argument of this node can be defered so we need to check if the arguments are null.

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

◆ is_power_like()

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

Test if the node acts like a power of variable.

Returns
True.

Reimplemented from graph::leaf_node< T, SAFE_MATH >.

◆ reduce()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual shared_leaf< T, SAFE_MATH > graph::piecewise_1D_node< T, SAFE_MATH >::reduce ( )
inlinevirtual

Reduction method.

If all the values in the data buffer are the same. Reduce to a single constant.

Returns
A reduced representation of the node.

Implements graph::leaf_node< T, SAFE_MATH >.

◆ to_latex()

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

Convert the node to latex.

Implements graph::leaf_node< T, SAFE_MATH >.

◆ to_vizgraph()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual shared_leaf< T, SAFE_MATH > graph::piecewise_1D_node< T, SAFE_MATH >::to_vizgraph ( std::stringstream &  stream,
jit::register_map registers 
)
inlinevirtual

Convert the node to vizgraph.

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

Implements graph::leaf_node< T, SAFE_MATH >.


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