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 auto c = constant_cast(this->arg);
317 if (c.get()) {
318// GNU complex revalues cos(0, i0) evaluates to (1, -i0). This is casuing a
319// problem with the c and fortran binding tests.
320 if (c->is(0)) {
321 return one<T, SAFE_MATH> ();
322 }
323 return constant<T, SAFE_MATH> (this->evaluate());
324 }
325
326 auto ap1 = piecewise_1D_cast(this->arg);
327 if (ap1.get()) {
328 return piecewise_1D(this->evaluate(),
329 ap1->get_arg(),
330 ap1->get_scale(),
331 ap1->get_offset());
332 }
333
334 auto ap2 = piecewise_2D_cast(this->arg);
335 if (ap2.get()) {
336 return piecewise_2D(this->evaluate(),
337 ap2->get_num_columns(),
338 ap2->get_left(), ap2->get_x_scale(), ap2->get_x_offset(),
339 ap2->get_right(), ap2->get_y_scale(), ap2->get_y_offset());
340 }
341
342// Cos(ArcTan(x, y)) -> x/Sqrt(x^2 + y^2)
343 auto temp = atan_cast(this->arg);
344 if (temp.get()) {
345 return temp->get_left() /
346 (sqrt(temp->get_left()*temp->get_left() +
347 temp->get_right()*temp->get_right()));
348 }
349
350// Remove negative constants from the arguments.
351 auto am = multiply_cast(this->arg);
352 if (am.get()) {
353 auto lc = constant_cast(am->get_left());
354 if (lc.get() && lc->evaluate().is_negative()) {
355 return cos(-this->arg);
356 }
357 }
358
359 return this->shared_from_this();
360 }
361
362//------------------------------------------------------------------------------
369//------------------------------------------------------------------------------
372 if (this->is_match(x)) {
373 return one<T, SAFE_MATH> ();
374 }
375
376 const size_t hash = reinterpret_cast<size_t> (x.get());
377 if (this->df_cache.find(hash) == this->df_cache.end()) {
378 this->df_cache[hash] = -sin(this->arg)*this->arg->df(x);
379 }
380 return this->df_cache[hash];
381 }
382
383//------------------------------------------------------------------------------
391//------------------------------------------------------------------------------
393 compile(std::ostringstream &stream,
394 jit::register_map &registers,
396 const jit::register_usage &usage) {
397 if (registers.find(this) == registers.end()) {
398 shared_leaf<T, SAFE_MATH> a = this->arg->compile(stream,
399 registers,
400 indices,
401 usage);
402
403 registers[this] = jit::to_string('r', this);
404 stream << " const ";
405 jit::add_type<T> (stream);
406 stream << " " << registers[this] << " = cos("
407 << registers[a.get()] << ")";
408 this->endline(stream, usage);
409 }
410
411 return this->shared_from_this();
412 }
413
414//------------------------------------------------------------------------------
419//------------------------------------------------------------------------------
421 if (this == x.get()) {
422 return true;
423 }
424
425 auto x_cast = cos_cast(x);
426 if (x_cast.get()) {
427 return this->arg->is_match(x_cast->get_arg());
428 }
429
430 return false;
431 }
432
433//------------------------------------------------------------------------------
435//------------------------------------------------------------------------------
436 virtual void to_latex() const {
437 std::cout << "\\cos\\left(";
438 this->arg->to_latex();
439 std::cout << "\\right)";
440 }
441
442//------------------------------------------------------------------------------
446//------------------------------------------------------------------------------
448 if (this->has_pseudo()) {
449 return cos(this->arg->remove_pseudo());
450 }
451 return this->shared_from_this();
452 }
453
454//------------------------------------------------------------------------------
460//------------------------------------------------------------------------------
461 virtual shared_leaf<T, SAFE_MATH> to_vizgraph(std::stringstream &stream,
462 jit::register_map &registers) {
463 if (registers.find(this) == registers.end()) {
464 const std::string name = jit::to_string('r', this);
465 registers[this] = name;
466 stream << " " << name
467 << " [label = \"cos\", shape = oval, style = filled, fillcolor = blue, fontcolor = white];" << std::endl;
468
469 auto a = this->arg->to_vizgraph(stream, registers);
470 stream << " " << name << " -- " << registers[a.get()] << ";" << std::endl;
471 }
472
473 return this->shared_from_this();
474 }
475 };
476
477//------------------------------------------------------------------------------
485//------------------------------------------------------------------------------
486 template<jit::float_scalar T, bool SAFE_MATH=false>
488 auto temp = std::make_shared<cosine_node<T, SAFE_MATH>> (x)->reduce();
489// Test for hash collisions.
490 for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) {
491 if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) ==
494 return temp;
495 } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) {
497 }
498 }
499#if defined(__clang__) || defined(__GNUC__)
501#else
502 assert(false && "Should never reach.");
503#endif
504 }
505
507 template<jit::float_scalar T, bool SAFE_MATH=false>
508 using shared_cosine = std::shared_ptr<cosine_node<T, SAFE_MATH>>;
509
510//------------------------------------------------------------------------------
518//------------------------------------------------------------------------------
519 template<jit::float_scalar T, bool SAFE_MATH=false>
521 return std::dynamic_pointer_cast<cosine_node<T, SAFE_MATH>> (x);
522 }
523
524//******************************************************************************
525// Tangent node.
526//******************************************************************************
527//------------------------------------------------------------------------------
537//------------------------------------------------------------------------------
538 template<jit::float_scalar T, bool SAFE_MATH=false>
542
543//******************************************************************************
544// Arctangent node.
545//******************************************************************************
546//------------------------------------------------------------------------------
551//------------------------------------------------------------------------------
552 template<jit::float_scalar T, bool SAFE_MATH=false>
553 class arctan_node final : public branch_node<T, SAFE_MATH> {
554 private:
555//------------------------------------------------------------------------------
561//------------------------------------------------------------------------------
562 static std::string to_string(leaf_node<T, SAFE_MATH> *l,
564 return "atan" + jit::format_to_string(reinterpret_cast<size_t> (l))
565 + jit::format_to_string(reinterpret_cast<size_t> (r));
566 }
567
568 public:
569//------------------------------------------------------------------------------
574//------------------------------------------------------------------------------
578
579//------------------------------------------------------------------------------
585//------------------------------------------------------------------------------
587 backend::buffer<T> left = this->left->evaluate();
588 backend::buffer<T> right = this->right->evaluate();
589 return backend::atan(left, right);
590 }
591
592//------------------------------------------------------------------------------
596//------------------------------------------------------------------------------
598 auto l = constant_cast(this->left);
599 auto r = constant_cast(this->right);
600 if (l.get() && r.get()) {
601 return constant<T, SAFE_MATH> (this->evaluate());
602 }
603
604 auto pl1 = piecewise_1D_cast(this->left);
605 auto pr1 = piecewise_1D_cast(this->right);
606
607 if (pl1.get() && (r.get() || pl1->is_arg_match(this->right))) {
608 return piecewise_1D(this->evaluate(), pl1->get_arg(),
609 pl1->get_scale(), pl1->get_offset());
610 } else if (pr1.get() && (l.get() || pr1->is_arg_match(this->left))) {
611 return piecewise_1D(this->evaluate(), pr1->get_arg(),
612 pr1->get_scale(), pr1->get_offset());
613 }
614
615 auto pl2 = piecewise_2D_cast(this->left);
616 auto pr2 = piecewise_2D_cast(this->right);
617
618 if (pl2.get() && (r.get() || pl2->is_arg_match(this->right))) {
619 return piecewise_2D(this->evaluate(),
620 pl2->get_num_columns(),
621 pl2->get_left(), pl2->get_x_scale(), pl2->get_x_offset(),
622 pl2->get_right(), pl2->get_y_scale(), pl2->get_y_offset());
623 } else if (pr2.get() && (l.get() || pr2->is_arg_match(this->left))) {
624 return piecewise_2D(this->evaluate(),
625 pr2->get_num_columns(),
626 pr2->get_left(), pr2->get_x_scale(), pr2->get_x_offset(),
627 pr2->get_right(), pr2->get_y_scale(), pr2->get_y_offset());
628 }
629
630// Combine 2D and 1D piecewise constants if a row or column matches.
631 if (pr2.get() && pr2->is_row_match(this->left)) {
632 backend::buffer<T> result = pl1->evaluate();
633 result.atan_row(pr2->evaluate());
634 return piecewise_2D(result,
635 pr2->get_num_columns(),
636 pr2->get_left(), pr2->get_x_scale(), pr2->get_x_offset(),
637 pr2->get_right(), pr2->get_y_scale(), pr2->get_y_offset());
638 } else if (pr2.get() && pr2->is_col_match(this->left)) {
639 backend::buffer<T> result = pl1->evaluate();
640 result.atan_col(pr2->evaluate());
641 return piecewise_2D(result,
642 pr2->get_num_columns(),
643 pr2->get_left(), pr2->get_x_scale(), pr2->get_x_offset(),
644 pr2->get_right(), pr2->get_y_scale(), pr2->get_y_offset());
645 } else if (pl2.get() && pl2->is_row_match(this->right)) {
646 backend::buffer<T> result = pl2->evaluate();
647 result.atan_row(pr1->evaluate());
648 return piecewise_2D(result,
649 pl2->get_num_columns(),
650 pl2->get_left(), pl2->get_x_scale(), pl2->get_x_offset(),
651 pl2->get_right(), pl2->get_y_scale(), pl2->get_y_offset());
652 } else if (pl2.get() && pl2->is_col_match(this->right)) {
653 backend::buffer<T> result = pl2->evaluate();
654 result.atan_col(pr1->evaluate());
655 return piecewise_2D(result,
656 pl2->get_num_columns(),
657 pl2->get_left(), pl2->get_x_scale(), pl2->get_x_offset(),
658 pl2->get_right(), pl2->get_y_scale(), pl2->get_y_offset());
659 }
660
661 return this->shared_from_this();
662 }
663
664//------------------------------------------------------------------------------
671//------------------------------------------------------------------------------
674 if (this->is_match(x)) {
675 return one<T, SAFE_MATH> ();
676 }
677
678 const size_t hash = reinterpret_cast<size_t> (x.get());
679 if (this->df_cache.find(hash) == this->df_cache.end()) {
680 auto z = this->right/this->left;
681 this->df_cache[hash] = (1.0/(1.0 + z*z))*z->df(x);
682 }
683 return this->df_cache[hash];
684 }
685
686//------------------------------------------------------------------------------
694//------------------------------------------------------------------------------
696 compile(std::ostringstream &stream,
697 jit::register_map &registers,
699 const jit::register_usage &usage) {
700 if (registers.find(this) == registers.end()) {
701 shared_leaf<T, SAFE_MATH> l = this->left->compile(stream,
702 registers,
703 indices,
704 usage);
705 shared_leaf<T, SAFE_MATH> r = this->right->compile(stream,
706 registers,
707 indices,
708 usage);
709
710 registers[this] = jit::to_string('r', this);
711 stream << " const ";
712 jit::add_type<T> (stream);
713 if constexpr (jit::complex_scalar<T>) {
714 stream << " " << registers[this] << " = atan("
715 << registers[r.get()] << "/"
716 << registers[l.get()];
717 } else {
718 stream << " " << registers[this] << " = atan2("
719 << registers[r.get()] << ","
720 << registers[l.get()];
721 }
722 stream << ")";
723 this->endline(stream, usage);
724 }
725
726 return this->shared_from_this();
727 }
728
729//------------------------------------------------------------------------------
734//------------------------------------------------------------------------------
736 if (this == x.get()) {
737 return true;
738 }
739
740 auto x_cast = atan_cast(x);
741 if (x_cast.get()) {
742 return this->left->is_match(x_cast->get_left()) &&
743 this->right->is_match(x_cast->get_right());
744 }
745
746 return false;
747 }
748
749//------------------------------------------------------------------------------
751//------------------------------------------------------------------------------
752 virtual void to_latex() const {
753 std::cout << "atan\\left(";
754 this->left->to_latex();
755 std::cout << ",";
756 this->right->to_latex();
757 std::cout << "\\right)";
758 }
759
760//------------------------------------------------------------------------------
764//------------------------------------------------------------------------------
766 if (this->has_pseudo()) {
767 return atan(this->left->remove_pseudo(),
768 this->right->remove_pseudo());
769 }
770 return this->shared_from_this();
771 }
772
773//------------------------------------------------------------------------------
779//------------------------------------------------------------------------------
780 virtual shared_leaf<T, SAFE_MATH> to_vizgraph(std::stringstream &stream,
781 jit::register_map &registers) {
782 if (registers.find(this) == registers.end()) {
783 const std::string name = jit::to_string('r', this);
784 registers[this] = name;
785 stream << " " << name
786 << " [label = \"atan\", shape = oval, style = filled, fillcolor = blue, fontcolor = white];" << std::endl;
787
788 auto l = this->left->to_vizgraph(stream, registers);
789 stream << " " << name << " -- " << registers[l.get()] << ";" << std::endl;
790 auto r = this->right->to_vizgraph(stream, registers);
791 stream << " " << name << " -- " << registers[r.get()] << ";" << std::endl;
792 }
793
794 return this->shared_from_this();
795 }
796 };
797
798//------------------------------------------------------------------------------
806//------------------------------------------------------------------------------
807 template<jit::float_scalar T, bool SAFE_MATH=false>
810 auto temp = std::make_shared<arctan_node<T, SAFE_MATH>> (l, r)->reduce();
811// Test for hash collisions.
812 for (size_t i = temp->get_hash(); i < std::numeric_limits<size_t>::max(); i++) {
813 if (leaf_node<T, SAFE_MATH>::caches.nodes.find(i) ==
816 return temp;
817 } else if (temp->is_match(leaf_node<T, SAFE_MATH>::caches.nodes[i])) {
819 }
820 }
821#if defined(__clang__) || defined(__GNUC__)
823#else
824 assert(false && "Should never reach.");
825#endif
826 }
827
828//------------------------------------------------------------------------------
837//------------------------------------------------------------------------------
838 template<jit::float_scalar T, jit::float_scalar L, bool SAFE_MATH=false>
841 return atan(constant<T, SAFE_MATH> (static_cast<T> (l)), r);
842 }
843
844//------------------------------------------------------------------------------
853//------------------------------------------------------------------------------
854 template<jit::float_scalar T, jit::float_scalar R, bool SAFE_MATH=false>
856 const R r) {
857 return atan(l, constant<T, SAFE_MATH> (static_cast<T> (r)));
858 }
859
861 template<jit::float_scalar T, bool SAFE_MATH=false>
862 using shared_atan = std::shared_ptr<arctan_node<T, SAFE_MATH>>;
863
864//------------------------------------------------------------------------------
872//------------------------------------------------------------------------------
873 template<jit::float_scalar T, bool SAFE_MATH=false>
875 return std::dynamic_pointer_cast<arctan_node<T, SAFE_MATH>> (x);
876 }
877}
878
879#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:667
void atan_row(const buffer< T > &x)
Atan row operation.
Definition backend.hpp:623
void cos()
Take cos.
Definition backend.hpp:250
Class representing a sine_node leaf.
Definition trigonometry.hpp:553
virtual shared_leaf< T, SAFE_MATH > df(shared_leaf< T, SAFE_MATH > x)
Transform node to derivative.
Definition trigonometry.hpp:673
arctan_node(shared_leaf< T, SAFE_MATH > x, shared_leaf< T, SAFE_MATH > y)
Construct a arctan_node node.
Definition trigonometry.hpp:575
virtual shared_leaf< T, SAFE_MATH > reduce()
Reduce a arctan node.
Definition trigonometry.hpp:597
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:696
virtual shared_leaf< T, SAFE_MATH > remove_pseudo()
Remove pseudo variable nodes.
Definition trigonometry.hpp:765
virtual bool is_match(shared_leaf< T, SAFE_MATH > x)
Query if the nodes match.
Definition trigonometry.hpp:735
virtual shared_leaf< T, SAFE_MATH > to_vizgraph(std::stringstream &stream, jit::register_map &registers)
Convert the node to vizgraph.
Definition trigonometry.hpp:780
virtual backend::buffer< T > evaluate()
Evaluate the results of arctan.
Definition trigonometry.hpp:586
virtual void to_latex() const
Convert the node to latex.
Definition trigonometry.hpp:752
Class representing a branch node.
Definition node.hpp:1165
shared_leaf< T, SAFE_MATH > right
Right branch of the tree.
Definition node.hpp:1170
shared_leaf< T, SAFE_MATH > left
Left branch of the tree.
Definition node.hpp:1168
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:461
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:393
virtual shared_leaf< T, SAFE_MATH > df(shared_leaf< T, SAFE_MATH > x)
Transform node to derivative.
Definition trigonometry.hpp:371
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)
Query if the nodes match.
Definition trigonometry.hpp:420
virtual void to_latex() const
Convert the node to latex.
Definition trigonometry.hpp:436
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:447
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:639
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:620
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)
Query 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:1051
shared_leaf< T, SAFE_MATH > arg
Argument.
Definition node.hpp:1054
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:1130
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:1354
shared_leaf< T, SAFE_MATH > tan(shared_leaf< T, SAFE_MATH > x)
Define tangent convenience function.
Definition trigonometry.hpp:539
std::shared_ptr< arctan_node< T, SAFE_MATH > > shared_atan
Convenience type alias for shared add nodes.
Definition trigonometry.hpp:862
constexpr shared_leaf< T, SAFE_MATH > zero()
Forward declare for zero.
Definition node.hpp:986
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:808
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:608
shared_atan< T, SAFE_MATH > atan_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a power node.
Definition trigonometry.hpp:874
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:1034
constexpr T i
Convenience type for imaginary constant.
Definition node.hpp:1018
shared_leaf< T, SAFE_MATH > sin(shared_leaf< T, SAFE_MATH > x)
Define sine convenience function.
Definition trigonometry.hpp:229
shared_leaf< T, SAFE_MATH > sqrt(shared_leaf< T, SAFE_MATH > x)
Define sqrt convenience 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:508
std::shared_ptr< leaf_node< T, SAFE_MATH > > shared_leaf
Convenience type alias for shared leaf nodes.
Definition node.hpp:676
shared_leaf< T, SAFE_MATH > cos(shared_leaf< T, SAFE_MATH > x)
Define cosine convenience function.
Definition trigonometry.hpp:487
shared_cosine< T, SAFE_MATH > cos_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a cosine node.
Definition trigonometry.hpp:520
std::string format_to_string(const T value)
Convert a value to a string while avoiding locale.
Definition register.hpp:212
std::map< void *, size_t > register_usage
Type alias for counting register usage.
Definition register.hpp:259
std::map< void *, std::string > register_map
Type alias for mapping node pointers to register names.
Definition register.hpp:257
std::string to_string(const char prefix, const NODE *pointer)
Convert a graph::leaf_node pointer to a string.
Definition register.hpp:246
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:292