ViennaCL - The Vienna Computing Library: viennacl/linalg/detail/op_applier.hpp Source File

ViennaCL - The Vienna Computing Library 1.7.1 Free open-source GPU-accelerated linear algebra and solver library. |

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
op_applier.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_LINALG_DETAIL_OP_APPLIER_HPP
2 #define VIENNACL_LINALG_DETAIL_OP_APPLIER_HPP
3
4 /* =========================================================================
5 Copyright (c) 2010-2016, Institute for Microelectronics,
6 Institute for Analysis and Scientific Computing,
7 TU Wien.
8 Portions of this software are copyright by UChicago Argonne, LLC.
9
10 -----------------
11 ViennaCL - The Vienna Computing Library
12 -----------------
13
14 Project Head: Karl Rupp rupp@iue.tuwien.ac.at
15
16 (A list of authors and contributors can be found in the manual)
17
18 License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20
26 #include "viennacl/forwards.h"
27 #include <cmath>
28
29 namespace viennacl
30 {
31 namespace linalg
32 {
33 namespace detail
34 {
35
42 template<typename OpT>
43 struct op_applier
44 {
45 typedef typename OpT::ERROR_UNKNOWN_OP_TAG_PROVIDED error_type;
46 };
47
49 template<>
50 struct op_applier<op_element_binary<op_prod> >
51 {
52 template<typename T>
53 static void apply(T & result, T const & x, T const & y) { result = x * y; }
54 };
55
56 template<>
57 struct op_applier<op_element_binary<op_div> >
58 {
59 template<typename T>
60 static void apply(T & result, T const & x, T const & y) { result = x / y; }
61 };
62
63 template<>
64 struct op_applier<op_element_binary<op_pow> >
65 {
66 template<typename T>
67 static void apply(T & result, T const & x, T const & y) { result = std::pow(x, y); }
68 };
69
70 #define VIENNACL_MAKE_UNARY_OP_APPLIER(funcname) \
71 template<> \
72 struct op_applier<op_element_unary<op_##funcname> > \
73 { \
74 template<typename T> \
75 static void apply(T & result, T const & x) { using namespace std; result = funcname(x); } \
76 }
77
78 VIENNACL_MAKE_UNARY_OP_APPLIER(abs);
79 VIENNACL_MAKE_UNARY_OP_APPLIER(acos);
80 VIENNACL_MAKE_UNARY_OP_APPLIER(asin);
81 VIENNACL_MAKE_UNARY_OP_APPLIER(atan);
82 VIENNACL_MAKE_UNARY_OP_APPLIER(ceil);
83 VIENNACL_MAKE_UNARY_OP_APPLIER(cos);
84 VIENNACL_MAKE_UNARY_OP_APPLIER(cosh);
85 VIENNACL_MAKE_UNARY_OP_APPLIER(exp);
86 VIENNACL_MAKE_UNARY_OP_APPLIER(fabs);
87 VIENNACL_MAKE_UNARY_OP_APPLIER(floor);
88 VIENNACL_MAKE_UNARY_OP_APPLIER(log);
89 VIENNACL_MAKE_UNARY_OP_APPLIER(log10);
90 VIENNACL_MAKE_UNARY_OP_APPLIER(sin);
91 VIENNACL_MAKE_UNARY_OP_APPLIER(sinh);
92 VIENNACL_MAKE_UNARY_OP_APPLIER(sqrt);
93 VIENNACL_MAKE_UNARY_OP_APPLIER(tan);
94 VIENNACL_MAKE_UNARY_OP_APPLIER(tanh);
95
96 #undef VIENNACL_MAKE_UNARY_OP_APPLIER
97
99 }
100 }
101 }
102
103 #endif // VIENNACL_LINALG_DETAIL_OP_EXECUTOR_HPP
viennacl::linalg::detail::op_applier::error_type
OpT::ERROR_UNKNOWN_OP_TAG_PROVIDED error_type
Definition: op_applier.hpp:45
viennacl::linalg::detail::op_applier
Worker class for decomposing expression templates.
Definition: op_applier.hpp:43
forwards.h
This file provides the forward declarations for the main types used within ViennaCL.
viennacl::op_div
A tag class representing division.
Definition: forwards.h:98
viennacl::op_prod
A tag class representing matrix-vector products and element-wise multiplications. ...
Definition: forwards.h:94
viennacl::op_element_binary
A tag class representing element-wise binary operations (like multiplication) on vectors or matrices...
Definition: forwards.h:130