ALP User Documentation 0.7.alpha
Algebraic Programming User Documentation
Loading...
Searching...
No Matches
ops.hpp
Go to the documentation of this file.
1
2/*
3 * Copyright 2021 Huawei Technologies Co., Ltd.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
27#ifndef _H_GRB_OPERATORS
28#define _H_GRB_OPERATORS
29
30#include "internalops.hpp"
31#include "type_traits.hpp"
32
33
34namespace grb {
35
40 namespace operators {
41
54 template<
55 typename D1, typename D2 = D1, typename D3 = D2,
56 enum Backend implementation = config::default_backend
57 >
59 public internal::Operator<
60 internal::left_assign< D1, D2, D3, implementation >
61 >
62 {
63 public:
64
65 template< typename A, typename B, typename C, enum Backend D >
67
68 left_assign() {}
69 };
70
80 template<
81 typename D1, typename D2 = D1, typename D3 = D2,
82 enum Backend implementation = config::default_backend
83 >
85 public internal::Operator<
86 internal::left_assign_if< D1, D2, D3, implementation >
87 >
88 {
89 public:
90
91 template< typename A, typename B, typename C, enum Backend D >
93
95 };
96
109 template<
110 typename D1, typename D2 = D1, typename D3 = D2,
111 enum Backend implementation = config::default_backend
112 >
113 class right_assign : public internal::Operator<
114 internal::right_assign< D1, D2, D3, implementation >
115 >
116 {
117 public:
118
119 template< typename A, typename B, typename C, enum Backend D >
121
122 right_assign() {}
123 };
124
134 template<
135 typename D1, typename D2 = D1, typename D3 = D2,
136 enum Backend implementation = config::default_backend
137 >
138 class right_assign_if : public internal::Operator<
139 internal::right_assign_if< D1, D2, D3, implementation >
140 >
141 {
142 public:
143
144 template< typename A, typename B, typename C, enum Backend D >
146
147 right_assign_if() {}
148 };
149
166 // [Operator Wrapping]
167 template<
168 typename D1, typename D2 = D1, typename D3 = D2,
169 enum Backend implementation = config::default_backend
170 >
171 class add : public internal::Operator<
172 internal::add< D1, D2, D3, implementation >
173 >
174 {
175
176 public:
177
178 template< typename A, typename B, typename C, enum Backend D >
180
181 add() {}
182 };
183 // [Operator Wrapping]
184
201 template<
202 typename D1, typename D2 = D1, typename D3 = D2,
203 enum Backend implementation = config::default_backend
204 >
205 class mul : public internal::Operator<
206 internal::mul< D1, D2, D3, implementation >
207 >
208 {
209 public:
210
211 template< typename A, typename B, typename C, enum Backend D >
213
214 mul() {}
215 };
216
234 template<
235 typename D1, typename D2 = D1, typename D3 = D2,
236 enum Backend implementation = config::default_backend
237 >
238 class max : public internal::Operator<
239 internal::max< D1, D2, D3, implementation >
240 >
241 {
242 public:
243
244 template< typename A, typename B, typename C, enum Backend D >
246
247 max() {}
248 };
249
267 template<
268 typename D1, typename D2 = D1, typename D3 = D2,
269 enum Backend implementation = config::default_backend
270 >
271 class min : public internal::Operator<
272 internal::min< D1, D2, D3, implementation >
273 >
274 {
275 public:
276
277 template< typename A, typename B, typename C, enum Backend D >
279
280 min() {}
281 };
282
294 template<
295 typename D1, typename D2 = D1, typename D3 = D2,
296 enum Backend implementation = config::default_backend
297 >
298 class subtract : public internal::Operator<
299 internal::substract< D1, D2, D3, implementation >
300 >
301 {
302 public:
303
304 template< typename A, typename B, typename C, enum Backend D >
306
307 subtract() {}
308 };
309
321 template<
322 typename D1, typename D2 = D1, typename D3 = D2,
323 enum Backend implementation = config::default_backend
324 >
325 class divide : public internal::Operator<
326 internal::divide< D1, D2, D3, implementation >
327 >
328 {
329 public:
330
331 template< typename A, typename B, typename C, enum Backend D >
333
334 divide() {}
335 };
336
346 template<
347 typename D1, typename D2 = D1, typename D3 = D2,
348 enum Backend implementation = config::default_backend
349 >
350 class divide_reverse : public internal::Operator<
351 internal::divide_reverse< D1, D2, D3, implementation >
352 >
353 {
354 public:
355
356 template< typename A, typename B, typename C, enum Backend D >
358
359 divide_reverse() {}
360 };
361
372 template<
373 typename D1, typename D2 = D1, typename D3 = D2,
374 enum Backend implementation = config::default_backend
375 >
376 class equal : public internal::Operator<
377 internal::equal< D1, D2, D3, implementation >
378 >
379 {
380 public:
381
382 template< typename A, typename B, typename C, enum Backend D >
384
385 equal() {}
386 };
387
398 template<
399 typename D1, typename D2 = D1, typename D3 = D2,
400 enum Backend implementation = config::default_backend
401 >
402 class not_equal : public internal::Operator<
403 internal::not_equal< D1, D2, D3, implementation >
404 >
405 {
406 public:
407
408 template< typename A, typename B, typename C, enum Backend D >
410
411 not_equal() {}
412 };
413
427 template<
428 typename D1, typename D2 = D1, typename D3 = D2,
429 enum Backend implementation = config::default_backend
430 >
431 class any_or : public internal::Operator<
432 internal::any_or< D1, D2, D3, implementation >
433 >
434 {
435 public:
436
437 template< typename A, typename B, typename C, enum Backend D >
439
440 any_or() {}
441 };
442
455 template<
456 typename D1, typename D2 = D1, typename D3 = D2,
457 enum Backend implementation = config::default_backend
458 >
459 class logical_or : public internal::Operator<
460 internal::logical_or< D1, D2, D3, implementation >
461 >
462 {
463
464 public:
465
466 template< typename A, typename B, typename C, enum Backend D >
468
469 logical_or() {}
470 };
471
484 template<
485 typename D1, typename D2 = D1, typename D3 = D2,
486 enum Backend implementation = config::default_backend
487 >
488 class logical_and : public internal::Operator<
489 internal::logical_and< D1, D2, D3, implementation >
490 >
491 {
492 public:
493
494 template< typename A, typename B, typename C, enum Backend D >
496
497 logical_and() {}
498 };
499
508 template<
509 typename D1, typename D2 = D1, typename D3 = D2,
510 enum Backend implementation = config::default_backend
511 >
512 class relu : public internal::Operator<
513 internal::relu< D1, D2, D3, implementation >
514 >
515 {
516 public:
517
518 template< typename A, typename B, typename C, enum Backend D >
520
521 relu() {}
522 };
523
535 template<
536 typename D1, typename D2 = D1, typename D3 = D2,
537 enum Backend implementation = config::default_backend
538 >
539 class abs_diff : public internal::Operator<
540 internal::abs_diff< D1, D2, D3, implementation >
541 >
542 {
543 public:
544
545 template< typename A, typename B, typename C, enum Backend D >
547
548 abs_diff() {}
549 };
550
569 template< typename IType, typename VType >
570 class argmin : public internal::Operator< internal::argmin< IType, VType > > {
571 public:
572 argmin() {}
573 };
574
593 template< typename IType, typename VType >
594 class argmax : public internal::Operator< internal::argmax< IType, VType > > {
595 public:
596 argmax() {}
597 };
598
610 template<
611 typename D1, typename D2, typename D3,
612 enum Backend implementation = config::default_backend
613 >
614 class square_diff : public internal::Operator<
615 internal::square_diff< D1, D2, D3, implementation >
616 >
617 {
618 public:
619
620 template< typename A, typename B, typename C, enum Backend D >
622
623 square_diff() {}
624 };
625
635 template<
636 typename IN1, typename IN2,
637 enum Backend implementation = config::default_backend
638 >
639 class zip : public internal::Operator<
640 internal::zip< IN1, IN2, implementation >
641 >
642 {
643 public:
644
645 template< typename A, typename B, enum Backend D >
647
648 zip() {}
649 };
650
663 template<
664 typename D1, typename D2 = D1, typename D3 = D2,
665 enum Backend implementation = config::default_backend
666 >
667 class equal_first : public internal::Operator<
668 internal::equal_first< D1, D2, D3, implementation >
669 >
670 {
671 public:
672
673 template< typename A, typename B, typename C, enum Backend D >
675
676 equal_first() {}
677 };
678
679 } // namespace operators
680
681 template< typename D1, typename D2, typename D3, enum Backend implementation >
682 struct is_operator< operators::left_assign_if< D1, D2, D3, implementation > > {
683 static const constexpr bool value = true;
684 };
685
686 template< typename D1, typename D2, typename D3, enum Backend implementation >
687 struct is_operator< operators::right_assign_if< D1, D2, D3, implementation > > {
688 static const constexpr bool value = true;
689 };
690
691 template< typename D1, typename D2, typename D3, enum Backend implementation >
692 struct is_operator< operators::left_assign< D1, D2, D3, implementation > > {
693 static const constexpr bool value = true;
694 };
695
696 template< typename D1, typename D2, typename D3, enum Backend implementation >
697 struct is_operator< operators::right_assign< D1, D2, D3, implementation > > {
698 static const constexpr bool value = true;
699 };
700
701 // [Operator Type Traits]
702 template< typename D1, typename D2, typename D3, enum Backend implementation >
703 struct is_operator< operators::add< D1, D2, D3, implementation > > {
704 static const constexpr bool value = true;
705 };
706 // [Operator Type Traits]
707
708 template< typename D1, typename D2, typename D3, enum Backend implementation >
709 struct is_operator< operators::mul< D1, D2, D3, implementation > > {
710 static const constexpr bool value = true;
711 };
712
713 template< typename D1, typename D2, typename D3, enum Backend implementation >
714 struct is_operator< operators::max< D1, D2, D3, implementation > > {
715 static const constexpr bool value = true;
716 };
717
718 template< typename D1, typename D2, typename D3, enum Backend implementation >
719 struct is_operator< operators::min< D1, D2, D3, implementation > > {
720 static const constexpr bool value = true;
721 };
722
723 template< typename D1, typename D2, typename D3, enum Backend implementation >
724 struct is_operator< operators::subtract< D1, D2, D3, implementation > > {
725 static const constexpr bool value = true;
726 };
727
728 template< typename D1, typename D2, typename D3, enum Backend implementation >
729 struct is_operator< operators::divide< D1, D2, D3, implementation > > {
730 static const constexpr bool value = true;
731 };
732
733 template< typename D1, typename D2, typename D3, enum Backend implementation >
734 struct is_operator< operators::divide_reverse< D1, D2, D3, implementation > > {
735 static const constexpr bool value = true;
736 };
737
738 template< typename D1, typename D2, typename D3, enum Backend implementation >
739 struct is_operator< operators::equal< D1, D2, D3, implementation > > {
740 static const constexpr bool value = true;
741 };
742
743 template< typename D1, typename D2, typename D3, enum Backend implementation >
744 struct is_operator< operators::not_equal< D1, D2, D3, implementation > > {
745 static const constexpr bool value = true;
746 };
747
748 template< typename D1, typename D2, typename D3, enum Backend implementation >
749 struct is_operator< operators::any_or< D1, D2, D3, implementation > > {
750 static const constexpr bool value = true;
751 };
752
753 template< typename D1, typename D2, typename D3, enum Backend implementation >
754 struct is_operator< operators::logical_or< D1, D2, D3, implementation > > {
755 static const constexpr bool value = true;
756 };
757
758 template< typename D1, typename D2, typename D3, enum Backend implementation >
759 struct is_operator< operators::logical_and< D1, D2, D3, implementation > > {
760 static const constexpr bool value = true;
761 };
762
763 template< typename D1, typename D2, typename D3, enum Backend implementation >
764 struct is_operator< operators::abs_diff< D1, D2, D3, implementation > > {
765 static const constexpr bool value = true;
766 };
767
768 template< typename D1, typename D2, typename D3, enum Backend implementation >
769 struct is_operator< operators::relu< D1, D2, D3, implementation > > {
770 static const constexpr bool value = true;
771 };
772
773 template< typename IType, typename VType >
774 struct is_operator< operators::argmin< IType, VType > > {
775 static const constexpr bool value = true;
776 };
777
778 template< typename IType, typename VType >
779 struct is_operator< operators::argmax< IType, VType > > {
780 static const constexpr bool value = true;
781 };
782
783 template< typename D1, typename D2, typename D3, enum Backend implementation >
784 struct is_operator< operators::square_diff< D1, D2, D3, implementation > > {
785 static const constexpr bool value = true;
786 };
787
788 template< typename IN1, typename IN2, enum Backend implementation >
789 struct is_operator< operators::zip< IN1, IN2, implementation > > {
790 static const constexpr bool value = true;
791 };
792
793 template< typename D1, typename D2, typename D3, enum Backend implementation >
794 struct is_operator< operators::equal_first< D1, D2, D3, implementation > > {
795 static const constexpr bool value = true;
796 };
797
798 template< typename D1, typename D2, typename D3 >
799 struct is_idempotent< operators::min< D1, D2, D3 >, void > {
800 static const constexpr bool value = true;
801 };
802
803 template< typename D1, typename D2, typename D3 >
804 struct is_idempotent< operators::max< D1, D2, D3 >, void > {
805 static const constexpr bool value = true;
806 };
807
808 template< typename D1, typename D2, typename D3 >
809 struct is_idempotent< operators::any_or< D1, D2, D3 >, void > {
810 static const constexpr bool value = true;
811 };
812
813 template< typename D1, typename D2, typename D3 >
814 struct is_idempotent< operators::logical_or< D1, D2, D3 >, void > {
815 static const constexpr bool value = true;
816 };
817
818 template< typename D1, typename D2, typename D3 >
819 struct is_idempotent< operators::logical_and< D1, D2, D3 >, void > {
820 static const constexpr bool value = true;
821 };
822
823 template< typename D1, typename D2, typename D3 >
824 struct is_idempotent< operators::relu< D1, D2, D3 >, void > {
825 static const constexpr bool value = true;
826 };
827
828 template< typename D1, typename D2, typename D3 >
829 struct is_idempotent< operators::left_assign_if< D1, D2, D3 >, void > {
830 static const constexpr bool value = true;
831 };
832
833 template< typename D1, typename D2, typename D3 >
834 struct is_idempotent< operators::right_assign_if< D1, D2, D3 >, void > {
835 static const constexpr bool value = true;
836 };
837
838 template< typename IType, typename VType >
839 struct is_idempotent< operators::argmin< IType, VType >, void > {
840 static const constexpr bool value = true;
841 };
842
843 template< typename IType, typename VType >
844 struct is_idempotent< operators::argmax< IType, VType >, void > {
845 static const constexpr bool value = true;
846 };
847
848 template< typename OP >
849 struct is_associative<
850 OP,
851 typename std::enable_if< is_operator< OP >::value, void >::type
852 > {
853 static constexpr const bool value = OP::is_associative();
854 };
855
856 template< typename OP >
857 struct is_commutative<
858 OP,
859 typename std::enable_if< is_operator< OP >::value, void >::type
860 > {
861 static constexpr const bool value = OP::is_commutative();
862 };
863
864 // internal type traits follow
865
866 namespace internal {
867
868 template< typename D1, typename D2, typename D3, enum Backend implementation >
869 struct maybe_noop< operators::left_assign_if< D1, D2, D3, implementation > > {
870 static const constexpr bool value = true;
871 };
872
873 template< typename D1, typename D2, typename D3, enum Backend implementation >
874 struct maybe_noop< operators::right_assign_if< D1, D2, D3, implementation > > {
875 static const constexpr bool value = true;
876 };
877
878 } // end namespace grb::internal
879
880} // end namespace grb
881
882#ifdef __DOXYGEN__
888 #define _DEBUG_NO_IOSTREAM_PAIR_CONVERTER
889#endif
890
891#ifdef _DEBUG
892 #ifndef _DEBUG_NO_IOSTREAM_PAIR_CONVERTER
893namespace std {
894 template< typename U, typename V >
895 std::ostream & operator<<( std::ostream &out, const std::pair< U, V > &pair ) {
896 out << "( " << pair.first << ", " << pair.second << " )";
897 return out;
898 }
899} // end namespace std
900 #endif
901#endif
902
903#endif // end ``_H_GRB_OPERATORS''
904
This operator returns the absolute difference between two numbers.
Definition: ops.hpp:542
This operator takes the sum of the two input parameters and writes it to the output variable.
Definition: ops.hpp:174
This operator is a generalisation of the logical or.
Definition: ops.hpp:434
The argmax operator on key-value pairs.
Definition: ops.hpp:594
The argmin operator on key-value pairs.
Definition: ops.hpp:570
Reversed division of two numbers.
Definition: ops.hpp:353
Numerical division of two numbers.
Definition: ops.hpp:328
Compares std::pair inputs taking the first entry in every pair as the comparison key,...
Definition: ops.hpp:670
Operator which returns true if its inputs compare equal, and false otherwise.
Definition: ops.hpp:379
This operator assigns the left-hand input if the right-hand input evaluates true.
Definition: ops.hpp:88
This operator discards all right-hand side input and simply copies the left-hand side input to the ou...
Definition: ops.hpp:62
The logical and.
Definition: ops.hpp:491
The logical or.
Definition: ops.hpp:462
This operator takes the maximum of the two input parameters and writes the result to the output varia...
Definition: ops.hpp:241
This operator takes the minimum of the two input parameters and writes the result to the output varia...
Definition: ops.hpp:274
This operator multiplies the two input parameters and writes the result to the output variable.
Definition: ops.hpp:208
Operator that returns false whenever its inputs compare equal, and true otherwise.
Definition: ops.hpp:405
This operation is equivalent to grb::operators::min.
Definition: ops.hpp:515
This operator assigns the right-hand input if the left-hand input evaluates true.
Definition: ops.hpp:141
This operator discards all left-hand side input and simply copies the right-hand side input to the ou...
Definition: ops.hpp:116
This operation returns the squared difference between two numbers.
Definition: ops.hpp:617
Numerical substraction of two numbers.
Definition: ops.hpp:301
The zip operator that operators on keys as a left-hand input and values as a right hand input,...
Definition: ops.hpp:642
RC zip(Matrix< OutputType, backend, RIT, CIT, NIT > &A, const Vector< InputType1, backend, Coords > &x, const Vector< InputType2, backend, Coords > &y, const Vector< InputType3, backend, Coords > &z, const Phase &phase=EXECUTE)
The grb::zip merges three vectors into a matrix.
Definition: blas3.hpp:181
Backend
A collection of all backends.
Definition: backends.hpp:46
The ALP/GraphBLAS namespace.
Definition: graphblas.hpp:450
static const constexpr bool value
Whether T is associative.
Definition: type_traits.hpp:208
static const constexpr bool value
Whether T is commutative.
Definition: type_traits.hpp:246
static const constexpr bool value
Wheter T is idempotent.
Definition: type_traits.hpp:167
Used to inspect whether a given type is an ALP operator.
Definition: type_traits.hpp:104
static const constexpr bool value
Whether T is an ALP operator.
Definition: type_traits.hpp:111
Specifies the ALP algebraic type traits.