24 template<jit::
float_scalar T,
bool SAFE_MATH=false>
77 ap2->get_num_columns(),
85 return temp->get_right() /
87 temp->get_right()*
temp->get_right()));
94 if (
lc.get() &&
lc->evaluate().is_negative()) {
116 const size_t hash =
reinterpret_cast<size_t> (x.get());
137 if (registers.find(
this) == registers.end()) {
138 auto a = this->
arg->compile(stream, registers,
143 jit::add_type<T> (stream);
144 stream <<
" " << registers[
this] <<
" = sin("
145 << registers[
a.get()] <<
")";
159 if (
this == x.get()) {
165 return this->
arg->is_match(
x_cast->get_arg());
175 std::cout <<
"\\sin\\left(";
176 this->
arg->to_latex();
177 std::cout <<
"\\right)";
187 return sin(this->
arg->remove_pseudo());
201 if (registers.find(
this) == registers.end()) {
203 registers[
this] =
name;
204 stream <<
" " <<
name
205 <<
" [label = \"sin\", shape = oval, style = filled, fillcolor = blue, fontcolor = white];" << std::endl;
207 auto a = this->
arg->to_vizgraph(stream, registers);
208 stream <<
" " <<
name <<
" -- " << registers[
a.get()] <<
";" << std::endl;
224 template<jit::
float_scalar T,
bool SAFE_MATH=false>
226 auto temp = std::make_shared<sine_node<T, SAFE_MATH>> (x)->reduce();
237#if defined(__clang__) || defined(__GNUC__)
240 assert(
false &&
"Should never reach.");
245 template<jit::
float_scalar T,
bool SAFE_MATH=false>
257 template<jit::
float_scalar T,
bool SAFE_MATH=false>
259 return std::dynamic_pointer_cast<sine_node<T, SAFE_MATH>> (x);
271 template<jit::
float_scalar T,
bool SAFE_MATH=false>
331 ap2->get_num_columns(),
339 return temp->get_left() /
341 temp->get_right()*
temp->get_right()));
348 if (
lc.get() &&
lc->evaluate().is_negative()) {
370 const size_t hash =
reinterpret_cast<size_t> (x.get());
391 if (registers.find(
this) == registers.end()) {
392 auto a = this->
arg->compile(stream, registers,
397 jit::add_type<T> (stream);
398 stream <<
" " << registers[
this] <<
" = cos("
399 << registers[
a.get()] <<
")";
413 if (
this == x.get()) {
419 return this->
arg->is_match(
x_cast->get_arg());
429 std::cout <<
"\\cos\\left(";
430 this->
arg->to_latex();
431 std::cout <<
"\\right)";
441 return cos(this->
arg->remove_pseudo());
455 if (registers.find(
this) == registers.end()) {
457 registers[
this] =
name;
458 stream <<
" " <<
name
459 <<
" [label = \"cos\", shape = oval, style = filled, fillcolor = blue, fontcolor = white];" << std::endl;
461 auto a = this->
arg->to_vizgraph(stream, registers);
462 stream <<
" " <<
name <<
" -- " << registers[
a.get()] <<
";" << std::endl;
478 template<jit::
float_scalar T,
bool SAFE_MATH=false>
480 auto temp = std::make_shared<cosine_node<T, SAFE_MATH>> (x)->reduce();
491#if defined(__clang__) || defined(__GNUC__)
494 assert(
false &&
"Should never reach.");
499 template<jit::
float_scalar T,
bool SAFE_MATH=false>
511 template<jit::
float_scalar T,
bool SAFE_MATH=false>
513 return std::dynamic_pointer_cast<cosine_node<T, SAFE_MATH>> (x);
530 template<jit::
float_scalar T,
bool SAFE_MATH=false>
544 template<jit::
float_scalar T,
bool SAFE_MATH=false>
592 if (l.get() &&
r.get()) {
599 if (
pl1.get() && (r.get() ||
pl1->is_arg_match(
this->right))) {
601 }
else if (
pr1.get() && (l.get() ||
pr1->is_arg_match(
this->left))) {
608 if (
pl2.get() && (r.get() ||
pl2->is_arg_match(
this->right))) {
610 pl2->get_num_columns(),
613 }
else if (
pr2.get() && (l.get() ||
pr2->is_arg_match(
this->left))) {
615 pr2->get_num_columns(),
621 if (
pr2.get() &&
pr2->is_row_match(
this->left)) {
625 pr2->get_num_columns(),
628 }
else if (
pr2.get() &&
pr2->is_col_match(
this->left)) {
632 pr2->get_num_columns(),
635 }
else if (
pl2.get() &&
pl2->is_row_match(
this->right)) {
639 pl2->get_num_columns(),
642 }
else if (
pl2.get() &&
pl2->is_col_match(
this->right)) {
646 pl2->get_num_columns(),
668 const size_t hash =
reinterpret_cast<size_t> (x.get());
690 if (registers.find(
this) == registers.end()) {
693 auto r = this->
right->compile(stream, registers,
698 jit::add_type<T> (stream);
700 stream <<
" " << registers[
this] <<
" = atan("
701 << registers[
r.get()] <<
"/"
702 << registers[l.get()];
704 stream <<
" " << registers[
this] <<
" = atan2("
705 << registers[
r.get()] <<
","
706 << registers[l.get()];
722 if (
this == x.get()) {
728 return this->
left->is_match(
x_cast->get_left()) &&
739 std::cout <<
"atan\\left(";
740 this->
left->to_latex();
742 this->
right->to_latex();
743 std::cout <<
"\\right)";
753 return atan(this->
left->remove_pseudo(),
754 this->right->remove_pseudo());
768 if (registers.find(
this) == registers.end()) {
770 registers[
this] =
name;
771 stream <<
" " <<
name
772 <<
" [label = \"atan\", shape = oval, style = filled, fillcolor = blue, fontcolor = white];" << std::endl;
775 stream <<
" " <<
name <<
" -- " << registers[l.get()] <<
";" << std::endl;
776 auto r = this->
right->to_vizgraph(stream, registers);
777 stream <<
" " <<
name <<
" -- " << registers[
r.get()] <<
";" << std::endl;
793 template<jit::
float_scalar T,
bool SAFE_MATH=false>
796 auto temp = std::make_shared<arctan_node<T, SAFE_MATH>> (l,
r)->reduce();
807#if defined(__clang__) || defined(__GNUC__)
810 assert(
false &&
"Should never reach.");
824 template<jit::
float_scalar T, jit::
float_scalar L,
bool SAFE_MATH=false>
840 template<jit::
float_scalar T, jit::
float_scalar R,
bool SAFE_MATH=false>
847 template<jit::
float_scalar T,
bool SAFE_MATH=false>
859 template<jit::
float_scalar T,
bool SAFE_MATH=false>
861 return std::dynamic_pointer_cast<arctan_node<T, SAFE_MATH>> (x);
Class representing a generic buffer.
Definition backend.hpp:29
void sin()
Take sin.
Definition backend.hpp:230
void atan_col(const buffer< T > &x)
Atan col operation.
Definition backend.hpp:617
void atan_row(const buffer< T > &x)
Atan row operation.
Definition backend.hpp:573
void cos()
Take cos.
Definition backend.hpp:237
Class representing a sine_node leaf.
Definition trigonometry.hpp:545
virtual shared_leaf< T, SAFE_MATH > df(shared_leaf< T, SAFE_MATH > x)
Transform node to derivative.
Definition trigonometry.hpp:663
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.
Definition trigonometry.hpp:686
arctan_node(shared_leaf< T, SAFE_MATH > x, shared_leaf< T, SAFE_MATH > y)
Construct a arctan_node node.
Definition trigonometry.hpp:567
virtual shared_leaf< T, SAFE_MATH > reduce()
Reduce a arctan node.
Definition trigonometry.hpp:589
virtual shared_leaf< T, SAFE_MATH > remove_pseudo()
Remove pseudo variable nodes.
Definition trigonometry.hpp:751
virtual bool is_match(shared_leaf< T, SAFE_MATH > x)
Query if the nodes match.
Definition trigonometry.hpp:721
virtual shared_leaf< T, SAFE_MATH > to_vizgraph(std::stringstream &stream, jit::register_map ®isters)
Convert the node to vizgraph.
Definition trigonometry.hpp:766
virtual backend::buffer< T > evaluate()
Evaluate the results of arctan.
Definition trigonometry.hpp:578
virtual void to_latex() const
Convert the node to latex.
Definition trigonometry.hpp:738
Class representing a branch node.
Definition node.hpp:1337
shared_leaf< T, SAFE_MATH > right
Right branch of the tree.
Definition node.hpp:1342
shared_leaf< T, SAFE_MATH > left
Left branch of the tree.
Definition node.hpp:1340
Class representing a cosine_node leaf.
Definition trigonometry.hpp:272
virtual shared_leaf< T, SAFE_MATH > to_vizgraph(std::stringstream &stream, jit::register_map ®isters)
Convert the node to vizgraph.
Definition trigonometry.hpp:453
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.
Definition trigonometry.hpp:387
virtual shared_leaf< T, SAFE_MATH > df(shared_leaf< T, SAFE_MATH > x)
Transform node to derivative.
Definition trigonometry.hpp:365
cosine_node(shared_leaf< T, SAFE_MATH > x)
Construct a cosine_node node.
Definition trigonometry.hpp:290
virtual shared_leaf< T, SAFE_MATH > reduce()
Reduce the cos(x).
Definition trigonometry.hpp:311
virtual bool is_match(shared_leaf< T, SAFE_MATH > x)
Query if the nodes match.
Definition trigonometry.hpp:412
virtual void to_latex() const
Convert the node to latex.
Definition trigonometry.hpp:428
virtual backend::buffer< T > evaluate()
Evaluate the results of cosine.
Definition trigonometry.hpp:300
virtual shared_leaf< T, SAFE_MATH > remove_pseudo()
Remove pseudo variable nodes.
Definition trigonometry.hpp:439
Class representing a node leaf.
Definition node.hpp:371
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > compile(std::ostringstream &stream, jit::register_map ®isters, const jit::register_map &thread_mem, const jit::register_usage &usage)=0
Compile the node.
virtual void endline(std::ostringstream &stream, const jit::register_usage &usage, const char end=';') const
End a line in the kernel source.
Definition node.hpp:653
virtual std::shared_ptr< leaf_node< T, SAFE_MATH > > to_vizgraph(std::stringstream &stream, jit::register_map ®isters)=0
Convert the node to vizgraph.
virtual bool has_pseudo() const
Query if the node contains pseudo variables.
Definition node.hpp:633
const size_t hash
Hash for node.
Definition node.hpp:374
std::unordered_map< size_t, std::shared_ptr< leaf_node< T, SAFE_MATH > > > df_cache
Cache derivative terms.
Definition node.hpp:378
Class representing a sine_node leaf.
Definition trigonometry.hpp:25
virtual shared_leaf< T, SAFE_MATH > remove_pseudo()
Remove pseudo variable nodes.
Definition trigonometry.hpp:185
virtual shared_leaf< T, SAFE_MATH > to_vizgraph(std::stringstream &stream, jit::register_map ®isters)
Convert the node to vizgraph.
Definition trigonometry.hpp:199
virtual void to_latex() const
Convert the node to latex.
Definition trigonometry.hpp:174
virtual backend::buffer< T > evaluate()
Evaluate the results of sine.
Definition trigonometry.hpp:53
virtual shared_leaf< T, SAFE_MATH > reduce()
Reduce the sin(x).
Definition trigonometry.hpp:64
sine_node(shared_leaf< T, SAFE_MATH > x)
Construct a sine_node node.
Definition trigonometry.hpp:43
virtual shared_leaf< T, SAFE_MATH > df(shared_leaf< T, SAFE_MATH > x)
Transform node to derivative.
Definition trigonometry.hpp:111
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.
Definition trigonometry.hpp:133
virtual bool is_match(shared_leaf< T, SAFE_MATH > x)
Query if the nodes match.
Definition trigonometry.hpp:158
Class representing a straight node.
Definition node.hpp:1219
shared_leaf< T, SAFE_MATH > arg
Argument.
Definition node.hpp:1222
Complex scalar concept.
Definition register.hpp:25
subroutine assert(test, message)
Assert check.
Definition f_binding_test.f90:38
buffer< T > atan(buffer< T > &x, buffer< T > &y)
Take the inverse tangent.
Definition backend.hpp:1609
Name space for graph nodes.
Definition arithmetic.hpp:13
shared_piecewise_2D< T, SAFE_MATH > piecewise_2D_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a piecewise 2D node.
Definition piecewise.hpp:1508
shared_leaf< T, SAFE_MATH > tan(shared_leaf< T, SAFE_MATH > x)
Define tangent convenience function.
Definition trigonometry.hpp:531
std::shared_ptr< arctan_node< T, SAFE_MATH > > shared_atan
Convenience type alias for shared atan nodes.
Definition trigonometry.hpp:848
constexpr shared_leaf< T, SAFE_MATH > zero()
Forward declare for zero.
Definition node.hpp:1154
std::shared_ptr< sine_node< T, SAFE_MATH > > shared_sine
Convenience type alias for shared sine nodes.
Definition trigonometry.hpp:246
shared_leaf< T, SAFE_MATH > atan(shared_leaf< T, SAFE_MATH > l, shared_leaf< T, SAFE_MATH > r)
Build arctan node.
Definition trigonometry.hpp:794
shared_sine< T, SAFE_MATH > sin_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a sine node.
Definition trigonometry.hpp:258
shared_piecewise_1D< T, SAFE_MATH > piecewise_1D_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a piecewise 1D node.
Definition piecewise.hpp:849
shared_atan< T, SAFE_MATH > atan_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a power node.
Definition trigonometry.hpp:860
shared_multiply< T, SAFE_MATH > multiply_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a multiply node.
Definition arithmetic.hpp:2843
shared_constant< T, SAFE_MATH > constant_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a constant node.
Definition node.hpp:1202
constexpr T i
Convenience type for imaginary constant.
Definition node.hpp:1186
shared_leaf< T, SAFE_MATH > sin(shared_leaf< T, SAFE_MATH > x)
Define sine convenience function.
Definition trigonometry.hpp:225
shared_leaf< T, SAFE_MATH > sqrt(shared_leaf< T, SAFE_MATH > x)
Define sqrt convenience function.
Definition math.hpp:297
std::shared_ptr< cosine_node< T, SAFE_MATH > > shared_cosine
Convenience type alias for shared cosine nodes.
Definition trigonometry.hpp:500
std::shared_ptr< leaf_node< T, SAFE_MATH > > shared_leaf
Convenience type alias for shared leaf nodes.
Definition node.hpp:691
shared_leaf< T, SAFE_MATH > cos(shared_leaf< T, SAFE_MATH > x)
Define cosine convenience function.
Definition trigonometry.hpp:479
shared_cosine< T, SAFE_MATH > cos_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a cosine node.
Definition trigonometry.hpp:512
std::string format_to_string(const T value)
Convert a value to a string while avoiding locale.
Definition register.hpp:213
std::unordered_map< void *, size_t > register_usage
Type alias for counting register usage.
Definition register.hpp:261
std::unordered_map< void *, std::string > register_map
Type alias for mapping node pointers to register names.
Definition register.hpp:259
std::string to_string(const char prefix, const NODE *pointer)
Convert a graph::leaf_node pointer to a string.
Definition register.hpp:247
Base nodes of graph computation framework.
void piecewise_1D()
Tests for 1D piecewise nodes.
Definition piecewise_test.cpp:82
void piecewise_2D()
Tests for 2D piecewise nodes.
Definition piecewise_test.cpp:321