Graph Framework
|
Class representing a 1D piecewise constant. More...
#include <piecewise.hpp>
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_MATH > | reduce () |
Reduction method. | |
virtual shared_leaf< T, SAFE_MATH > | df (shared_leaf< T, SAFE_MATH > x) |
Transform node to derivative. | |
virtual void | compile_preamble (std::ostringstream &stream, jit::register_map ®isters, 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_MATH > | compile (std::ostringstream &stream, jit::register_map ®isters, 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_MATH > | to_vizgraph (std::stringstream &stream, jit::register_map ®isters) |
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_MATH > | get_power_base () |
Get the base of a power. | |
virtual shared_leaf< T, SAFE_MATH > | get_power_exponent () const |
Get the exponent of a power. | |
bool | is_arg_match (shared_leaf< T, SAFE_MATH > x) |
Check if the args match. | |
T | get_scale () const |
Get x argument scale. | |
T | get_offset () const |
Get x argument offset. | |
size_t | get_size () const |
Get the size of the buffer. | |
![]() | |
straight_node (shared_leaf< T, SAFE_MATH > a, const std::string s) | |
Construct a straight node. | |
shared_leaf< T, SAFE_MATH > | get_arg () |
Get the argument. | |
![]() | |
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 | |
![]() | |
typedef T | base |
Type def to retrieve the backend type. | |
![]() | |
static thread_local caches_t | caches |
A per thread instance of the cache structure. | |
![]() | |
shared_leaf< T, SAFE_MATH > | arg |
Argument. | |
![]() | |
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. | |
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)
T | Base type of the calculation. |
SAFE_MATH | Use Safe Math operations. |
|
inline |
Construct 1D a piecewise constant node.
[in] | d | Data to initalize the piecewise constant. |
[in] | x | Argument. |
[in] | scale | Scale factor for the argument. |
[in] | offset | Offset factor for the argument. |
|
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)
[in,out] | stream | String buffer stream. |
[in,out] | registers | List of defined registers. |
[in,out] | indices | List of defined indices. |
[in] | usage | List of register usage count. |
Reimplemented from graph::straight_node< T, SAFE_MATH >.
|
inlinevirtual |
Compile preamble.
[in,out] | stream | String buffer stream. |
[in,out] | registers | List of defined registers. |
[in,out] | visited | List of visited nodes. |
[in,out] | usage | List of register usage count. |
[in,out] | textures1d | List of 1D textures. |
[in,out] | textures2d | List of 2D textures. |
[in,out] | avail_const_mem | Available constant memory. |
Reimplemented from graph::straight_node< T, SAFE_MATH >.
|
inlinevirtual |
Transform node to derivative.
[in] | x | The variable to take the derivative to. |
|
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.
Reimplemented from graph::straight_node< T, SAFE_MATH >.
|
inline |
Get x argument offset.
|
inlinevirtual |
Get the base of a power.
Reimplemented from graph::leaf_node< T, SAFE_MATH >.
|
inlinevirtual |
Get the exponent of a power.
Reimplemented from graph::straight_node< T, SAFE_MATH >.
|
inline |
Get x argument scale.
|
inline |
Get the size of the buffer.
|
inlinevirtual |
Test the constant node has a zero.
Reimplemented from graph::leaf_node< T, SAFE_MATH >.
|
inlinevirtual |
Test if node acts like a variable.
Reimplemented from graph::straight_node< T, SAFE_MATH >.
|
inline |
Check if the args match.
[in] | x | Node to match. |
|
inlinevirtual |
Test if node is a constant.
Reimplemented from graph::leaf_node< T, SAFE_MATH >.
|
inlinevirtual |
Querey if the nodes match.
The argument of this node can be defered so we need to check if the arguments are null.
[in] | x | Other graph to check if it is a match. |
|
inlinevirtual |
Test if the node acts like a power of variable.
Reimplemented from graph::leaf_node< T, SAFE_MATH >.
|
inlinevirtual |
Reduction method.
If all the values in the data buffer are the same. Reduce to a single constant.
Implements graph::leaf_node< T, SAFE_MATH >.
|
inlinevirtual |
Convert the node to latex.
Implements graph::leaf_node< T, SAFE_MATH >.
|
inlinevirtual |
Convert the node to vizgraph.
[in,out] | stream | String buffer stream. |
[in,out] | registers | List of defined registers. |
Implements graph::leaf_node< T, SAFE_MATH >.