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(),
72 ap1->get_arg(),
73 ap1->get_scale(),
74 ap1->get_offset());
75 }
76
77 auto ap2 = piecewise_2D_cast(this->arg);
78 if (ap2.get()) {
79 return piecewise_2D(this->evaluate(),
80 ap2->get_num_columns(),
81 ap2->get_left(), ap2->get_x_scale(), ap2->get_x_offset(),
82 ap2->get_right(), ap2->get_y_scale(), ap2->get_y_offset());
83 }
84
85// Sin(ArcTan(x, y)) -> y/Sqrt(x^2 + y^2)
86 auto temp = atan_cast(this->arg);
87 if (temp.get()) {
88 return temp->get_right() /
89 (sqrt(temp->get_left()*temp->get_left() +
90 temp->get_right()*temp->get_right()));
91 }
92
93// Remove negative constants from the arguments.
94 auto am = multiply_cast(this->arg);
95 if (am.get()) {
96 auto lc = constant_cast(am->get_left());
97 if (lc.get() && lc->evaluate().is_negative()) {
98 return -sin(-this->arg);
99 }
100 }
101
102 return this->shared_from_this();
103 }
104
105//------------------------------------------------------------------------------
112//------------------------------------------------------------------------------
115 if (this->is_match(x)) {
116 return one<T, SAFE_MATH> ();
117 }
118
119 const size_t hash = reinterpret_cast<size_t> (x.get());
120 if (this->df_cache.find(hash) == this->df_cache.end()) {
121 this->df_cache[hash] = cos(this->arg)*this->arg->df(x);
122 }
123 return this->df_cache[hash];
124 }
125
126//------------------------------------------------------------------------------
134//------------------------------------------------------------------------------
135 virtual shared_leaf<T, SAFE_MATH> compile(std::ostringstream &stream,
136 jit::register_map &registers,
138 const jit::register_usage &usage) {
139 if (registers.find(this) == registers.end()) {
140 shared_leaf<T, SAFE_MATH> a = this->arg->compile(stream,
141 registers,
142 indices,
143 usage);
144
145 registers[this] = jit::to_string('r', this);
146 stream << " const ";
147 jit::add_type<T> (stream);
148 stream << " " << registers[this] << " = sin("
149 << registers[a.get()] << ")";
150 this->endline(stream, usage);
151 }
152
153 return this->shared_from_this();
154 }
155
156//------------------------------------------------------------------------------
161//------------------------------------------------------------------------------
163 if (this == x.get()) {
164 return true;
165 }
166
167 auto x_cast = sin_cast(x);
168 if (x_cast.get()) {
169 return this->arg->is_match(x_cast->get_arg());
170 }
171
172 return false;
173 }
174
175//------------------------------------------------------------------------------
177//------------------------------------------------------------------------------
178 virtual void to_latex() const {
179 std::cout << "\\sin\\left(";
180 this->arg->to_latex();
181 std::cout << "\\right)";
182 }
183
184//------------------------------------------------------------------------------
188//------------------------------------------------------------------------------
190 if (this->has_pseudo()) {
191 return sin(this->arg->remove_pseudo());
192 }
193 return this->shared_from_this();
194 }
195
196//------------------------------------------------------------------------------
202//------------------------------------------------------------------------------
203 virtual shared_leaf<T, SAFE_MATH> to_vizgraph(std::stringstream &stream,
204 jit::register_map &registers) {
205 if (registers.find(this) == registers.end()) {
206 const std::string name = jit::to_string('r', this);
207 registers[this] = name;
208 stream << " " << name
209 << " [label = \"sin\", shape = oval, style = filled, fillcolor = blue, fontcolor = white];" << std::endl;
210
211 auto a = this->arg->to_vizgraph(stream, registers);
212 stream << " " << name << " -- " << registers[a.get()] << ";" << std::endl;
213 }
214
215 return this->shared_from_this();
216 }
217 };
218
219//------------------------------------------------------------------------------
227//------------------------------------------------------------------------------
228 template<jit::float_scalar T, bool SAFE_MATH=false>
230 auto temp = std::make_shared<sine_node<T, SAFE_MATH>> (x)->reduce();
231// Test for hash collisions.
232 for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) {
233 if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) ==
236 return temp;
237 } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) {
239 }
240 }
241#if defined(__clang__) || defined(__GNUC__)
243#else
244 assert(false && "Should never reach.");
245#endif
246 }
247
249 template<jit::float_scalar T, bool SAFE_MATH=false>
250 using shared_sine = std::shared_ptr<sine_node<T, SAFE_MATH>>;
251
252//------------------------------------------------------------------------------
260//------------------------------------------------------------------------------
261 template<jit::float_scalar T, bool SAFE_MATH=false>
263 return std::dynamic_pointer_cast<sine_node<T, SAFE_MATH>> (x);
264 }
265
266//******************************************************************************
267// Cosine node.
268//******************************************************************************
269//------------------------------------------------------------------------------
274//------------------------------------------------------------------------------
275 template<jit::float_scalar T, bool SAFE_MATH=false>
276 class cosine_node final : public straight_node<T, SAFE_MATH> {
277 private:
278//------------------------------------------------------------------------------
283//------------------------------------------------------------------------------
284 static std::string to_string(leaf_node<T, SAFE_MATH> *a) {
285 return "cos" + jit::format_to_string(reinterpret_cast<size_t> (a));
286 }
287
288 public:
289//------------------------------------------------------------------------------
293//------------------------------------------------------------------------------
296
297//------------------------------------------------------------------------------
303//------------------------------------------------------------------------------
305 backend::buffer<T> result = this->arg->evaluate();
306 result.cos();
307 return result;
308 }
309
310//------------------------------------------------------------------------------
314//------------------------------------------------------------------------------
316 if (constant_cast(this->arg).get()) {
317 return constant<T, SAFE_MATH> (this->evaluate());
318 }
319
320 auto ap1 = piecewise_1D_cast(this->arg);
321 if (ap1.get()) {
322 return piecewise_1D(this->evaluate(),
323 ap1->get_arg(),
324 ap1->get_scale(),
325 ap1->get_offset());
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(), ap2->get_x_scale(), ap2->get_x_offset(),
333 ap2->get_right(), ap2->get_y_scale(), ap2->get_y_offset());
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 shared_leaf<T, SAFE_MATH> a = this->arg->compile(stream,
393 registers,
394 indices,
395 usage);
396
397 registers[this] = jit::to_string('r', this);
398 stream << " const ";
399 jit::add_type<T> (stream);
400 stream << " " << registers[this] << " = cos("
401 << registers[a.get()] << ")";
402 this->endline(stream, usage);
403 }
404
405 return this->shared_from_this();
406 }
407
408//------------------------------------------------------------------------------
413//------------------------------------------------------------------------------
415 if (this == x.get()) {
416 return true;
417 }
418
419 auto x_cast = cos_cast(x);
420 if (x_cast.get()) {
421 return this->arg->is_match(x_cast->get_arg());
422 }
423
424 return false;
425 }
426
427//------------------------------------------------------------------------------
429//------------------------------------------------------------------------------
430 virtual void to_latex() const {
431 std::cout << "\\cos\\left(";
432 this->arg->to_latex();
433 std::cout << "\\right)";
434 }
435
436//------------------------------------------------------------------------------
440//------------------------------------------------------------------------------
442 if (this->has_pseudo()) {
443 return cos(this->arg->remove_pseudo());
444 }
445 return this->shared_from_this();
446 }
447
448//------------------------------------------------------------------------------
454//------------------------------------------------------------------------------
455 virtual shared_leaf<T, SAFE_MATH> to_vizgraph(std::stringstream &stream,
456 jit::register_map &registers) {
457 if (registers.find(this) == registers.end()) {
458 const std::string name = jit::to_string('r', this);
459 registers[this] = name;
460 stream << " " << name
461 << " [label = \"cos\", shape = oval, style = filled, fillcolor = blue, fontcolor = white];" << std::endl;
462
463 auto a = this->arg->to_vizgraph(stream, registers);
464 stream << " " << name << " -- " << registers[a.get()] << ";" << std::endl;
465 }
466
467 return this->shared_from_this();
468 }
469 };
470
471//------------------------------------------------------------------------------
479//------------------------------------------------------------------------------
480 template<jit::float_scalar T, bool SAFE_MATH=false>
482 auto temp = std::make_shared<cosine_node<T, SAFE_MATH>> (x)->reduce();
483// Test for hash collisions.
484 for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) {
485 if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) ==
488 return temp;
489 } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) {
491 }
492 }
493#if defined(__clang__) || defined(__GNUC__)
495#else
496 assert(false && "Should never reach.");
497#endif
498 }
499
501 template<jit::float_scalar T, bool SAFE_MATH=false>
502 using shared_cosine = std::shared_ptr<cosine_node<T, SAFE_MATH>>;
503
504//------------------------------------------------------------------------------
512//------------------------------------------------------------------------------
513 template<jit::float_scalar T, bool SAFE_MATH=false>
515 return std::dynamic_pointer_cast<cosine_node<T, SAFE_MATH>> (x);
516 }
517
518//******************************************************************************
519// Tangent node.
520//******************************************************************************
521//------------------------------------------------------------------------------
531//------------------------------------------------------------------------------
532 template<jit::float_scalar T, bool SAFE_MATH=false>
536
537//******************************************************************************
538// Arctangent node.
539//******************************************************************************
540//------------------------------------------------------------------------------
545//------------------------------------------------------------------------------
546 template<jit::float_scalar T, bool SAFE_MATH=false>
547 class arctan_node final : public branch_node<T, SAFE_MATH> {
548 private:
549//------------------------------------------------------------------------------
555//------------------------------------------------------------------------------
556 static std::string to_string(leaf_node<T, SAFE_MATH> *l,
558 return "atan" + jit::format_to_string(reinterpret_cast<size_t> (l))
559 + jit::format_to_string(reinterpret_cast<size_t> (r));
560 }
561
562 public:
563//------------------------------------------------------------------------------
568//------------------------------------------------------------------------------
572
573//------------------------------------------------------------------------------
579//------------------------------------------------------------------------------
581 backend::buffer<T> left = this->left->evaluate();
582 backend::buffer<T> right = this->right->evaluate();
583 return backend::atan(left, right);
584 }
585
586//------------------------------------------------------------------------------
590//------------------------------------------------------------------------------
592 auto l = constant_cast(this->left);
593 auto r = constant_cast(this->right);
594 if (l.get() && r.get()) {
595 return constant<T, SAFE_MATH> (this->evaluate());
596 }
597
598 auto pl1 = piecewise_1D_cast(this->left);
599 auto pr1 = piecewise_1D_cast(this->right);
600
601 if (pl1.get() && (r.get() || pl1->is_arg_match(this->right))) {
602 return piecewise_1D(this->evaluate(), pl1->get_arg(),
603 pl1->get_scale(), pl1->get_offset());
604 } else if (pr1.get() && (l.get() || pr1->is_arg_match(this->left))) {
605 return piecewise_1D(this->evaluate(), pr1->get_arg(),
606 pr1->get_scale(), pr1->get_offset());
607 }
608
609 auto pl2 = piecewise_2D_cast(this->left);
610 auto pr2 = piecewise_2D_cast(this->right);
611
612 if (pl2.get() && (r.get() || pl2->is_arg_match(this->right))) {
613 return piecewise_2D(this->evaluate(),
614 pl2->get_num_columns(),
615 pl2->get_left(), pl2->get_x_scale(), pl2->get_x_offset(),
616 pl2->get_right(), pl2->get_y_scale(), pl2->get_y_offset());
617 } else if (pr2.get() && (l.get() || pr2->is_arg_match(this->left))) {
618 return piecewise_2D(this->evaluate(),
619 pr2->get_num_columns(),
620 pr2->get_left(), pr2->get_x_scale(), pr2->get_x_offset(),
621 pr2->get_right(), pr2->get_y_scale(), pr2->get_y_offset());
622 }
623
624// Combine 2D and 1D piecewise constants if a row or column matches.
625 if (pr2.get() && pr2->is_row_match(this->left)) {
626 backend::buffer<T> result = pl1->evaluate();
627 result.atan_row(pr2->evaluate());
628 return piecewise_2D(result,
629 pr2->get_num_columns(),
630 pr2->get_left(), pr2->get_x_scale(), pr2->get_x_offset(),
631 pr2->get_right(), pr2->get_y_scale(), pr2->get_y_offset());
632 } else if (pr2.get() && pr2->is_col_match(this->left)) {
633 backend::buffer<T> result = pl1->evaluate();
634 result.atan_col(pr2->evaluate());
635 return piecewise_2D(result,
636 pr2->get_num_columns(),
637 pr2->get_left(), pr2->get_x_scale(), pr2->get_x_offset(),
638 pr2->get_right(), pr2->get_y_scale(), pr2->get_y_offset());
639 } else if (pl2.get() && pl2->is_row_match(this->right)) {
640 backend::buffer<T> result = pl2->evaluate();
641 result.atan_row(pr1->evaluate());
642 return piecewise_2D(result,
643 pl2->get_num_columns(),
644 pl2->get_left(), pl2->get_x_scale(), pl2->get_x_offset(),
645 pl2->get_right(), pl2->get_y_scale(), pl2->get_y_offset());
646 } else if (pl2.get() && pl2->is_col_match(this->right)) {
647 backend::buffer<T> result = pl2->evaluate();
648 result.atan_col(pr1->evaluate());
649 return piecewise_2D(result,
650 pl2->get_num_columns(),
651 pl2->get_left(), pl2->get_x_scale(), pl2->get_x_offset(),
652 pl2->get_right(), pl2->get_y_scale(), pl2->get_y_offset());
653 }
654
655 return this->shared_from_this();
656 }
657
658//------------------------------------------------------------------------------
665//------------------------------------------------------------------------------
668 if (this->is_match(x)) {
669 return one<T, SAFE_MATH> ();
670 }
671
672 const size_t hash = reinterpret_cast<size_t> (x.get());
673 if (this->df_cache.find(hash) == this->df_cache.end()) {
674 auto z = this->right/this->left;
675 this->df_cache[hash] = (1.0/(1.0 + z*z))*z->df(x);
676 }
677 return this->df_cache[hash];
678 }
679
680//------------------------------------------------------------------------------
688//------------------------------------------------------------------------------
690 compile(std::ostringstream &stream,
691 jit::register_map &registers,
693 const jit::register_usage &usage) {
694 if (registers.find(this) == registers.end()) {
695 shared_leaf<T, SAFE_MATH> l = this->left->compile(stream,
696 registers,
697 indices,
698 usage);
699 shared_leaf<T, SAFE_MATH> r = this->right->compile(stream,
700 registers,
701 indices,
702 usage);
703
704 registers[this] = jit::to_string('r', this);
705 stream << " const ";
706 jit::add_type<T> (stream);
707 if constexpr (jit::complex_scalar<T>) {
708 stream << " " << registers[this] << " = atan("
709 << registers[r.get()] << "/"
710 << registers[l.get()];
711 } else {
712 stream << " " << registers[this] << " = atan2("
713 << registers[r.get()] << ","
714 << registers[l.get()];
715 }
716 stream << ")";
717 this->endline(stream, usage);
718 }
719
720 return this->shared_from_this();
721 }
722
723//------------------------------------------------------------------------------
728//------------------------------------------------------------------------------
730 if (this == x.get()) {
731 return true;
732 }
733
734 auto x_cast = atan_cast(x);
735 if (x_cast.get()) {
736 return this->left->is_match(x_cast->get_left()) &&
737 this->right->is_match(x_cast->get_right());
738 }
739
740 return false;
741 }
742
743//------------------------------------------------------------------------------
745//------------------------------------------------------------------------------
746 virtual void to_latex() const {
747 std::cout << "atan\\left(";
748 this->left->to_latex();
749 std::cout << ",";
750 this->right->to_latex();
751 std::cout << "\\right)";
752 }
753
754//------------------------------------------------------------------------------
758//------------------------------------------------------------------------------
760 if (this->has_pseudo()) {
761 return atan(this->left->remove_pseudo(),
762 this->right->remove_pseudo());
763 }
764 return this->shared_from_this();
765 }
766
767//------------------------------------------------------------------------------
773//------------------------------------------------------------------------------
774 virtual shared_leaf<T, SAFE_MATH> to_vizgraph(std::stringstream &stream,
775 jit::register_map &registers) {
776 if (registers.find(this) == registers.end()) {
777 const std::string name = jit::to_string('r', this);
778 registers[this] = name;
779 stream << " " << name
780 << " [label = \"atan\", shape = oval, style = filled, fillcolor = blue, fontcolor = white];" << std::endl;
781
782 auto l = this->left->to_vizgraph(stream, registers);
783 stream << " " << name << " -- " << registers[l.get()] << ";" << std::endl;
784 auto r = this->right->to_vizgraph(stream, registers);
785 stream << " " << name << " -- " << registers[r.get()] << ";" << std::endl;
786 }
787
788 return this->shared_from_this();
789 }
790 };
791
792//------------------------------------------------------------------------------
800//------------------------------------------------------------------------------
801 template<jit::float_scalar T, bool SAFE_MATH=false>
804 auto temp = std::make_shared<arctan_node<T, SAFE_MATH>> (l, r)->reduce();
805// Test for hash collisions.
806 for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) {
807 if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) ==
810 return temp;
811 } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) {
813 }
814 }
815#if defined(__clang__) || defined(__GNUC__)
817#else
818 assert(false && "Should never reach.");
819#endif
820 }
821
822//------------------------------------------------------------------------------
831//------------------------------------------------------------------------------
832 template<jit::float_scalar T, jit::float_scalar L, bool SAFE_MATH=false>
835 return atan(constant<T, SAFE_MATH> (static_cast<T> (l)), r);
836 }
837
838//------------------------------------------------------------------------------
847//------------------------------------------------------------------------------
848 template<jit::float_scalar T, jit::float_scalar R, bool SAFE_MATH=false>
850 const R r) {
851 return atan(l, constant<T, SAFE_MATH> (static_cast<T> (r)));
852 }
853
855 template<jit::float_scalar T, bool SAFE_MATH=false>
856 using shared_atan = std::shared_ptr<arctan_node<T, SAFE_MATH>>;
857
858//------------------------------------------------------------------------------
866//------------------------------------------------------------------------------
867 template<jit::float_scalar T, bool SAFE_MATH=false>
869 return std::dynamic_pointer_cast<arctan_node<T, SAFE_MATH>> (x);
870 }
871}
872
873#endif /* trigonometry_h */
Class representing a generic buffer.
Definition backend.hpp:29
void sin()
Take sin.
Definition backend.hpp:241
void atan_col(const buffer< T > &x)
Atan col operation.
Definition backend.hpp:635
void atan_row(const buffer< T > &x)
Atan row operation.
Definition backend.hpp:591
void cos()
Take cos.
Definition backend.hpp:250
Class representing a sine_node leaf.
Definition trigonometry.hpp:547
virtual shared_leaf< T, SAFE_MATH > df(shared_leaf< T, SAFE_MATH > x)
Transform node to derivative.
Definition trigonometry.hpp:667
arctan_node(shared_leaf< T, SAFE_MATH > x, shared_leaf< T, SAFE_MATH > y)
Construct a arctan_node node.
Definition trigonometry.hpp:569
virtual shared_leaf< T, SAFE_MATH > reduce()
Reduce a arctan node.
Definition trigonometry.hpp:591
virtual shared_leaf< T, SAFE_MATH > compile(std::ostringstream &stream, jit::register_map &registers, jit::register_map &indices, const jit::register_usage &usage)
Compile the node.
Definition trigonometry.hpp:690
virtual shared_leaf< T, SAFE_MATH > remove_pseudo()
Remove pseudo variable nodes.
Definition trigonometry.hpp:759
virtual bool is_match(shared_leaf< T, SAFE_MATH > x)
Querey if the nodes match.
Definition trigonometry.hpp:729
virtual shared_leaf< T, SAFE_MATH > to_vizgraph(std::stringstream &stream, jit::register_map &registers)
Convert the node to vizgraph.
Definition trigonometry.hpp:774
virtual backend::buffer< T > evaluate()
Evaluate the results of arctan.
Definition trigonometry.hpp:580
virtual void to_latex() const
Convert the node to latex.
Definition trigonometry.hpp:746
Class representing a branch node.
Definition node.hpp:1173
shared_leaf< T, SAFE_MATH > right
Right branch of the tree.
Definition node.hpp:1178
shared_leaf< T, SAFE_MATH > left
Left branch of the tree.
Definition node.hpp:1176
Class representing a cosine_node leaf.
Definition trigonometry.hpp:276
virtual shared_leaf< T, SAFE_MATH > to_vizgraph(std::stringstream &stream, jit::register_map &registers)
Convert the node to vizgraph.
Definition trigonometry.hpp:455
virtual shared_leaf< T, SAFE_MATH > compile(std::ostringstream &stream, jit::register_map &registers, jit::register_map &indices, 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:294
virtual shared_leaf< T, SAFE_MATH > reduce()
Reduce the cos(x).
Definition trigonometry.hpp:315
virtual bool is_match(shared_leaf< T, SAFE_MATH > x)
Querey if the nodes match.
Definition trigonometry.hpp:414
virtual void to_latex() const
Convert the node to latex.
Definition trigonometry.hpp:430
virtual backend::buffer< T > evaluate()
Evaluate the results of cosine.
Definition trigonometry.hpp:304
virtual shared_leaf< T, SAFE_MATH > remove_pseudo()
Remove pseudo variable nodes.
Definition trigonometry.hpp:441
Class representing a node leaf.
Definition node.hpp:364
virtual void endline(std::ostringstream &stream, const jit::register_usage &usage) const final
End a line in the kernel source.
Definition node.hpp:637
std::map< size_t, std::shared_ptr< leaf_node< T, SAFE_MATH > > > df_cache
Cache derivative terms.
Definition node.hpp:371
virtual bool has_pseudo() const
Query if the node contains pseudo variables.
Definition node.hpp:618
const size_t hash
Hash for node.
Definition node.hpp:367
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:189
virtual shared_leaf< T, SAFE_MATH > to_vizgraph(std::stringstream &stream, jit::register_map &registers)
Convert the node to vizgraph.
Definition trigonometry.hpp:203
virtual void to_latex() const
Convert the node to latex.
Definition trigonometry.hpp:178
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:114
virtual bool is_match(shared_leaf< T, SAFE_MATH > x)
Querey if the nodes match.
Definition trigonometry.hpp:162
virtual shared_leaf< T, SAFE_MATH > compile(std::ostringstream &stream, jit::register_map &registers, jit::register_map &indices, const jit::register_usage &usage)
Compile the node.
Definition trigonometry.hpp:135
Class representing a straight node.
Definition node.hpp:1059
shared_leaf< T, SAFE_MATH > arg
Argument.
Definition node.hpp:1062
Complex scalar concept.
Definition register.hpp:24
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:1098
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:1323
shared_leaf< T, SAFE_MATH > tan(shared_leaf< T, SAFE_MATH > x)
Define tangent convience function.
Definition trigonometry.hpp:533
std::shared_ptr< arctan_node< T, SAFE_MATH > > shared_atan
Convenience type alias for shared add nodes.
Definition trigonometry.hpp:856
constexpr shared_leaf< T, SAFE_MATH > zero()
Forward declare for zero.
Definition node.hpp:994
std::shared_ptr< sine_node< T, SAFE_MATH > > shared_sine
Convenience type alias for shared sine nodes.
Definition trigonometry.hpp:250
shared_leaf< T, SAFE_MATH > atan(shared_leaf< T, SAFE_MATH > l, shared_leaf< T, SAFE_MATH > r)
Build arctan node.
Definition trigonometry.hpp:802
shared_sine< T, SAFE_MATH > sin_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a sine node.
Definition trigonometry.hpp:262
shared_piecewise_1D< T, SAFE_MATH > piecewise_1D_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a piecewise 1D node.
Definition piecewise.hpp:601
shared_atan< T, SAFE_MATH > atan_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a power node.
Definition trigonometry.hpp:868
shared_multiply< T, SAFE_MATH > multiply_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a multiply node.
Definition arithmetic.hpp:2723
shared_constant< T, SAFE_MATH > constant_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a constant node.
Definition node.hpp:1042
constexpr T i
Convinece type for imaginary constant.
Definition node.hpp:1026
shared_leaf< T, SAFE_MATH > sin(shared_leaf< T, SAFE_MATH > x)
Define sine convience function.
Definition trigonometry.hpp:229
shared_leaf< T, SAFE_MATH > sqrt(shared_leaf< T, SAFE_MATH > x)
Define sqrt convience function.
Definition math.hpp:279
std::shared_ptr< cosine_node< T, SAFE_MATH > > shared_cosine
Convenience type alias for shared cosine nodes.
Definition trigonometry.hpp:502
std::shared_ptr< leaf_node< T, SAFE_MATH > > shared_leaf
Convenience type alias for shared leaf nodes.
Definition node.hpp:673
shared_leaf< T, SAFE_MATH > cos(shared_leaf< T, SAFE_MATH > x)
Define cosine convience function.
Definition trigonometry.hpp:481
shared_cosine< T, SAFE_MATH > cos_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a cosine node.
Definition trigonometry.hpp:514
std::string format_to_string(const T value)
Convert a value to a string while avoiding locale.
Definition register.hpp:211
std::map< void *, size_t > register_usage
Type alias for counting register usage.
Definition register.hpp:258
std::map< void *, std::string > register_map
Type alias for mapping node pointers to register names.
Definition register.hpp:256
std::string to_string(const char prefix, const NODE *pointer)
Convert a graph::leaf_node pointer to a string.
Definition register.hpp:245
Base nodes of graph computation framework.
void piecewise_1D()
Tests for 1D piecewise nodes.
Definition piecewise_test.cpp:80
void piecewise_2D()
Tests for 2D piecewise nodes.
Definition piecewise_test.cpp:283