Nektar++
Loading...
Searching...
No Matches
MathHelper.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: MathHelper.hpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description:
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#pragma once
36
38
39#include <array>
40#include <string>
41#include <vector>
42
43namespace Nektar::Math
44{
45
46class RandomGenerator;
47
48// Generic MathHelper class definition.
50{
51public:
53 {
54 }
55
56 MathHelper(const std::string &defaultExecSpace)
57 : m_defaultExecSpace(defaultExecSpace)
58 {
59 }
60
62 {
64 return *this;
65 }
66
67 // For all functions below, T can be either a MemoryRegion of a Field.
68 template <typename T>
69 LIB_MATH_EXPORT void zero(T &x, const std::string &execSpace = "");
70
71 template <typename TData, typename T>
72 LIB_MATH_EXPORT void fill(const TData &val, T &x,
73 const std::string &execSpace = "");
74
75 template <typename T>
77 const typename T::value_type a,
78 const typename T::value_type b, T &x,
79 const std::string &execSpace = "");
80
81 template <typename T>
83 const typename T::value_type mean,
84 const typename T::value_type sigma, T &x,
85 const std::string &execSpace = "");
86
87 template <typename T>
88 LIB_MATH_EXPORT void copy(T &x, T &y, const std::string &execSpace = "");
89
90 template <typename T>
91 LIB_MATH_EXPORT void abs(T &x, T &y, const std::string &execSpace = "");
92
93 template <typename T>
94 LIB_MATH_EXPORT void neg(T &x, T &y, const std::string &execSpace = "");
95
96 template <typename T>
97 LIB_MATH_EXPORT void sqrt(T &x, T &y, const std::string &execSpace = "");
98
99 template <typename T>
100 LIB_MATH_EXPORT void add(T &x, T &y, T &z,
101 const std::string &execSpace = "");
102
103 template <typename T>
104 LIB_MATH_EXPORT void sub(T &x, T &y, T &z,
105 const std::string &execSpace = "");
106
107 template <typename T>
108 LIB_MATH_EXPORT void mul(const typename T::value_type alpha, T &x, T &y,
109 const std::string &execSpace = "");
110
111 template <typename T>
112 LIB_MATH_EXPORT void mul(T &x, T &y, T &z,
113 const std::string &execSpace = "");
114
115 template <typename T>
116 LIB_MATH_EXPORT void div(const typename T::value_type alpha, T &x, T &y,
117 const std::string &execSpace = "");
118
119 template <typename T>
120 LIB_MATH_EXPORT void div(T &x, T &y, T &z,
121 const std::string &execSpace = "");
122
123 template <typename T>
124 LIB_MATH_EXPORT void daxpy(const typename T::value_type alpha, T &x, T &y,
125 T &z, const std::string &execSpace = "");
126
127 template <typename T>
128 LIB_MATH_EXPORT void daxpby(const typename T::value_type alpha, T &x,
129 const typename T::value_type beta, T &y, T &z,
130 const std::string &execSpace = "");
131
132 template <typename T>
133 LIB_MATH_EXPORT void daxpbypz(const typename T::value_type alpha, T &x,
134 const typename T::value_type beta, T &y, T &z,
135 T &w, const std::string &execSpace = "");
136
137 template <typename T>
138 LIB_MATH_EXPORT void daxpbypcz(const typename T::value_type alpha, T &x,
139 const typename T::value_type beta, T &y,
140 const typename T::value_type gamma, T &z,
141 T &w, const std::string &execSpace = "");
142
143 // y = sum_j alpha[j] x[j], added to y if append, in one pass; T is a
144 // Field.
145 template <typename T>
147 const std::vector<typename T::value_type> &alpha,
148 const std::vector<T *> &x, T &y, const bool append,
149 const std::string &execSpace = "");
150
151 template <typename T>
152 LIB_MATH_EXPORT typename T::value_type reduceSum(
153 T &x, const std::string &execSpace = "");
154
155 template <typename M, typename T>
156 LIB_MATH_EXPORT typename T::value_type reduceSum(
157 M &mask, T &x, const std::string &execSpace = "");
158
159 template <typename T>
160 LIB_MATH_EXPORT typename T::value_type reduceMax(
161 T &x, const std::string &execSpace = "");
162
163 template <typename M, typename T>
164 LIB_MATH_EXPORT typename T::value_type reduceMax(
165 M &mask, T &x, const std::string &execSpace = "");
166
167 template <typename T>
168 LIB_MATH_EXPORT typename T::value_type reduceMin(
169 T &x, const std::string &execSpace = "");
170
171 template <typename M, typename T>
172 LIB_MATH_EXPORT typename T::value_type reduceMin(
173 M &mask, T &x, const std::string &execSpace = "");
174
175 template <typename T>
176 LIB_MATH_EXPORT typename T::value_type ddot(
177 T &x, T &y, const std::string &execSpace = "");
178
179 template <typename M, typename T>
180 LIB_MATH_EXPORT typename T::value_type ddot(
181 M &mask, T &x, T &y, const std::string &execSpace = "");
182
183 // {(x, y), (x, z)} in one pass over x; T is a Field.
184 template <typename T>
185 LIB_MATH_EXPORT std::array<typename T::value_type, 2> ddot2(
186 T &x, T &y, T &z, const std::string &execSpace = "");
187
188 template <typename M, typename T>
189 LIB_MATH_EXPORT std::array<typename T::value_type, 2> ddot2(
190 M &mask, T &x, T &y, T &z, const std::string &execSpace = "");
191
192 template <typename T>
193 LIB_MATH_EXPORT typename T::value_type l1norm(
194 T &x, const std::string &execSpace = "");
195
196 template <typename M, typename T>
197 LIB_MATH_EXPORT typename T::value_type l1norm(
198 M &mask, T &x, const std::string &execSpace = "");
199
200 template <typename T>
201 LIB_MATH_EXPORT typename T::value_type l2norm(
202 T &, const std::string &execSpace = "");
203
204 template <typename M, typename T>
205 LIB_MATH_EXPORT typename T::value_type l2norm(
206 M &mask, T &, const std::string &execSpace = "");
207
208 template <typename T>
209 LIB_MATH_EXPORT typename T::value_type linfnorm(
210 T &x, const std::string &execSpace = "");
211
212 template <typename M, typename T>
213 LIB_MATH_EXPORT typename T::value_type linfnorm(
214 M &mask, T &x, const std::string &execSpace = "");
215
216private:
218};
219
220} // namespace Nektar::Math
#define LIB_MATH_EXPORT
LIB_MATH_EXPORT void abs(T &x, T &y, const std::string &execSpace="")
LIB_MATH_EXPORT void daxpbypcz(const typename T::value_type alpha, T &x, const typename T::value_type beta, T &y, const typename T::value_type gamma, T &z, T &w, const std::string &execSpace="")
LIB_MATH_EXPORT T::value_type l2norm(T &, const std::string &execSpace="")
LIB_MATH_EXPORT void add(T &x, T &y, T &z, const std::string &execSpace="")
LIB_MATH_EXPORT void zero(T &x, const std::string &execSpace="")
LIB_MATH_EXPORT void daxpby(const typename T::value_type alpha, T &x, const typename T::value_type beta, T &y, T &z, const std::string &execSpace="")
LIB_MATH_EXPORT T::value_type reduceMin(T &x, const std::string &execSpace="")
LIB_MATH_EXPORT void sqrt(T &x, T &y, const std::string &execSpace="")
LIB_MATH_EXPORT void daxpy(const typename T::value_type alpha, T &x, T &y, T &z, const std::string &execSpace="")
LIB_MATH_EXPORT T::value_type reduceMax(T &x, const std::string &execSpace="")
LIB_MATH_EXPORT T::value_type linfnorm(M &mask, T &x, const std::string &execSpace="")
LIB_MATH_EXPORT T::value_type l1norm(T &x, const std::string &execSpace="")
LIB_MATH_EXPORT T::value_type l2norm(M &mask, T &, const std::string &execSpace="")
LIB_MATH_EXPORT void daxpbypz(const typename T::value_type alpha, T &x, const typename T::value_type beta, T &y, T &z, T &w, const std::string &execSpace="")
LIB_MATH_EXPORT void fillNormal(RandomGenerator &gen, const typename T::value_type mean, const typename T::value_type sigma, T &x, const std::string &execSpace="")
LIB_MATH_EXPORT T::value_type linfnorm(T &x, const std::string &execSpace="")
LIB_MATH_EXPORT std::array< typename T::value_type, 2 > ddot2(T &x, T &y, T &z, const std::string &execSpace="")
Math::MathHelper & operator=(const Math::MathHelper &rhs)
LIB_MATH_EXPORT T::value_type ddot(M &mask, T &x, T &y, const std::string &execSpace="")
LIB_MATH_EXPORT void fillUniform(RandomGenerator &gen, const typename T::value_type a, const typename T::value_type b, T &x, const std::string &execSpace="")
LIB_MATH_EXPORT T::value_type ddot(T &x, T &y, const std::string &execSpace="")
LIB_MATH_EXPORT void mul(T &x, T &y, T &z, const std::string &execSpace="")
LIB_MATH_EXPORT void div(T &x, T &y, T &z, const std::string &execSpace="")
LIB_MATH_EXPORT void sub(T &x, T &y, T &z, const std::string &execSpace="")
LIB_MATH_EXPORT T::value_type reduceSum(T &x, const std::string &execSpace="")
LIB_MATH_EXPORT T::value_type reduceMax(M &mask, T &x, const std::string &execSpace="")
LIB_MATH_EXPORT std::array< typename T::value_type, 2 > ddot2(M &mask, T &x, T &y, T &z, const std::string &execSpace="")
LIB_MATH_EXPORT T::value_type reduceSum(M &mask, T &x, const std::string &execSpace="")
LIB_MATH_EXPORT T::value_type reduceMin(M &mask, T &x, const std::string &execSpace="")
LIB_MATH_EXPORT void fill(const TData &val, T &x, const std::string &execSpace="")
MathHelper(const std::string &defaultExecSpace)
LIB_MATH_EXPORT void neg(T &x, T &y, const std::string &execSpace="")
LIB_MATH_EXPORT void mul(const typename T::value_type alpha, T &x, T &y, const std::string &execSpace="")
LIB_MATH_EXPORT void copy(T &x, T &y, const std::string &execSpace="")
LIB_MATH_EXPORT void div(const typename T::value_type alpha, T &x, T &y, const std::string &execSpace="")
LIB_MATH_EXPORT T::value_type l1norm(M &mask, T &x, const std::string &execSpace="")
LIB_MATH_EXPORT void linearCombination(const std::vector< typename T::value_type > &alpha, const std::vector< T * > &x, T &y, const bool append, const std::string &execSpace="")
Pseudo-random number generator behind Math::fillUniform and Math::fillNormal.
@ beta
Gauss Radau pinned at x=-1,.
Definition PointsType.h:59