TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
mapped_functions.hxx
Go to the documentation of this file.
1/**
2 * @file
3 * @brief Provides lazy, coefficient-wise array operations of standard mathematical functions.
4 */
5
6#pragma once
7
8#include "./concepts.hpp"
9#include "./map.hpp"
10#include "./mapped_functions.hpp"
11#include "./traits.hpp"
12
13#include <cmath>
14#include <complex>
15#include <utility>
16
17/*
18 File is generated by vim.
19 To regenerate the file,
20 1- load the vim function by (or add this to your .vim ?)
21 :source vimexpand.vim
22 2- call it
23 :call VimExpandSimple()
24
25
26 It is better than C macro, it gives a cleaner code
27 (for error messages, no preproc, doc generation : otherwise no doc string ...)
28
29 ---- normal mapping -------
30
31 VIMEXPAND abs imag floor
32 /// \brief Lazy, coefficient-wise @ function for nda::Array types.
33 ///
34 /// \tparam A nda::Array type.
35 /// \param a nda::Array object.
36 /// \return A lazy nda::expr_call object.
37 template <Array A>
38 auto @(A &&a) {
39 return nda::map(
40 [](auto const &x) {
41 using std::@;
42 return @(x);
43 })(std::forward<A>(a));
44 }
45
46 --------- same, no using std::-------
47
48 VIMEXPAND real abs2 isnan
49 /// \brief Lazy, coefficient-wise @ function for nda::Array types.
50 ///
51 /// \tparam A nda::Array type.
52 /// \param a nda::Array object.
53 /// \return A lazy nda::expr_call object.
54 template <Array A>
55 auto @(A &&a) {
56 return nda::map(
57 [](auto const &x) {return @(x); })(std::forward<A>(a));
58 }
59
60 --------- mapping with matrix excluded -------
61
62 VIMEXPAND exp cos sin tan cosh sinh tanh acos asin atan log sqrt
63 /// \brief Lazy, coefficient-wise @ function for non-matrix nda::Array types.
64 ///
65 /// \tparam A nda::Array type.
66 /// \param a nda::Array object.
67 /// \return A lazy nda::expr_call object.
68 template <Array A>
69 auto @(A &&a) requires(get_algebra<A> != 'M') {
70 return nda::map(
71 [](auto const &x) {
72 using std::@;
73 return @(x);
74 })(std::forward<A>(a));
75 }
76
77*/
78
79namespace nda {
80
81 /**
82 * @addtogroup av_math
83 * @{
84 */
85
86 // --- VIMEXPAND_START --DO NOT EDIT BELOW --
87
88
89 /// \brief Lazy, coefficient-wise abs function for nda::Array types.
90 ///
91 /// \tparam A nda::Array type.
92 /// \param a nda::Array object.
93 /// \return A lazy nda::expr_call object.
94 template <Array A>
95 auto abs(A &&a) {
96 return nda::map(
97 [](auto const &x) {
98 using std::abs;
99 return abs(x);
100 })(std::forward<A>(a));
101 }
102
103 /// \brief Lazy, coefficient-wise imag function for nda::Array types.
104 ///
105 /// \tparam A nda::Array type.
106 /// \param a nda::Array object.
107 /// \return A lazy nda::expr_call object.
108 template <Array A>
109 auto imag(A &&a) {
110 return nda::map(
111 [](auto const &x) {
112 using std::imag;
113 return imag(x);
114 })(std::forward<A>(a));
115 }
116
117 /// \brief Lazy, coefficient-wise floor function for nda::Array types.
118 ///
119 /// \tparam A nda::Array type.
120 /// \param a nda::Array object.
121 /// \return A lazy nda::expr_call object.
122 template <Array A>
123 auto floor(A &&a) {
124 return nda::map(
125 [](auto const &x) {
126 using std::floor;
127 return floor(x);
128 })(std::forward<A>(a));
129 }
130
131 /// \brief Lazy, coefficient-wise real function for nda::Array types.
132 ///
133 /// \tparam A nda::Array type.
134 /// \param a nda::Array object.
135 /// \return A lazy nda::expr_call object.
136 template <Array A>
137 auto real(A &&a) {
138 return nda::map(
139 [](auto const &x) {return real(x); })(std::forward<A>(a));
140 }
141
142 /// \brief Lazy, coefficient-wise abs2 function for nda::Array types.
143 ///
144 /// \tparam A nda::Array type.
145 /// \param a nda::Array object.
146 /// \return A lazy nda::expr_call object.
147 template <Array A>
148 auto abs2(A &&a) {
149 return nda::map(
150 [](auto const &x) {return abs2(x); })(std::forward<A>(a));
151 }
152
153 /// \brief Lazy, coefficient-wise isnan function for nda::Array types.
154 ///
155 /// \tparam A nda::Array type.
156 /// \param a nda::Array object.
157 /// \return A lazy nda::expr_call object.
158 template <Array A>
159 auto isnan(A &&a) {
160 return nda::map(
161 [](auto const &x) {return isnan(x); })(std::forward<A>(a));
162 }
163
164 /// \brief Lazy, coefficient-wise exp function for non-matrix nda::Array types.
165 ///
166 /// \tparam A nda::Array type.
167 /// \param a nda::Array object.
168 /// \return A lazy nda::expr_call object.
169 template <Array A>
170 auto exp(A &&a) requires(get_algebra<A> != 'M') {
171 return nda::map(
172 [](auto const &x) {
173 using std::exp;
174 return exp(x);
175 })(std::forward<A>(a));
176 }
177
178 /// \brief Lazy, coefficient-wise cos function for non-matrix nda::Array types.
179 ///
180 /// \tparam A nda::Array type.
181 /// \param a nda::Array object.
182 /// \return A lazy nda::expr_call object.
183 template <Array A>
184 auto cos(A &&a) requires(get_algebra<A> != 'M') {
185 return nda::map(
186 [](auto const &x) {
187 using std::cos;
188 return cos(x);
189 })(std::forward<A>(a));
190 }
191
192 /// \brief Lazy, coefficient-wise sin function for non-matrix nda::Array types.
193 ///
194 /// \tparam A nda::Array type.
195 /// \param a nda::Array object.
196 /// \return A lazy nda::expr_call object.
197 template <Array A>
198 auto sin(A &&a) requires(get_algebra<A> != 'M') {
199 return nda::map(
200 [](auto const &x) {
201 using std::sin;
202 return sin(x);
203 })(std::forward<A>(a));
204 }
205
206 /// \brief Lazy, coefficient-wise tan function for non-matrix nda::Array types.
207 ///
208 /// \tparam A nda::Array type.
209 /// \param a nda::Array object.
210 /// \return A lazy nda::expr_call object.
211 template <Array A>
212 auto tan(A &&a) requires(get_algebra<A> != 'M') {
213 return nda::map(
214 [](auto const &x) {
215 using std::tan;
216 return tan(x);
217 })(std::forward<A>(a));
218 }
219
220 /// \brief Lazy, coefficient-wise cosh function for non-matrix nda::Array types.
221 ///
222 /// \tparam A nda::Array type.
223 /// \param a nda::Array object.
224 /// \return A lazy nda::expr_call object.
225 template <Array A>
226 auto cosh(A &&a) requires(get_algebra<A> != 'M') {
227 return nda::map(
228 [](auto const &x) {
229 using std::cosh;
230 return cosh(x);
231 })(std::forward<A>(a));
232 }
233
234 /// \brief Lazy, coefficient-wise sinh function for non-matrix nda::Array types.
235 ///
236 /// \tparam A nda::Array type.
237 /// \param a nda::Array object.
238 /// \return A lazy nda::expr_call object.
239 template <Array A>
240 auto sinh(A &&a) requires(get_algebra<A> != 'M') {
241 return nda::map(
242 [](auto const &x) {
243 using std::sinh;
244 return sinh(x);
245 })(std::forward<A>(a));
246 }
247
248 /// \brief Lazy, coefficient-wise tanh function for non-matrix nda::Array types.
249 ///
250 /// \tparam A nda::Array type.
251 /// \param a nda::Array object.
252 /// \return A lazy nda::expr_call object.
253 template <Array A>
254 auto tanh(A &&a) requires(get_algebra<A> != 'M') {
255 return nda::map(
256 [](auto const &x) {
257 using std::tanh;
258 return tanh(x);
259 })(std::forward<A>(a));
260 }
261
262 /// \brief Lazy, coefficient-wise acos function for non-matrix nda::Array types.
263 ///
264 /// \tparam A nda::Array type.
265 /// \param a nda::Array object.
266 /// \return A lazy nda::expr_call object.
267 template <Array A>
268 auto acos(A &&a) requires(get_algebra<A> != 'M') {
269 return nda::map(
270 [](auto const &x) {
271 using std::acos;
272 return acos(x);
273 })(std::forward<A>(a));
274 }
275
276 /// \brief Lazy, coefficient-wise asin function for non-matrix nda::Array types.
277 ///
278 /// \tparam A nda::Array type.
279 /// \param a nda::Array object.
280 /// \return A lazy nda::expr_call object.
281 template <Array A>
282 auto asin(A &&a) requires(get_algebra<A> != 'M') {
283 return nda::map(
284 [](auto const &x) {
285 using std::asin;
286 return asin(x);
287 })(std::forward<A>(a));
288 }
289
290 /// \brief Lazy, coefficient-wise atan function for non-matrix nda::Array types.
291 ///
292 /// \tparam A nda::Array type.
293 /// \param a nda::Array object.
294 /// \return A lazy nda::expr_call object.
295 template <Array A>
296 auto atan(A &&a) requires(get_algebra<A> != 'M') {
297 return nda::map(
298 [](auto const &x) {
299 using std::atan;
300 return atan(x);
301 })(std::forward<A>(a));
302 }
303
304 /// \brief Lazy, coefficient-wise log function for non-matrix nda::Array types.
305 ///
306 /// \tparam A nda::Array type.
307 /// \param a nda::Array object.
308 /// \return A lazy nda::expr_call object.
309 template <Array A>
310 auto log(A &&a) requires(get_algebra<A> != 'M') {
311 return nda::map(
312 [](auto const &x) {
313 using std::log;
314 return log(x);
315 })(std::forward<A>(a));
316 }
317
318 /// \brief Lazy, coefficient-wise sqrt function for non-matrix nda::Array types.
319 ///
320 /// \tparam A nda::Array type.
321 /// \param a nda::Array object.
322 /// \return A lazy nda::expr_call object.
323 template <Array A>
324 auto sqrt(A &&a) requires(get_algebra<A> != 'M') {
325 return nda::map(
326 [](auto const &x) {
327 using std::sqrt;
328 return sqrt(x);
329 })(std::forward<A>(a));
330 }
331
332 /** @} */
333}
auto cos(A &&a)
Lazy, coefficient-wise cos function for non-matrix nda::Array types.
auto sinh(A &&a)
Lazy, coefficient-wise sinh function for non-matrix nda::Array types.
auto tanh(A &&a)
Lazy, coefficient-wise tanh function for non-matrix nda::Array types.
auto sin(A &&a)
Lazy, coefficient-wise sin function for non-matrix nda::Array types.
auto log(A &&a)
Lazy, coefficient-wise log function for non-matrix nda::Array types.
auto floor(A &&a)
Lazy, coefficient-wise floor function for nda::Array types.
auto abs(A &&a)
Lazy, coefficient-wise abs function for nda::Array types.
auto tan(A &&a)
Lazy, coefficient-wise tan function for non-matrix nda::Array types.
auto atan(A &&a)
Lazy, coefficient-wise atan function for non-matrix nda::Array types.
auto real(A &&a)
Lazy, coefficient-wise real function for nda::Array types.
auto sqrt(A &&a)
Lazy, coefficient-wise sqrt function for non-matrix nda::Array types.
auto imag(A &&a)
Lazy, coefficient-wise imag function for nda::Array types.
auto isnan(A &&a)
Lazy, coefficient-wise isnan function for nda::Array types.
auto cosh(A &&a)
Lazy, coefficient-wise cosh function for non-matrix nda::Array types.
auto abs2(A &&a)
Lazy, coefficient-wise abs2 function for nda::Array types.
auto asin(A &&a)
Lazy, coefficient-wise asin function for non-matrix nda::Array types.
auto acos(A &&a)
Lazy, coefficient-wise acos function for non-matrix nda::Array types.
auto exp(A &&a)
Lazy, coefficient-wise exp function for non-matrix nda::Array types.