24 template<jit::
float_scalar T,
bool SAFE_MATH=false>
77 ap2->get_num_columns(),
85 return temp->get_right() /
86 (
sqrt(temp->get_left()*temp->get_left() +
87 temp->get_right()*temp->get_right()));
94 if (lc.get() && lc->evaluate().is_negative()) {
99 return this->shared_from_this();
116 const size_t hash =
reinterpret_cast<size_t> (x.get());
117 if (this->
df_cache.find(
hash) == this->df_cache.end()) {
137 if (registers.find(
this) == registers.end()) {
138 auto a = this->
arg->compile(stream, registers,
144 stream <<
" " << registers[
this] <<
" = sin("
145 << registers[a.get()] <<
")";
149 return this->shared_from_this();
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());
189 return this->shared_from_this();
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;
211 return this->shared_from_this();
224 template<jit::
float_scalar T,
bool SAFE_MATH=false>
226 auto temp = std::make_shared<sine_node<T, SAFE_MATH>> (x)->reduce();
228 for (
size_t i = temp->get_hash();
i < std::numeric_limits<size_t>::max();
i++) {
237#if defined(__clang__) || defined(__GNUC__)
238 __builtin_unreachable();
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() /
340 (
sqrt(temp->get_left()*temp->get_left() +
341 temp->get_right()*temp->get_right()));
348 if (lc.get() && lc->evaluate().is_negative()) {
353 return this->shared_from_this();
370 const size_t hash =
reinterpret_cast<size_t> (x.get());
371 if (this->
df_cache.find(
hash) == this->df_cache.end()) {
391 if (registers.find(
this) == registers.end()) {
392 auto a = this->
arg->compile(stream, registers,
398 stream <<
" " << registers[
this] <<
" = cos("
399 << registers[a.get()] <<
")";
403 return this->shared_from_this();
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());
443 return this->shared_from_this();
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;
465 return this->shared_from_this();
478 template<jit::
float_scalar T,
bool SAFE_MATH=false>
480 auto temp = std::make_shared<cosine_node<T, SAFE_MATH>> (x)->reduce();
482 for (
size_t i = temp->get_hash();
i < std::numeric_limits<size_t>::max();
i++) {
491#if defined(__clang__) || defined(__GNUC__)
492 __builtin_unreachable();
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(),
651 return this->shared_from_this();
668 const size_t hash =
reinterpret_cast<size_t> (x.get());
669 if (this->
df_cache.find(
hash) == this->df_cache.end()) {
690 if (registers.find(
this) == registers.end()) {
691 auto l = this->
left->compile(stream, registers,
693 auto r = this->
right->compile(stream, registers,
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()];
712 return this->shared_from_this();
722 if (
this == x.get()) {
728 return this->
left->is_match(x_cast->get_left()) &&
729 this->
right->is_match(x_cast->get_right());
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());
756 return this->shared_from_this();
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;
774 auto l = this->
left->to_vizgraph(stream, registers);
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;
780 return this->shared_from_this();
793 template<jit::
float_scalar T,
bool SAFE_MATH=false>
796 auto temp = std::make_shared<arctan_node<T, SAFE_MATH>> (l, r)->reduce();
798 for (
size_t i = temp->get_hash();
i < std::numeric_limits<size_t>::max();
i++) {
807#if defined(__clang__) || defined(__GNUC__)
808 __builtin_unreachable();
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
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
branch_node(shared_leaf< T, SAFE_MATH > l, shared_leaf< T, SAFE_MATH > r, const std::string s)
Definition node.hpp:1352
shared_leaf< T, SAFE_MATH > right
Definition node.hpp:1341
shared_leaf< T, SAFE_MATH > left
Definition node.hpp:1339
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:370
virtual void endline(std::ostringstream &stream, const jit::register_usage &usage, const char end=';') const
Definition node.hpp:652
static caches_t caches
A per thread instance of the cache structure.
Definition node.hpp:682
virtual bool has_pseudo() const
Definition node.hpp:632
const size_t hash
Definition node.hpp:373
std::unordered_map< size_t, std::shared_ptr< leaf_node< T, SAFE_MATH > > > df_cache
Definition node.hpp:377
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
shared_leaf< T, SAFE_MATH > arg
Definition node.hpp:1221
straight_node(shared_leaf< T, SAFE_MATH > a, const std::string s)
Definition node.hpp:1230
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:1582
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< cosine_node< T, SAFE_MATH > > shared_cosine
Convenience type alias for shared cosine nodes.
Definition trigonometry.hpp:500
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
std::shared_ptr< sine_node< T, SAFE_MATH > > shared_sine
Convenience type alias for shared sine nodes.
Definition trigonometry.hpp:246
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
constexpr shared_leaf< T, SAFE_MATH > one()
Forward declare for one.
Definition node.hpp:1166
std::shared_ptr< leaf_node< T, SAFE_MATH > > shared_leaf
Convenience type alias for shared leaf nodes.
Definition node.hpp:690
shared_constant< T, SAFE_MATH > constant_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a constant node.
Definition node.hpp:1201
constexpr T i
Convenience type for imaginary constant.
Definition node.hpp:1185
std::shared_ptr< arctan_node< T, SAFE_MATH > > shared_atan
Convenience type alias for shared atan nodes.
Definition trigonometry.hpp:848
shared_leaf< T, SAFE_MATH > constant(const backend::buffer< T > &d)
Construct a constant.
Definition node.hpp:1110
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
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
void add_type(std::basic_ostream< char > &stream)
Write out the node base type to a general stream.
Definition register.hpp:165
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