|
Graph Framework
|
Class representing a 2D piecewise constant. More...
#include <piecewise.hpp>
Public Member Functions | |
| piecewise_2D_node (const backend::buffer< T > &d, const size_t n, shared_leaf< T, SAFE_MATH > x, shared_leaf< T, SAFE_MATH > y) | |
| Construct 2D a piecewise constant node. | |
| size_t | get_num_columns () const |
| Get the number of columns. | |
| size_t | get_num_rows () const |
| Get the number of columns. | |
| 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, jit::preamble_map &pre_funcs, int &avail_const_mem) |
| Compile preamble. | |
| virtual shared_leaf< T, SAFE_MATH > | compile (std::ostringstream &stream, jit::register_map ®isters, const jit::register_map &thread_mem, const jit::register_usage &usage) |
| Compile the node. | |
| virtual bool | is_match (shared_leaf< T, SAFE_MATH > x) |
| Query if the nodes match. | |
| virtual bool | is_arg_match (shared_leaf< T, SAFE_MATH > x) |
| Query 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 | is_all_variables () const |
| Test if node acts like a variable. | |
| virtual bool | has_constant_zero () const |
| Test the constant node has a zero. | |
| 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_row_match (shared_leaf< T, SAFE_MATH > x) |
| Do the rows match. | |
| bool | is_col_match (shared_leaf< T, SAFE_MATH > x) |
| Do the columns match. | |
Public Member Functions inherited from graph::branch_node< T, SAFE_MATH > | |
| branch_node (shared_leaf< T, SAFE_MATH > l, shared_leaf< T, SAFE_MATH > r, const std::string s) | |
| Assigns the left and right branches. | |
| branch_node (shared_leaf< T, SAFE_MATH > l, shared_leaf< T, SAFE_MATH > r, const std::string s, const size_t count, const bool pseudo) | |
| Assigns the left and right branches. | |
| shared_leaf< T, SAFE_MATH > | get_left () const |
| Get the left branch. | |
| shared_leaf< T, SAFE_MATH > | get_right () const |
| Get the right branch. | |
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) |
| Transform node to derivative. | |
| 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. | |
| 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 char end=';') const |
| End a line in the kernel source. | |
Additional Inherited Members | |
Public Types inherited from graph::leaf_node< T, SAFE_MATH > | |
| typedef T | base |
| 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::branch_node< T, SAFE_MATH > | |
| shared_leaf< T, SAFE_MATH > | left |
| Left branch of the tree. | |
| shared_leaf< T, SAFE_MATH > | right |
| Right branch of the tree. | |
Protected Attributes inherited from graph::leaf_node< T, SAFE_MATH > | |
| 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. | |
Class representing a 2D piecewise constant.
This class is used to implement the coefficient terms of bicubic spline interpolation. An function is interpolated using
z(x,y) = Σ_i,3Σ_j,3 c_ij*x^i*y^j (1)
The arguments x and y are assumed to be the normalized arguments
x_norm = (x - xmin)/dx - i (2) y_norm = (y - ymin)/dy - j (3)
To avoid tracking the indices i and j which normalizes x and y to a zero to one interval the coefficients should be normalized to
c00'_ij = Σ_k,3Σ_l,3 (-i)^k*(-j)^l*ckl_ij (4) c10'_ij = Σ_k,3Σ_l,3 k*(-i)^(k-1)*(-j)^l*ckl_ij (5) c01'_ij = Σ_k,3Σ_l,3 l*(-i)^k*(-j)^(l-1)*ckl_ij (6) c20'_ij = Σ_k,3Σ_l,3 Max(2*k-3,0)*(-i)^(k-2)*(-j)^l*ckl_ij (7) c02'_ij = Σ_k,3Σ_l,3 Max(2*l-3,0)*(-i)^k*(-j)^(l-2)*ckl_ij (8) c30'_ij = Σ_k,3Σ_l,3 Max(k-2,0)*(-i)^(k-3)*(-j)^l*ckl_ij (9) c03'_ij = Σ_k,3Σ_l,3 Max(l-2,0)*(-i)^k*(-j)^(l-3)*ckl_ij (10) c11'_ij = Σ_k,3Σ_l,3 k*l*(-i)^(k-1)*(-j)^(j-1) (11) c21'_ij = Σ_k,3Σ_l,3 Max(2*k-3,0)*l*(-i)^(k-2)*(-j)^(j-1) (12) c12'_ij = Σ_k,3Σ_l,3 k*Max(2*l-3,0)*(-i)^(k-1)*(-j)^(j-2) (13) c31'_ij = Σ_k,3Σ_l,3 Max(k-2,0)*l*(-i)^(k-3)*(-j)^(j-1) (14) c13'_ij = Σ_k,3Σ_l,3 k*Max(l-2,0)*(-i)^(k-1)*(-j)^(j-3) (15) c22'_ij = Σ_k,3Σ_l,3 Max(2*k-3,0)*Max(2*l-3,0)*(-i)^(k-2)*(-j)^(j-2) (16) c32'_ij = Σ_k,3Σ_l,3 Max(k-2,0)*Max(2*l-3,0)*(-i)^(k-3)*(-j)^(j-2) (17) c23'_ij = Σ_k,3Σ_l,3 Max(2*k-3,0)*Max(l-2,0)*(-i)^(k-2)*(-j)^(j-3) (18) c33'_ij = Σ_k,3Σ_l,3 Max(k-2,0)*Max(l-2,0)*(-i)^(k-3)*(-j)^(j-3) (19)
This makes the normalized arguments (6,7) become
x_norm' = (x - xmin)/dx (20) y_norm' = (y - ymin)/dy (21)
| T | Base type of the calculation. |
| SAFE_MATH | Use Safe Math operations. |
|
inline |
Construct 2D a piecewise constant node.
| [in] | d | Data to initialize the piecewise constant. |
| [in] | n | Number of columns. |
| [in] | x | X Argument. |
| [in] | y | Y 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) y' = (y - ymin)/dy (2)
and the spline coefficients are of the form.
c00'_ij = Σ_k,3Σ_l,3 (-i)^k*(-j)^l*ckl_ij (3) c10'_ij = Σ_k,3Σ_l,3 k*(-i)^(k-1)*(-j)^l*ckl_ij (4) c01'_ij = Σ_k,3Σ_l,3 l*(-i)^k*(-j)^(l-1)*ckl_ij (5) c20'_ij = Σ_k,3Σ_l,3 Max(2*k-3,0)*(-i)^(k-2)*(-j)^l*ckl_ij (6) c02'_ij = Σ_k,3Σ_l,3 Max(2*l-3,0)*(-i)^k*(-j)^(l-2)*ckl_ij (7) c30'_ij = Σ_k,3Σ_l,3 Max(k-2,0)*(-i)^(k-3)*(-j)^l*ckl_ij (8) c03'_ij = Σ_k,3Σ_l,3 Max(l-2,0)*(-i)^k*(-j)^(l-3)*ckl_ij (9) c11'_ij = Σ_k,3Σ_l,3 k*l*(-i)^(k-1)*(-j)^(j-1) (10) c21'_ij = Σ_k,3Σ_l,3 Max(2*k-3,0)*l*(-i)^(k-2)*(-j)^(j-1) (11) c12'_ij = Σ_k,3Σ_l,3 k*Max(2*l-3,0)*(-i)^(k-1)*(-j)^(j-2) (12) c31'_ij = Σ_k,3Σ_l,3 Max(k-2,0)*l*(-i)^(k-3)*(-j)^(j-1) (13) c13'_ij = Σ_k,3Σ_l,3 k*Max(l-2,0)*(-i)^(k-1)*(-j)^(j-3) (14) c22'_ij = Σ_k,3Σ_l,3 Max(2*k-3,0)*Max(2*l-3,0)*(-i)^(k-2)*(-j)^(j-2) (15) c32'_ij = Σ_k,3Σ_l,3 Max(k-2,0)*Max(2*l-3,0)*(-i)^(k-3)*(-j)^(j-2) (16) c23'_ij = Σ_k,3Σ_l,3 Max(2*k-3,0)*Max(l-2,0)*(-i)^(k-2)*(-j)^(j-3) (17) c33'_ij = Σ_k,3Σ_l,3 Max(k-2,0)*Max(l-2,0)*(-i)^(k-3)*(-j)^(j-3) (18)
| [in,out] | stream | String buffer stream. |
| [in,out] | registers | List of defined registers. |
| [in] | thread_mem | List of defined thread memory registers. |
| [in] | usage | List of register usage count. |
Implements graph::leaf_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] | pre_funcs | Set of preamble functions. |
| [in,out] | avail_const_mem | Available constant memory. |
Reimplemented from graph::branch_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 returns the data as if it were a constant.
Implements graph::leaf_node< T, SAFE_MATH >.
|
inline |
Get the number of columns.
|
inline |
Get the number of columns.
|
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::branch_node< T, SAFE_MATH >.
|
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::branch_node< T, SAFE_MATH >.
|
inlinevirtual |
Query if the nodes match.
Assumes both arguments are either set or not set.
| [in] | x | Other graph to check if it is a match. |
|
inline |
Do the columns match.
The number of rows is the column dimension.
| [in] | x | Node to match. |
|
inlinevirtual |
Test if node is a constant.
Reimplemented from graph::leaf_node< T, SAFE_MATH >.
|
inlinevirtual |
Query if the nodes match.
Assumes both arguments are either set or not set.
| [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 >.
|
inline |
Do the rows match.
| [in] | x | Node to match. |
|
inlinevirtual |
Reduction method.
If all the values in the data buffer are the same. Reduce to a single constant.
Reimplemented from graph::leaf_node< T, SAFE_MATH >.
|
inlinevirtual |
Convert the node to latex.
Assumes both arguments are either set or not set.
Reimplemented from 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 >.