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

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

#include <piecewise.hpp>

Inheritance diagram for graph::piecewise_2D_node< T, SAFE_MATH >:
graph::branch_node< T, SAFE_MATH > graph::leaf_node< T, SAFE_MATH >

Public Member Functions

 piecewise_2D_node (const backend::buffer< T > &d, const size_t n, shared_leaf< T, SAFE_MATH > x, const T x_scale, const T x_offset, shared_leaf< T, SAFE_MATH > y, const T y_scale, const T y_offset)
 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.
 
get_x_scale () const
 Get x argument scale.
 
get_x_offset () const
 Get x argument offset.
 
get_y_scale () const
 Get y argument scale.
 
get_y_offset () const
 Get y argument offset.
 
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.
 
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_MATHget_left ()
 Get the left branch.
 
shared_leaf< T, SAFE_MATHget_right ()
 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)=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::branch_node< T, SAFE_MATH >
shared_leaf< T, SAFE_MATHleft
 Left branch of the tree.
 
shared_leaf< T, SAFE_MATHright
 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::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_2D_node< T, SAFE_MATH >

Class representing a 2D piecewise constant.

This class is used to impliment the coefficent 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 aguments 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 normaizes 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)

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

Constructor & Destructor Documentation

◆ piecewise_2D_node()

template<jit::float_scalar T, bool SAFE_MATH = false>
graph::piecewise_2D_node< T, SAFE_MATH >::piecewise_2D_node ( const backend::buffer< T > &  d,
const size_t  n,
shared_leaf< T, SAFE_MATH x,
const x_scale,
const x_offset,
shared_leaf< T, SAFE_MATH y,
const y_scale,
const y_offset 
)
inline

Construct 2D a piecewise constant node.

Parameters
[in]dData to initalize the piecewise constant.
[in]nNumber of columns.
[in]xX Argument.
[in]x_scaleScale factor for the xargument.
[in]x_offsetOffset factor for the x argument.
[in]yY Argument.
[in]y_scaleScale factor for the y argument.
[in]y_offsetOffset factor for the y argument.

Member Function Documentation

◆ compile()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual shared_leaf< T, SAFE_MATH > graph::piecewise_2D_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) 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)

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.

Implements graph::leaf_node< T, SAFE_MATH >.

◆ compile_preamble()

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

◆ df()

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

Implements graph::leaf_node< T, SAFE_MATH >.

◆ get_num_columns()

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

Get the number of columns.

Returns
The number of columns in the constant.

◆ get_num_rows()

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

Get the number of columns.

Returns
The number of columns in the constant.

◆ get_power_base()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual shared_leaf< T, SAFE_MATH > graph::piecewise_2D_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_2D_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::branch_node< T, SAFE_MATH >.

◆ get_x_offset()

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

Get x argument offset.

Returns
The offset factor for x.

◆ get_x_scale()

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

Get x argument scale.

Returns
The scale factor for x.

◆ get_y_offset()

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

Get y argument offset.

Returns
The offset factor for x.

◆ get_y_scale()

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

Get y argument scale.

Returns
The scale factor for y.

◆ has_constant_zero()

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

◆ is_arg_match()

template<jit::float_scalar T, bool SAFE_MATH = false>
bool graph::piecewise_2D_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_col_match()

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

Do the columns match.

The number of rows is the column dimension.

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

◆ is_constant()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual bool graph::piecewise_2D_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_2D_node< T, SAFE_MATH >::is_match ( shared_leaf< T, SAFE_MATH x)
inlinevirtual

Querey if the nodes match.

Assumes both arguments are either set or not set.

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

◆ is_row_match()

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

Do the rows match.

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

◆ reduce()

template<jit::float_scalar T, bool SAFE_MATH = false>
virtual shared_leaf< T, SAFE_MATH > graph::piecewise_2D_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_2D_node< T, SAFE_MATH >::to_latex ( ) const
inlinevirtual

Convert the node to latex.

Assumes both arguments are either set or not set.

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_2D_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: