Graph Framework
Loading...
Searching...
No Matches
trigonometry.hpp
Go to the documentation of this file.
1//------------------------------------------------------------------------------
6//------------------------------------------------------------------------------
7
8#ifndef trigonometry_h
9#define trigonometry_h
10
11#include "node.hpp"
12
13namespace graph {
14
15//******************************************************************************
16// Sine node.
17//******************************************************************************
18//------------------------------------------------------------------------------
23//------------------------------------------------------------------------------
24 template<jit::float_scalar T, bool SAFE_MATH=false>
25 class sine_node final : public straight_node<T, SAFE_MATH> {
26 private:
27//------------------------------------------------------------------------------
32//------------------------------------------------------------------------------
33 static std::string to_string(leaf_node<T, SAFE_MATH> *a) {
34 return "sin" + jit::format_to_string(reinterpret_cast<size_t> (a));
35 }
36
37 public:
38//------------------------------------------------------------------------------
42//------------------------------------------------------------------------------
45
46//------------------------------------------------------------------------------
52//------------------------------------------------------------------------------
54 backend::buffer<T> result = this->arg->evaluate();
55 result.sin();
56 return result;
57 }
58
59//------------------------------------------------------------------------------
63//------------------------------------------------------------------------------
65 if (constant_cast(this->arg).get()) {
66 return constant<T, SAFE_MATH> (this->evaluate());
67 }
68
69 auto ap1 = piecewise_1D_cast(this->arg);
70 if (ap1.get()) {
71 return piecewise_1D(this->evaluate(), ap1->get_arg());
72 }
73
74 auto ap2 = piecewise_2D_cast(this->arg);
75 if (ap2.get()) {
76 return piecewise_2D(this->evaluate(),
77 ap2->get_num_columns(),
78 ap2->get_left(),
79 ap2->get_right());
80 }
81
82// Sin(ArcTan(x, y)) -> y/Sqrt(x^2 + y^2)
83 auto temp = atan_cast(this->arg);
84 if (temp.get()) {
85 return temp->get_right() /
86 (sqrt(temp->get_left()*temp->get_left() +
87 temp->get_right()*temp->get_right()));
88 }
89
90// Remove negative constants from the arguments.
91 auto am = multiply_cast(this->arg);
92 if (am.get()) {
93 auto lc = constant_cast(am->get_left());
94 if (lc.get() && lc->evaluate().is_negative()) {
95 return -sin(-this->arg);
96 }
97 }
98
99 return this->shared_from_this();
100 }
101
102//------------------------------------------------------------------------------
109//------------------------------------------------------------------------------
112 if (this->is_match(x)) {
113 return one<T, SAFE_MATH> ();
114 }
115
116 const size_t hash = reinterpret_cast<size_t> (x.get());
117 if (this->df_cache.find(hash) == this->df_cache.end()) {
118 this->df_cache[hash] = cos(this->arg)*this->arg->df(x);
119 }
120 return this->df_cache[hash];
121 }
122
123//------------------------------------------------------------------------------
131//------------------------------------------------------------------------------
133 compile(std::ostringstream &stream,
134 jit::register_map &registers,
136 const jit::register_usage &usage) {
137 if (registers.find(this) == registers.end()) {
138 auto a = this->arg->compile(stream, registers,
140
141 registers[this] = jit::to_string('r', this);
142 stream << " const ";
143 jit::add_type<T> (stream);
144 stream << " " << registers[this] << " = sin("
145 << registers[a.get()] << ")";
146 this->endline(stream, usage);
147 }
148
149 return this->shared_from_this();
150 }
151
152//------------------------------------------------------------------------------
157//------------------------------------------------------------------------------
159 if (this == x.get()) {
160 return true;
161 }
162
163 auto x_cast = sin_cast(x);
164 if (x_cast.get()) {
165 return this->arg->is_match(x_cast->get_arg());
166 }
167
168 return false;
169 }
170
171//------------------------------------------------------------------------------
173//------------------------------------------------------------------------------
174 virtual void to_latex() const {
175 std::cout << "\\sin\\left(";
176 this->arg->to_latex();
177 std::cout << "\\right)";
178 }
179
180//------------------------------------------------------------------------------
184//------------------------------------------------------------------------------
186 if (this->has_pseudo()) {
187 return sin(this->arg->remove_pseudo());
188 }
189 return this->shared_from_this();
190 }
191
192//------------------------------------------------------------------------------
198//------------------------------------------------------------------------------
199 virtual shared_leaf<T, SAFE_MATH> to_vizgraph(std::stringstream &stream,
200 jit::register_map &registers) {
201 if (registers.find(this) == registers.end()) {
202 const std::string name = jit::to_string('r', this);
203 registers[this] = name;
204 stream << " " << name
205 << " [label = \"sin\", shape = oval, style = filled, fillcolor = blue, fontcolor = white];" << std::endl;
206
207 auto a = this->arg->to_vizgraph(stream, registers);
208 stream << " " << name << " -- " << registers[a.get()] << ";" << std::endl;
209 }
210
211 return this->shared_from_this();
212 }
213 };
214
215//------------------------------------------------------------------------------
223//------------------------------------------------------------------------------
224 template<jit::float_scalar T, bool SAFE_MATH=false>
226 auto temp = std::make_shared<sine_node<T, SAFE_MATH>> (x)->reduce();
227// Test for hash collisions.
228 for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) {
229 if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) ==
232 return temp;
233 } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) {
235 }
236 }
237#if defined(__clang__) || defined(__GNUC__)
239#else
240 assert(false && "Should never reach.");
241#endif
242 }
243
245 template<jit::float_scalar T, bool SAFE_MATH=false>
246 using shared_sine = std::shared_ptr<sine_node<T, SAFE_MATH>>;
247
248//------------------------------------------------------------------------------
256//------------------------------------------------------------------------------
257 template<jit::float_scalar T, bool SAFE_MATH=false>
259 return std::dynamic_pointer_cast<sine_node<T, SAFE_MATH>> (x);
260 }
261
262//******************************************************************************
263// Cosine node.
264//******************************************************************************
265//------------------------------------------------------------------------------
270//------------------------------------------------------------------------------
271 template<jit::float_scalar T, bool SAFE_MATH=false>
272 class cosine_node final : public straight_node<T, SAFE_MATH> {
273 private:
274//------------------------------------------------------------------------------
279//------------------------------------------------------------------------------
280 static std::string to_string(leaf_node<T, SAFE_MATH> *a) {
281 return "cos" + jit::format_to_string(reinterpret_cast<size_t> (a));
282 }
283
284 public:
285//------------------------------------------------------------------------------
289//------------------------------------------------------------------------------
292
293//------------------------------------------------------------------------------
299//------------------------------------------------------------------------------
301 backend::buffer<T> result = this->arg->evaluate();
302 result.cos();
303 return result;
304 }
305
306//------------------------------------------------------------------------------
310//------------------------------------------------------------------------------
312 auto c = constant_cast(this->arg);
313 if (c.get()) {
314// GNU complex revalues cos(0, i0) evaluates to (1, -i0). This is casuing a
315// problem with the c and fortran binding tests.
316 if (c->is(0)) {
317 return one<T, SAFE_MATH> ();
318 }
319 return constant<T, SAFE_MATH> (this->evaluate());
320 }
321
322 auto ap1 = piecewise_1D_cast(this->arg);
323 if (ap1.get()) {
324 return piecewise_1D(this->evaluate(),
325 ap1->get_arg());
326 }
327
328 auto ap2 = piecewise_2D_cast(this->arg);
329 if (ap2.get()) {
330 return piecewise_2D(this->evaluate(),
331 ap2->get_num_columns(),
332 ap2->get_left(),
333 ap2->get_right());
334 }
335
336// Cos(ArcTan(x, y)) -> x/Sqrt(x^2 + y^2)
337 auto temp = atan_cast(this->arg);
338 if (temp.get()) {
339 return temp->get_left() /
340 (sqrt(temp->get_left()*temp->get_left() +
341 temp->get_right()*temp->get_right()));
342 }
343
344// Remove negative constants from the arguments.
345 auto am = multiply_cast(this->arg);
346 if (am.get()) {
347 auto lc = constant_cast(am->get_left());
348 if (lc.get() && lc->evaluate().is_negative()) {
349 return cos(-this->arg);
350 }
351 }
352
353 return this->shared_from_this();
354 }
355
356//------------------------------------------------------------------------------
363//------------------------------------------------------------------------------
366 if (this->is_match(x)) {
367 return one<T, SAFE_MATH> ();
368 }
369
370 const size_t hash = reinterpret_cast<size_t> (x.get());
371 if (this->df_cache.find(hash) == this->df_cache.end()) {
372 this->df_cache[hash] = -sin(this->arg)*this->arg->df(x);
373 }
374 return this->df_cache[hash];
375 }
376
377//------------------------------------------------------------------------------
385//------------------------------------------------------------------------------
387 compile(std::ostringstream &stream,
388 jit::register_map &registers,
390 const jit::register_usage &usage) {
391 if (registers.find(this) == registers.end()) {
392 auto a = this->arg->compile(stream, registers,
394
395 registers[this] = jit::to_string('r', this);
396 stream << " const ";
397 jit::add_type<T> (stream);
398 stream << " " << registers[this] << " = cos("
399 << registers[a.get()] << ")";
400 this->endline(stream, usage);
401 }
402
403 return this->shared_from_this();
404 }
405
406//------------------------------------------------------------------------------
411//------------------------------------------------------------------------------
413 if (this == x.get()) {
414 return true;
415 }
416
417 auto x_cast = cos_cast(x);
418 if (x_cast.get()) {
419 return this->arg->is_match(x_cast->get_arg());
420 }
421
422 return false;
423 }
424
425//------------------------------------------------------------------------------
427//------------------------------------------------------------------------------
428 virtual void to_latex() const {
429 std::cout << "\\cos\\left(";
430 this->arg->to_latex();
431 std::cout << "\\right)";
432 }
433
434//------------------------------------------------------------------------------
438//------------------------------------------------------------------------------
440 if (this->has_pseudo()) {
441 return cos(this->arg->remove_pseudo());
442 }
443 return this->shared_from_this();
444 }
445
446//------------------------------------------------------------------------------
452//------------------------------------------------------------------------------
453 virtual shared_leaf<T, SAFE_MATH> to_vizgraph(std::stringstream &stream,
454 jit::register_map &registers) {
455 if (registers.find(this) == registers.end()) {
456 const std::string name = jit::to_string('r', this);
457 registers[this] = name;
458 stream << " " << name
459 << " [label = \"cos\", shape = oval, style = filled, fillcolor = blue, fontcolor = white];" << std::endl;
460
461 auto a = this->arg->to_vizgraph(stream, registers);
462 stream << " " << name << " -- " << registers[a.get()] << ";" << std::endl;
463 }
464
465 return this->shared_from_this();
466 }
467 };
468
469//------------------------------------------------------------------------------
477//------------------------------------------------------------------------------
478 template<jit::float_scalar T, bool SAFE_MATH=false>
480 auto temp = std::make_shared<cosine_node<T, SAFE_MATH>> (x)->reduce();
481// Test for hash collisions.
482 for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) {
483 if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) ==
486 return temp;
487 } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) {
489 }
490 }
491#if defined(__clang__) || defined(__GNUC__)
493#else
494 assert(false && "Should never reach.");
495#endif
496 }
497
499 template<jit::float_scalar T, bool SAFE_MATH=false>
500 using shared_cosine = std::shared_ptr<cosine_node<T, SAFE_MATH>>;
501
502//------------------------------------------------------------------------------
510//------------------------------------------------------------------------------
511 template<jit::float_scalar T, bool SAFE_MATH=false>
513 return std::dynamic_pointer_cast<cosine_node<T, SAFE_MATH>> (x);
514 }
515
516//******************************************************************************
517// Tangent node.
518//******************************************************************************
519//------------------------------------------------------------------------------
529//------------------------------------------------------------------------------
530 template<jit::float_scalar T, bool SAFE_MATH=false>
534
535//******************************************************************************
536// Arctangent node.
537//******************************************************************************
538//------------------------------------------------------------------------------
543//------------------------------------------------------------------------------
544 template<jit::float_scalar T, bool SAFE_MATH=false>
545 class arctan_node final : public branch_node<T, SAFE_MATH> {
546 private:
547//------------------------------------------------------------------------------
553//------------------------------------------------------------------------------
554 static std::string to_string(leaf_node<T, SAFE_MATH> *l,
556 return "atan" + jit::format_to_string(reinterpret_cast<size_t> (l))
557 + jit::format_to_string(reinterpret_cast<size_t> (r));
558 }
559
560 public:
561//------------------------------------------------------------------------------
566//------------------------------------------------------------------------------
570
571//------------------------------------------------------------------------------
577//------------------------------------------------------------------------------
579 backend::buffer<T> left = this->left->evaluate();
580 backend::buffer<T> right = this->right->evaluate();
581 return backend::atan(left, right);
582 }
583
584//------------------------------------------------------------------------------
588//------------------------------------------------------------------------------
590 auto l = constant_cast(this->left);
591 auto r = constant_cast(this->right);
592 if (l.get() && r.get()) {
593 return constant<T, SAFE_MATH> (this->evaluate());
594 }
595
596 auto pl1 = piecewise_1D_cast(this->left);
597 auto pr1 = piecewise_1D_cast(this->right);
598
599 if (pl1.get() && (r.get() || pl1->is_arg_match(this->right))) {
600 return piecewise_1D(this->evaluate(), pl1->get_arg());
601 } else if (pr1.get() && (l.get() || pr1->is_arg_match(this->left))) {
602 return piecewise_1D(this->evaluate(), pr1->get_arg());
603 }
604
605 auto pl2 = piecewise_2D_cast(this->left);
606 auto pr2 = piecewise_2D_cast(this->right);
607
608 if (pl2.get() && (r.get() || pl2->is_arg_match(this->right))) {
609 return piecewise_2D(this->evaluate(),
610 pl2->get_num_columns(),
611 pl2->get_left(),
612 pl2->get_right());
613 } else if (pr2.get() && (l.get() || pr2->is_arg_match(this->left))) {
614 return piecewise_2D(this->evaluate(),
615 pr2->get_num_columns(),
616 pr2->get_left(),
617 pr2->get_right());
618 }
619
620// Combine 2D and 1D piecewise constants if a row or column matches.
621 if (pr2.get() && pr2->is_row_match(this->left)) {
622 backend::buffer<T> result = pl1->evaluate();
623 result.atan_row(pr2->evaluate());
624 return piecewise_2D(result,
625 pr2->get_num_columns(),
626 pr2->get_left(),
627 pr2->get_right());
628 } else if (pr2.get() && pr2->is_col_match(this->left)) {
629 backend::buffer<T> result = pl1->evaluate();
630 result.atan_col(pr2->evaluate());
631 return piecewise_2D(result,
632 pr2->get_num_columns(),
633 pr2->get_left(),
634 pr2->get_right());
635 } else if (pl2.get() && pl2->is_row_match(this->right)) {
636 backend::buffer<T> result = pl2->evaluate();
637 result.atan_row(pr1->evaluate());
638 return piecewise_2D(result,
639 pl2->get_num_columns(),
640 pl2->get_left(),
641 pl2->get_right());
642 } else if (pl2.get() && pl2->is_col_match(this->right)) {
643 backend::buffer<T> result = pl2->evaluate();
644 result.atan_col(pr1->evaluate());
645 return piecewise_2D(result,
646 pl2->get_num_columns(),
647 pl2->get_left(),
648 pl2->get_right());
649 }
650
651 return this->shared_from_this();
652 }
653
654//------------------------------------------------------------------------------
661//------------------------------------------------------------------------------
664 if (this->is_match(x)) {
665 return one<T, SAFE_MATH> ();
666 }
667
668 const size_t hash = reinterpret_cast<size_t> (x.get());
669 if (this->df_cache.find(hash) == this->df_cache.end()) {
670 auto z = this->right/this->left;
671 this->df_cache[hash] = (1.0/(1.0 + z*z))*z->df(x);
672 }
673 return this->df_cache[hash];
674 }
675
676//------------------------------------------------------------------------------
684//------------------------------------------------------------------------------
686 compile(std::ostringstream &stream,
687 jit::register_map &registers,
689 const jit::register_usage &usage) {
690 if (registers.find(this) == registers.end()) {
691 auto l = this->left->compile(stream, registers,
693 auto r = this->right->compile(stream, registers,
695
696 registers[this] = jit::to_string('r', this);
697 stream << " const ";
698 jit::add_type<T> (stream);
699 if constexpr (jit::complex_scalar<T>) {
700 stream << " " << registers[this] << " = atan("
701 << registers[r.get()] << "/"
702 << registers[l.get()];
703 } else {
704 stream << " " << registers[this] << " = atan2("
705 << registers[r.get()] << ","
706 << registers[l.get()];
707 }
708 stream << ")";
709 this->endline(stream, usage);
710 }
711
712 return this->shared_from_this();
713 }
714
715//------------------------------------------------------------------------------
720//------------------------------------------------------------------------------
722 if (this == x.get()) {
723 return true;
724 }
725
726 auto x_cast = atan_cast(x);
727 if (x_cast.get()) {
728 return this->left->is_match(x_cast->get_left()) &&
729 this->right->is_match(x_cast->get_right());
730 }
731
732 return false;
733 }
734
735//------------------------------------------------------------------------------
737//------------------------------------------------------------------------------
738 virtual void to_latex() const {
739 std::cout << "atan\\left(";
740 this->left->to_latex();
741 std::cout << ",";
742 this->right->to_latex();
743 std::cout << "\\right)";
744 }
745
746//------------------------------------------------------------------------------
750//------------------------------------------------------------------------------
752 if (this->has_pseudo()) {
753 return atan(this->left->remove_pseudo(),
754 this->right->remove_pseudo());
755 }
756 return this->shared_from_this();
757 }
758
759//------------------------------------------------------------------------------
765//------------------------------------------------------------------------------
766 virtual shared_leaf<T, SAFE_MATH> to_vizgraph(std::stringstream &stream,
767 jit::register_map &registers) {
768 if (registers.find(this) == registers.end()) {
769 const std::string name = jit::to_string('r', this);
770 registers[this] = name;
771 stream << " " << name
772 << " [label = \"atan\", shape = oval, style = filled, fillcolor = blue, fontcolor = white];" << std::endl;
773
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;
778 }
779
780 return this->shared_from_this();
781 }
782 };
783
784//------------------------------------------------------------------------------
792//------------------------------------------------------------------------------
793 template<jit::float_scalar T, bool SAFE_MATH=false>
796 auto temp = std::make_shared<arctan_node<T, SAFE_MATH>> (l, r)->reduce();
797// Test for hash collisions.
798 for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) {
799 if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) ==
802 return temp;
803 } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) {
805 }
806 }
807#if defined(__clang__) || defined(__GNUC__)
809#else
810 assert(false && "Should never reach.");
811#endif
812 }
813
814//------------------------------------------------------------------------------
823//------------------------------------------------------------------------------
824 template<jit::float_scalar T, jit::float_scalar L, bool SAFE_MATH=false>
827 return atan(constant<T, SAFE_MATH> (static_cast<T> (l)), r);
828 }
829
830//------------------------------------------------------------------------------
839//------------------------------------------------------------------------------
840 template<jit::float_scalar T, jit::float_scalar R, bool SAFE_MATH=false>
842 const R r) {
843 return atan(l, constant<T, SAFE_MATH> (static_cast<T> (r)));
844 }
845
847 template<jit::float_scalar T, bool SAFE_MATH=false>
848 using shared_atan = std::shared_ptr<arctan_node<T, SAFE_MATH>>;
849
850//------------------------------------------------------------------------------
858//------------------------------------------------------------------------------
859 template<jit::float_scalar T, bool SAFE_MATH=false>
861 return std::dynamic_pointer_cast<arctan_node<T, SAFE_MATH>> (x);
862 }
863}
864
865#endif /* trigonometry_h */
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 &registers, 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 &registers)
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 &registers)
Convert the node to vizgraph.
Definition trigonometry.hpp:453
virtual shared_leaf< T, SAFE_MATH > compile(std::ostringstream &stream, jit::register_map &registers, 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 &registers, 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 &registers)=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 &registers)
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 &registers, 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