AFLOW
 
Loading...
Searching...
No Matches
aurostd_xrandom.cpp
Go to the documentation of this file.
1// ***************************************************************************
2// * *
3// * Aflow STEFANO CURTAROLO - Duke University 2003-2024 *
4// * *
5// ***************************************************************************
6// Written by Stefano Curtarolo 1994-2012
7
8#ifndef _AUROSTD_XRANDOM_CPP_
9#define _AUROSTD_XRANDOM_CPP_
10
11#include "aurostd_xrandom.h"
12
13#include <cmath>
14#include <cstdlib>
15#include <ctime>
16
17#include <sys/time.h>
18#include <unistd.h>
19
20#include "aurostd.h"
22#include "aurostd_xscalar.h"
23
24#ifndef XXEND
25#define XXEND 1
26#endif
27
28// ----------------------------------------------------------------------------
29// --------------------------------------------------------------- implementation
30#define RAN3
31static long int _idum[1]; // to start ..
32
33namespace aurostd {
34 // namespace aurostd
35 long int _random_initialize(long int _num) {
36 (*_idum) = -std::labs(_num) - 1969;
37 // (*_idum)=-abs(_num)-1969;
38 return (*_idum);
39 }
40
41 long int _random_initialize() {
42 // (*_idum)=1969;
43 // (*_idum)=1969-aurostd::execute2int("date | sum")+aurostd::execute2int("ls /tmp | sum");
44
45 timeval tim;
46 gettimeofday(&tim, nullptr);
47 // double t1=tim.tv_sec+(tim.tv_usec/1000000.0);
48 // cerr << tim.tv_usec << endl;
49 // getpid
50 const int PID = getpid();
51 const int TID = aurostd::getTID(); // CO20200502 - threadID
52 const long int seed = tim.tv_usec + tim.tv_sec + PID + TID; // CO20200502 - threadID
53 srand(seed); // for std:: library things
54 (*_idum) = seed; // for aurostd:: library things
55 // cerr << PID << endl;
56 // cerr << TID << endl; //CO20200502 - threadID
57 return (*_idum);
58 }
59
60 // --------------------------------------------------------- uniform deviations
61 // --------------------------------------------------------------------- ran0()
62
63#define _AUROSTD_XRANDOM_RAN0_IA 16807
64#define _AUROSTD_XRANDOM_RAN0_IM 2147483647
65#define _AUROSTD_XRANDOM_RAN0_AM (1.0 / _AUROSTD_XRANDOM_RAN0_IM)
66#define _AUROSTD_XRANDOM_RAN0_IQ 127773
67#define _AUROSTD_XRANDOM_RAN0_IR 2836
68#define _AUROSTD_XRANDOM_RAN0_MASK 123459876
69
70 double ran0() { // 108.3 ns
71 long int k;
72 float ans;
73
75 k = (*_idum) / _AUROSTD_XRANDOM_RAN0_IQ;
77 if (*_idum < 0) {
79 }
80 ans = _AUROSTD_XRANDOM_RAN0_AM * (*_idum);
82 return ans;
83 }
84
85#undef _AUROSTD_XRANDOM_RAN0_IA
86#undef _AUROSTD_XRANDOM_RAN0_IM
87#undef _AUROSTD_XRANDOM_RAN0_AM
88#undef _AUROSTD_XRANDOM_RAN0_IQ
89#undef _AUROSTD_XRANDOM_RAN0_IR
90#undef _AUROSTD_XRANDOM_RAN0_MASK
91
92 // --------------------------------------------------------------------- ran1()
93#define _AUROSTD_XRANDOM_RAN1_IA 16807
94#define _AUROSTD_XRANDOM_RAN1_IM 2147483647
95#define _AUROSTD_XRANDOM_RAN1_AM (1.0 / _AUROSTD_XRANDOM_RAN1_IM)
96#define _AUROSTD_XRANDOM_RAN1_IQ 127773
97#define _AUROSTD_XRANDOM_RAN1_IR 2836
98#define _AUROSTD_XRANDOM_RAN1_NTAB 32
99#define _AUROSTD_XRANDOM_RAN1_EPS 1.2e-7
100#define _AUROSTD_XRANDOM_RAN1_RNMX (1.0 - _AUROSTD_XRANDOM_RAN1_EPS)
101
102 double ran1() { // 118.80 ns
103 // "minimal" random number generator of Park and Miller with Bays-Durham
104 // shuffle and added safeguards. Return a uniform random deviate between
105 // 0.0 and 1.0 (exclusive of the endpoint values:
106 // _AUROSTD_XRANDOM_RAN1_EPS and _AUROSTD_XRANDOM_RAN1_RNMX)
107
108 int j;
109 long int k;
110 static long int iy = 0;
111 static long int iv[_AUROSTD_XRANDOM_RAN1_NTAB];
112 double temp;
113 if (*_idum <= 0 || !iy) {
114 if (-(*_idum) < 1) {
115 *_idum = 1;
116 } else {
117 *_idum = -(*_idum);
118 }
119 for (j = _AUROSTD_XRANDOM_RAN1_NTAB + 7; j >= 0; j--) {
120 k = (*_idum) / _AUROSTD_XRANDOM_RAN1_IQ;
122 if (*_idum < 0) {
124 }
126 iv[j] = *_idum;
127 }
128 }
129 iy = iv[0];
130 }
131 k = (*_idum) / _AUROSTD_XRANDOM_RAN1_IQ;
133 if (*_idum < 0) {
135 }
137 iy = iv[j];
138 iv[j] = *_idum;
141 } else {
142 return temp;
143 }
144 }
145
146#undef _AUROSTD_XRANDOM_RAN1_IA
147#undef _AUROSTD_XRANDOM_RAN1_IM
148#undef _AUROSTD_XRANDOM_RAN1_AM
149#undef _AUROSTD_XRANDOM_RAN1_IQ
150#undef _AUROSTD_XRANDOM_RAN1_IR
151#undef _AUROSTD_XRANDOM_RAN1_NTAB
152#undef _AUROSTD_XRANDOM_RAN1_EPS
153#undef _AUROSTD_XRANDOM_RAN1_RNMX
154
155 // --------------------------------------------------------------------- ran2()
156
157#define _AUROSTD_XRANDOM_RAN2_IM1 2147483563
158#define _AUROSTD_XRANDOM_RAN2_IM2 2147483399
159#define _AUROSTD_XRANDOM_RAN2_AM (1.0 / _AUROSTD_XRANDOM_RAN2_IM1)
160#define _AUROSTD_XRANDOM_RAN2_IMM1 (_AUROSTD_XRANDOM_RAN2_IM1 - 1)
161#define _AUROSTD_XRANDOM_RAN2_IA1 40014
162#define _AUROSTD_XRANDOM_RAN2_IA2 40692
163#define _AUROSTD_XRANDOM_RAN2_IQ1 53668
164#define _AUROSTD_XRANDOM_RAN2_IQ2 52774
165#define _AUROSTD_XRANDOM_RAN2_IR1 12211
166#define _AUROSTD_XRANDOM_RAN2_IR2 3791
167#define _AUROSTD_XRANDOM_RAN2_NTAB 32
168#define _AUROSTD_XRANDOM_RAN2_NDIV (1 + _AUROSTD_XRANDOM_RAN2_IMM1 / _AUROSTD_XRANDOM_RAN2_NTAB)
169#define _AUROSTD_XRANDOM_RAN2_EPS 1.2e-7
170#define _AUROSTD_XRANDOM_RAN2_RNMX (1.0 - _AUROSTD_XRANDOM_RAN2_EPS)
171
172 double ran2() { // 215.0 ns
173 int j;
174 long int k;
175 static long int _idum2 = 123456789;
176 static long int iy = 0;
177 static long int iv[_AUROSTD_XRANDOM_RAN2_NTAB];
178 float temp;
179
180 if (*_idum <= 0) {
181 if (-(*_idum) < 1) {
182 *_idum = 1;
183 } else {
184 *_idum = -(*_idum);
185 }
186 _idum2 = (*_idum);
187 for (j = _AUROSTD_XRANDOM_RAN2_NTAB + 7; j >= 0; j--) {
188 k = (*_idum) / _AUROSTD_XRANDOM_RAN2_IQ1;
190 if (*_idum < 0) {
192 }
194 iv[j] = *_idum;
195 }
196 }
197 iy = iv[0];
198 }
199 k = (*_idum) / _AUROSTD_XRANDOM_RAN2_IQ1;
201 if (*_idum < 0) {
203 }
204 k = _idum2 / _AUROSTD_XRANDOM_RAN2_IQ2;
206 if (_idum2 < 0) {
208 }
210 iy = iv[j] - _idum2;
211 iv[j] = *_idum;
212 if (iy < 1) {
214 }
217 } else {
218 return temp;
219 }
220 }
221
222#undef _AUROSTD_XRANDOM_RAN2_IM1
223#undef _AUROSTD_XRANDOM_RAN2_IM2
224#undef _AUROSTD_XRANDOM_RAN2_AM
225#undef _AUROSTD_XRANDOM_RAN2_IMM1
226#undef _AUROSTD_XRANDOM_RAN2_IA1
227#undef _AUROSTD_XRANDOM_RAN2_IA2
228#undef _AUROSTD_XRANDOM_RAN2_IQ1
229#undef _AUROSTD_XRANDOM_RAN2_IQ2
230#undef _AUROSTD_XRANDOM_RAN2_IR1
231#undef _AUROSTD_XRANDOM_RAN2_IR2
232#undef _AUROSTD_XRANDOM_RAN2_NTAB
233#undef _AUROSTD_XRANDOM_RAN2_NDIV
234#undef _AUROSTD_XRANDOM_RAN2_EPS
235#undef _AUROSTD_XRANDOM_RAN2_RNMX
236
237 // --------------------------------------------------------------------- ran3()
238
239#define _AUROSTD_XRANDOM_RAN3_MBIG 1000000000
240#define _AUROSTD_XRANDOM_RAN3_MSEED 161803398
241#define _AUROSTD_XRANDOM_RAN3_MZ 0
242#define _AUROSTD_XRANDOM_RAN3_FAC (1.0 / _AUROSTD_XRANDOM_RAN3_MBIG)
243
244 double ran3() { // 83.60 ns
245 static int inext;
246 static int inextp;
247 static long int ma[56];
248 static int iff = 0;
249 long int mj;
250 long int mk;
251 int i;
252 int ii;
253 int k;
254
255 if (*_idum < 0 || iff == 0) {
256 iff = 1;
257 mj = _AUROSTD_XRANDOM_RAN3_MSEED - (*_idum < 0 ? -*_idum : *_idum);
259 ma[55] = mj;
260 mk = 1;
261 for (i = 1; i <= 54; i++) {
262 ii = (21 * i) % 55;
263 ma[ii] = mk;
264 mk = mj - mk;
265 if (mk < _AUROSTD_XRANDOM_RAN3_MZ) {
267 }
268 mj = ma[ii];
269 }
270 for (k = 1; k <= 4; k++) {
271 for (i = 1; i <= 55; i++) {
272 ma[i] -= ma[1 + (i + 30) % 55];
273 if (ma[i] < _AUROSTD_XRANDOM_RAN3_MZ) {
275 }
276 }
277 }
278 inext = 0;
279 inextp = 31;
280 *_idum = 1;
281 }
282 if (++inext == 56) {
283 inext = 1;
284 }
285 if (++inextp == 56) {
286 inextp = 1;
287 }
288 mj = ma[inext] - ma[inextp];
289 if (mj < _AUROSTD_XRANDOM_RAN3_MZ) {
291 }
292 ma[inext] = mj;
293 return mj * _AUROSTD_XRANDOM_RAN3_FAC;
294 }
295#undef _AUROSTD_XRANDOM_RAN3_MBIG
296#undef _AUROSTD_XRANDOM_RAN3_MSEED
297#undef _AUROSTD_XRANDOM_RAN3_MZ
298#undef _AUROSTD_XRANDOM_RAN3_FAC
299
300 // -------------------------------------------------------------- generic ran()
301
302#ifdef RAN0
303 inline double ran(void) {
304 return ran0();
305 }
306#else
307#ifdef RAN1
308 inline double ran(void) {
309 return ran1();
310 }
311#else
312#ifdef RAN2
313 inline double ran(void) {
314 return ran2();
315 }
316#else
317#ifdef RAN3
318 inline double ran() {
319 return ran3();
320 }
321#else
322 inline double ran(void) {
323 return ran0();
324 }
325#endif
326#endif
327#endif
328#endif
329
330 template <class utype> inline utype uniform(const utype& x) {
331 // returns a value from 0 to x, using ran() algorithm ....
332 return (utype) x * ((utype) ran());
333 }
334
335 template <class utype> inline utype uniform(const utype& x, const utype& y) {
336 // returns a value from x to y, using ran() algorithm ....
337 return (utype) x + (y - x) * ((utype) ran());
338 }
339
340#define AST_TEMPLATE(utype) template utype uniform(const utype&);
342#undef AST_TEMPLATE
343#define AST_TEMPLATE(utype) template utype uniform(const utype&, const utype&);
345#undef AST_TEMPLATE
346
347 // --------------------------------------------------------- gaussian deviation
348
349 double gaussian() { // Normal mean=0 sigma=1
350 // returns a normally distribuited deviate with zero mean and unit
351 // variance, using ran() as source of uniform deviates
352 static int iset = 0;
353 static double gset;
354 double fac;
355 double rsq;
356 double v1;
357 double v2;
358
359 if (iset == 0) {
360 do { // we need two
361 v1 = 2.0 * ran() - 1.0; // uniforms
362 v2 = 2.0 * ran() - 1.0; // variabiles
363 rsq = v1 * v1 + v2 * v2; // in the unit
364 } while (rsq >= 1.0 || rsq == 0.0); // circle ..
365 fac = std::sqrt(-2.0 * log(rsq) / rsq);
366 gset = v1 * fac;
367 iset = 1; // set flag
368 return v2 * fac;
369 } else {
370 iset = 0; // clear flag
371 return gset;
372 }
373 }
374
375 template <class utype>
376 inline utype // gaussian(mean=0,sigma)
377 gaussian(const utype& sigma) {
378 // returns a gaussian deviate with mean=0, sigma. using gaussian()
379 // return (utype) sqrt(sigma)*gaussian();
380 return (utype) sigma * ((utype) gaussian());
381 }
382
383 template <class utype>
384 inline utype // gaussian(m,sigma)
385 gaussian(const utype& mean, const utype& sigma) {
386 // returns a gaussian deviate with mean=mean, sigma. using gaussian()
387 // return (utype) mean+sqrt(sigma)*gaussian();
388 return (utype) mean + sigma * ((utype) gaussian());
389 }
390
391 // ------------------------------------------------------ exponential deviation
392
393 inline double expdev() { // exponential lambda=1
394 // returns a exponentially distribuited deviate with lambda=1
395 double u;
396 do {
397 u = ran();
398 } while (u == 0.0);
399 return -log(u);
400 }
401
402 template <class utype>
403 inline utype // exponential lambda
404 expdev(const utype& lambda) {
405 // returns a exponentially distribuited deviate with lambda
406 double u;
407 do {
408 u = ran();
409 } while (u == 0.0);
410 return (utype) -lambda * ((utype) log(u));
411 }
412
413 // ---------------------------------------------------------- laplace deviation
414
415 inline double laplacedev() { // laplace mean=0 a=1
416 // returns a laplace distribuited deviate p(x)=1/2a*exp(-|x-lambda|/a)
417 // sigma^2=2a*a mean=lambda
418 double u;
419 do {
420 u = ran();
421 } while (u == 0.0);
422 return u < 0.5 ? log(2.0 * u) : -log(2.0 * (1.0 - u));
423 }
424
425 template <class utype>
426 inline utype // laplace mean=0 a
427 laplacedev(const utype& a) {
428 // returns a laplace distribuited deviate p(x)=1/2a*exp(-|x-lambda|/a)
429 // sigma^2=2a*a mean=lambda
430 double u;
431 do {
432 u = ran();
433 } while (u == 0.0);
434 return u < 0.5 ? a * ((utype) log(2.0 * u)) : -a * ((utype) log(2.0 * (1.0 - u)));
435 }
436
437 template <class utype>
438 inline utype // laplace mean a
439 laplacedev(const utype& a, const utype& lambda) {
440 // returns a laplace distribuited deviate p(x)=1/2a*exp(-|x-lambda|/a)
441 // sigma^2=2a*a mean=lambda
442 double u;
443 do {
444 u = ran();
445 } while (u == 0.0);
446 return u < 0.5 ? a * ((utype) log(2.0 * u)) + lambda : -a * ((utype) log(2.0 * (1.0 - u))) + lambda;
447 }
448
449 // ---------------------------------------------------------- poisson deviation
450} // namespace aurostd
451
452// ----------------------------------------------------------------------------
453// ----------------------------------------------------------------------------
454
455#ifdef _AUROSTD_XVECTOR_CPP_
456
457namespace aurostd {
458 // namespace aurostd
459 template <class utype>
460 xvector<utype> // uniform xvector<utype> [x,y]
461 uniform(const xvector<utype>& a, const utype& x, const utype& y) {
462 for (int i = a.lrows; i <= a.urows; i++) a[i] = (utype) x + (y - x) * uniform(utype(1.0));
463 return a;
464 }
465 template xvector<double> uniform(const xvector<double>& a, const double& x, const double& y);
466
467 template <class utype>
468 xvector<utype> // uniform xvector<utype> [0,y]
469 uniform(const xvector<utype>& a, const utype& y) {
470 return uniform(a, utype(0.0), utype(y));
471 }
472
473 template <class utype>
474 xvector<utype> // uniform xvector<utype> [0,1]
475 uniform(const xvector<utype>& a) {
476 return uniform(a, utype(0.0), utype(1.0));
477 }
478
479 template <class utype>
480 xvector<xcomplex<utype>> // xcomplex xvector of uniforms
481 uniform(const xvector<xcomplex<utype>>& a, // real,imag in ([x1,y1],[x2,y2])
482 const utype& x1,
483 const utype& y1,
484 const utype& x2,
485 const utype& y2) {
486 for (int i = a.lrows; i <= a.urows; i++) a[i] = xcomplex<utype>(x1 + (y1 - x1) * uniform(utype(1.0)), x2 + (y2 - x2) * uniform(utype(1.0)));
487 return a;
488 }
489
490 template <class utype>
491 xvector<xcomplex<utype>> // xcomplex xvector of uniforms
492 uniform(const xvector<xcomplex<utype>>& a, // real,imag in ([0,x],[0,y])
493 const utype& x,
494 const utype& y) {
495 return uniform(a, utype(0.0), x, utype(0.0), y);
496 }
497
498 template <class utype>
499 xvector<xcomplex<utype>> // xcomplex xvector of uniforms
500 uniform(const xvector<xcomplex<utype>>& a, // real,imag in ([0,y],[0,y])
501 const utype& y) {
502 return uniform(a, utype(0.0), y, utype(0.0), y);
503 }
504
505 template <class utype>
506 xvector<xcomplex<utype>> // xcomplex xvector of uniforms
507 uniform(const xvector<xcomplex<utype>>& a) { // real,imag in ([0,1],[0,1])
508 return uniform(a, utype(0.0), utype(1.0), utype(0.0), utype(1.0));
509 }
510} // namespace aurostd
511
512// ----------------------------------------------------- gaussian distributions
513
514namespace aurostd {
515 // namespace aurostd
516 template <class utype>
517 xvector<utype> // gaussian xvector<utype> (m,sigma)
518 gaussian(const xvector<utype>& a, const utype& m, const utype& sigma) {
519 for (int i = a.lrows; i <= a.urows; i++)
520 // a[i]=(utype) m+sqrt(sigma)*gaussian();
521 a[i] = (utype) m + sigma * gaussian();
522 return a;
523 }
524
525 template <class utype>
526 xvector<utype> // gaussian xvector<utype> (m,sigma)
527 gaussian(const xvector<utype>& a, const xvector<utype>& m, const xvector<utype>& sigma) {
528 for (int i = a.lrows; i <= a.urows; i++)
529 // a[i]=(utype) m[i]+sqrt(sigma[i])*gaussian();
530 a[i] = (utype) m[i] + sigma[i] * gaussian();
531 return a;
532 }
533
534 template <class utype>
535 xvector<utype> // gaussian xvector<utype> (0,sigma)
536 gaussian(const xvector<utype>& a, const utype& sigma) {
537 return gaussian(a, utype(0.0), utype(sigma));
538 }
539
540 template <class utype>
541 xvector<utype> // gaussian xvector<utype> (0,1)
542 gaussian(const xvector<utype>& a) {
543 return gaussian(a, utype(0.0), utype(1.0));
544 }
545
546 template <class utype>
547 xvector<xcomplex<utype>> // xcomplex xvector of gaussians
548 gaussian(const xvector<xcomplex<utype>>& a, // real,imag (m1,sigma1),(m2,sigma2)
549 const utype& m1,
550 const utype& sigma1,
551 const utype& m2,
552 const utype& sigma2) {
553 for (int i = a.lrows; i <= a.urows; i++)
554 // a[i]=xcomplex<utype>(m1+sqrt(sigma1)*gaussian(),
555 // m2+sqrt(sigma2)*gaussian());
556 a[i] = xcomplex<utype>(m1 + sigma1 * gaussian(), m2 + sigma2 * gaussian());
557 return a;
558 }
559
560 template <class utype>
561 xvector<xcomplex<utype>> // xcomplex xvector of gaussians
562 gaussian(const xvector<xcomplex<utype>>& a, // real,imag in (0,m),(0,sigma)
563 const utype& m,
564 const utype& sigma) {
565 return gaussian(a, utype(0.0), m, utype(0.0), sigma);
566 }
567
568 template <class utype>
569 xvector<xcomplex<utype>> // xcomplex xvector of gaussians
570 gaussian(const xvector<xcomplex<utype>>& a,// real,imag in (0,sigma),(0,sigma)
571 const utype& sigma) {
572 return gaussian(a, utype(0.0), sigma, utype(0.0), sigma);
573 }
574
575 template <class utype>
576 xvector<xcomplex<utype>> // xcomplex xvector of gaussians
577 gaussian(const xvector<xcomplex<utype>>& a) { // real,imag in (0,1),(0,1)
578 return gaussian(a, utype(0.0), utype(1.0), utype(0.0), utype(1.0));
579 }
580} // namespace aurostd
581
582#endif
583
584// ----------------------------------------------------------------------------
585// ----------------------------------------------------------------------------
586#ifdef _AUROSTD_XMATRIX_CPP_
587
588namespace aurostd {
589 // namespace aurostd
590 template <class utype>
591 xmatrix<utype> // uniform xmatrix<utype> [x,y]
592 uniform(const xmatrix<utype>& a, const utype& x, const utype& y) {
593 for (int i = a.lrows; i <= a.urows; i++)
594 for (int j = a.lcols; j <= a.ucols; j++) a[i][j] = (utype) x + (y - x) * uniform(utype(1.0));
595 return a;
596 }
597
598 template <class utype>
599 xmatrix<utype> // uniform xmatrix<utype> [0,y]
600 uniform(const xmatrix<utype>& a, const utype& y) {
601 return uniform(a, utype(0.0), utype(y));
602 }
603
604 template <class utype>
605 xmatrix<utype> // uniform xmatrix<utype> [0,1]
606 uniform(const xmatrix<utype>& a) {
607 return uniform(a, utype(0.0), utype(1.0));
608 }
609
610 template <class utype>
611 xmatrix<xcomplex<utype>> // xcomplex xmatrix of uniforms
612 uniform(const xmatrix<xcomplex<utype>>& a, // real,imag in ([x1,y1],[x2,y2])
613 const utype& x1,
614 const utype& y1,
615 const utype& x2,
616 const utype& y2) {
617 for (int i = a.lrows; i <= a.urows; i++)
618 for (int j = a.lcols; j <= a.ucols; j++) a[i][j] = xcomplex<utype>(x1 + (y1 - x1) * uniform(utype(1.0)), x2 + (y2 - x2) * uniform(utype(1.0)));
619 return a;
620 }
621
622 template <class utype>
623 xmatrix<xcomplex<utype>> // xcomplex xmatrix of uniforms
624 uniform(const xmatrix<xcomplex<utype>>& a, // real,imag in ([0,x],[0,y])
625 const utype& x,
626 const utype& y) {
627 return uniform(a, utype(0.0), x, utype(0.0), y);
628 }
629
630 template <class utype>
631 xmatrix<xcomplex<utype>> // xcomplex xmatrix of uniforms
632 uniform(const xmatrix<xcomplex<utype>>& a, // real,imag in ([0,y],[0,y])
633 const utype& y) {
634 return uniform(a, utype(0.0), y, utype(0.0), y);
635 }
636
637 template <class utype>
638 xmatrix<xcomplex<utype>> // xcomplex xmatrix of uniforms
639 uniform(const xmatrix<xcomplex<utype>>& a) { // real,imag in ([0,1],[0,1])
640 return uniform(a, utype(0.0), utype(1.0), utype(0.0), utype(1.0));
641 }
642} // namespace aurostd
643
644// ----------------------------------------------------- gaussian distributions
645
646namespace aurostd {
647 // namespace aurostd
648 template <class utype>
649 xmatrix<utype> // gaussian xmatrix<utype> (m,sigma)
650 gaussian(const xmatrix<utype>& a, const utype& m, const utype& sigma) {
651 for (int i = a.lrows; i <= a.urows; i++)
652 for (int j = a.lcols; j <= a.ucols; j++)
653 // a[i][j]=(utype) (utype) m+sqrt(sigma)*gaussian();
654 a[i][j] = (utype) (utype) m + sigma * gaussian();
655 return a;
656 }
657
658 template <class utype>
659 xmatrix<utype> // gaussian xmatrix<utype> (m=0,sigma)
660 gaussian(const xmatrix<utype>& a, const utype& sigma) {
661 return gaussian(a, utype(0.0), utype(sigma));
662 }
663
664 template <class utype>
665 xmatrix<utype> // gaussian xmatrix<utype> (m=0,sigma=1)
666 gaussian(const xmatrix<utype>& a) {
667 return gaussian(a, utype(0.0), utype(1.0));
668 }
669
670 template <class utype>
671 xmatrix<xcomplex<utype>> // xcomplex xmatrix of gaussians
672 gaussian(const xmatrix<xcomplex<utype>>& a, // real,imag(m1,sigma1),(m2,sigma2)
673 const utype& m1,
674 const utype& sigma1,
675 const utype& m2,
676 const utype& sigma2) {
677 for (int i = a.lrows; i <= a.urows; i++)
678 for (int j = a.lcols; j <= a.ucols; j++)
679 // a[i][j]=xcomplex<utype>(m1+sqrt(sigma1)*gaussian(),
680 // m2+sqrt(sigma2)*gaussian());
681 a[i][j] = xcomplex<utype>(m1 + sigma1 * gaussian(), m2 + sigma2 * gaussian());
682 return a;
683 }
684
685 template <class utype>
686 xmatrix<xcomplex<utype>> // xcomplex xmatrix of gaussians
687 gaussian(const xmatrix<xcomplex<utype>>& a, // real,imag (0,sigma1),(0,sigma2)
688 const utype& sigma1,
689 const utype& sigma2) {
690 return gaussian(a, utype(0.0), sigma1, utype(0.0), sigma2);
691 }
692
693 template <class utype>
694 xmatrix<xcomplex<utype>> // xcomplex xmatrix of gaussians
695 gaussian(const xmatrix<xcomplex<utype>>& a, // real,imag (0,sigma),(0,sigma)
696 const utype& sigma) {
697 return gaussian(a, utype(0.0), sigma, utype(0.0), sigma);
698 }
699
700 template <class utype>
701 xmatrix<xcomplex<utype>> // xcomplex xmatrix of gaussians
702 gaussian(const xmatrix<xcomplex<utype>>& a) { // real,imag in (0,1),(0,1)
703 return gaussian(a, utype(0.0), utype(1.0), utype(0.0), utype(1.0));
704 }
705} // namespace aurostd
706
707#endif
708
709// ----------------------------------------------------------------------------
710// ----------------------------------------------------------------------------
711#ifdef __XTENSOR3_CPP
712
713namespace aurostd {
714 // namespace aurostd
715 template <class utype>
716 xtensor3<utype> // uniform xtensor3<utype> [x,y]
717 uniform(const xtensor3<utype>& a, const utype& x, const utype& y) {
718 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
719 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
720 for (int k = a.lindex[3]; k <= a.uindex[3]; k++) a[i][j][k] = (utype) x + (y - x) * uniform(utype(1.0));
721 return a;
722 }
723
724 template <class utype>
725 xtensor3<utype> // uniform xtensor3<utype> [0,y]
726 uniform(const xtensor3<utype>& a, const utype& y) {
727 return uniform(a, utype(0.0), utype(y));
728 }
729
730 template <class utype>
731 xtensor3<utype> // uniform xtensor3<utype> [0,1]
732 uniform(const xtensor3<utype>& a) {
733 return uniform(a, utype(0.0), utype(1.0));
734 }
735
736 template <class utype>
737 xtensor3<xcomplex<utype>> // xcomplex xtensor3 of uniforms
738 uniform(const xtensor3<xcomplex<utype>>& a, // real,imag in ([x1,y1],[x2,y2])
739 const utype& x1,
740 const utype& y1,
741 const utype& x2,
742 const utype& y2) {
743 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
744 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
745 for (int k = a.lindex[3]; k <= a.uindex[3]; k++) a[i][j][k] = xcomplex<utype>(x1 + (y1 - x1) * uniform(utype(1.0)), x2 + (y2 - x2) * uniform(utype(1.0)));
746 return a;
747 }
748
749 template <class utype>
750 xtensor3<xcomplex<utype>> // xcomplex xtensor3 of uniforms
751 uniform(const xtensor3<xcomplex<utype>>& a, // real,imag in ([0,x],[0,y])
752 const utype& x,
753 const utype& y) {
754 return uniform(a, utype(0.0), x, utype(0.0), y);
755 }
756
757 template <class utype>
758 xtensor3<xcomplex<utype>> // xcomplex xtensor3 of uniforms
759 uniform(const xtensor3<xcomplex<utype>>& a, // real,imag in ([0,y],[0,y])
760 const utype& y) {
761 return uniform(a, utype(0.0), y, utype(0.0), y);
762 }
763
764 template <class utype>
765 xtensor3<xcomplex<utype>> // xcomplex xtensor3 of uniforms
766 uniform(const xtensor3<xcomplex<utype>>& a) { // real,imag in ([0,1],[0,1])
767 return uniform(a, utype(0.0), utype(1.0), utype(0.0), utype(1.0));
768 }
769} // namespace aurostd
770
771// ----------------------------------------------------- gaussian distributions
772
773namespace aurostd {
774 // namespace aurostd
775 template <class utype>
776 xtensor3<utype> // gaussian xtensor3<utype> (m,sigma)
777 gaussian(const xtensor3<utype>& a, const utype& m, const utype& sigma) {
778 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
779 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
780 for (int k = a.lindex[3]; k <= a.uindex[3]; k++)
781 // a[i][j][k]=(utype) (utype) m+sqrt(sigma)*gaussian();
782 a[i][j][k] = (utype) (utype) m + sigma * gaussian();
783 return a;
784 }
785
786 template <class utype>
787 xtensor3<utype> // gaussian xtensor3<utype> (m=0,sigma)
788 gaussian(const xtensor3<utype>& a, const utype& sigma) {
789 return gaussian(a, utype(0.0), utype(sigma));
790 }
791
792 template <class utype>
793 xtensor3<utype> // gaussian xtensor3<utype> (m=0,sigma=1)
794 gaussian(const xtensor3<utype>& a) {
795 return gaussian(a, utype(0.0), utype(1.0));
796 }
797
798 template <class utype>
799 xtensor3<xcomplex<utype>> // xcomplex xtensor3 of gaussians
800 gaussian(const xtensor3<xcomplex<utype>>& a, // real,imag(m1,sigma1),(m2,sigma2)
801 const utype& m1,
802 const utype& sigma1,
803 const utype& m2,
804 const utype& sigma2) {
805 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
806 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
807 for (int k = a.lindex[3]; k <= a.uindex[3]; k++)
808 // a[i][j][k]=xcomplex<utype>(m1+sqrt(sigma1)*gaussian(),
809 // m2+sqrt(sigma2)*gaussian());
810 a[i][j][k] = xcomplex<utype>(m1 + sigma1 * gaussian(), m2 + sigma2 * gaussian());
811 return a;
812 }
813
814 template <class utype>
815 xtensor3<xcomplex<utype>> // xcomplex xtensor3 of gaussians
816 gaussian(const xtensor3<xcomplex<utype>>& a, // real,imag (0,sigma1),(0,sigma2)
817 const utype& sigma1,
818 const utype& sigma2) {
819 return gaussian(a, utype(0.0), sigma1, utype(0.0), sigma2);
820 }
821
822 template <class utype>
823 xtensor3<xcomplex<utype>> // xcomplex xtensor3 of gaussians
824 gaussian(const xtensor3<xcomplex<utype>>& a, // real,imag (0,sigma),(0,sigma)
825 const utype& sigma) {
826 return gaussian(a, utype(0.0), sigma, utype(0.0), sigma);
827 }
828
829 template <class utype>
830 xtensor3<xcomplex<utype>> // xcomplex xtensor3 of gaussians
831 gaussian(const xtensor3<xcomplex<utype>>& a) { // real,imag in (0,1),(0,1)
832 return gaussian(a, utype(0.0), utype(1.0), utype(0.0), utype(1.0));
833 }
834} // namespace aurostd
835
836#endif
837// ----------------------------------------------------------------------------
838
839// ----------------------------------------------------------------------------
840// ----------------------------------------------------------------------------
841#ifdef __XTENSOR4_CPP
842
843namespace aurostd {
844 // namespace aurostd
845 template <class utype>
846 xtensor4<utype> // uniform xtensor4<utype> [x,y]
847 uniform(const xtensor4<utype>& a, const utype& x, const utype& y) {
848 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
849 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
850 for (int k = a.lindex[3]; k <= a.uindex[3]; k++)
851 for (int l = a.lindex[4]; l <= a.uindex[4]; l++) a[i][j][k][l] = (utype) x + (y - x) * uniform(utype(1.0));
852 return a;
853 }
854
855 template <class utype>
856 xtensor4<utype> // uniform xtensor4<utype> [0,y]
857 uniform(const xtensor4<utype>& a, const utype& y) {
858 return uniform(a, utype(0.0), utype(y));
859 }
860
861 template <class utype>
862 xtensor4<utype> // uniform xtensor4<utype> [0,1]
863 uniform(const xtensor4<utype>& a) {
864 return uniform(a, utype(0.0), utype(1.0));
865 }
866
867 template <class utype>
868 xtensor4<xcomplex<utype>> // xcomplex xtensor4 of uniforms
869 uniform(const xtensor4<xcomplex<utype>>& a, // real,imag in ([x1,y1],[x2,y2])
870 const utype& x1,
871 const utype& y1,
872 const utype& x2,
873 const utype& y2) {
874 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
875 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
876 for (int k = a.lindex[3]; k <= a.uindex[3]; k++)
877 for (int l = a.lindex[4]; l <= a.uindex[4]; l++) a[i][j][k][l] = xcomplex<utype>(x1 + (y1 - x1) * uniform(utype(1.0)), x2 + (y2 - x2) * uniform(utype(1.0)));
878 return a;
879 }
880
881 template <class utype>
882 xtensor4<xcomplex<utype>> // xcomplex xtensor4 of uniforms
883 uniform(const xtensor4<xcomplex<utype>>& a, // real,imag in ([0,x],[0,y])
884 const utype& x,
885 const utype& y) {
886 return uniform(a, utype(0.0), x, utype(0.0), y);
887 }
888
889 template <class utype>
890 xtensor4<xcomplex<utype>> // xcomplex xtensor4 of uniforms
891 uniform(const xtensor4<xcomplex<utype>>& a, // real,imag in ([0,y],[0,y])
892 const utype& y) {
893 return uniform(a, utype(0.0), y, utype(0.0), y);
894 }
895
896 template <class utype>
897 xtensor4<xcomplex<utype>> // xcomplex xtensor4 of uniforms
898 uniform(const xtensor4<xcomplex<utype>>& a) { // real,imag in ([0,1],[0,1])
899 return uniform(a, utype(0.0), utype(1.0), utype(0.0), utype(1.0));
900 }
901} // namespace aurostd
902
903// ----------------------------------------------------- gaussian distributions
904
905namespace aurostd {
906 // namespace aurostd
907 template <class utype>
908 xtensor4<utype> // gaussian xtensor4<utype> (m,sigma)
909 gaussian(const xtensor4<utype>& a, const utype& m, const utype& sigma) {
910 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
911 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
912 for (int k = a.lindex[3]; k <= a.uindex[3]; k++)
913 for (int l = a.lindex[4]; l <= a.uindex[4]; l++)
914 // a[i][j][k][l]=(utype) (utype) m+sqrt(sigma)*gaussian();
915 a[i][j][k][l] = (utype) (utype) m + sigma * gaussian();
916 return a;
917 }
918
919 template <class utype>
920 xtensor4<utype> // gaussian xtensor4<utype> (m=0,sigma)
921 gaussian(const xtensor4<utype>& a, const utype& sigma) {
922 return gaussian(a, utype(0.0), utype(sigma));
923 }
924
925 template <class utype>
926 xtensor4<utype> // gaussian xtensor4<utype> (m=0,sigma=1)
927 gaussian(const xtensor4<utype>& a) {
928 return gaussian(a, utype(0.0), utype(1.0));
929 }
930
931 template <class utype>
932 xtensor4<xcomplex<utype>> // xcomplex xtensor4 of gaussians
933 gaussian(const xtensor4<xcomplex<utype>>& a, // real,imag(m1,sigma1),(m2,sigma2)
934 const utype& m1,
935 const utype& sigma1,
936 const utype& m2,
937 const utype& sigma2) {
938 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
939 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
940 for (int k = a.lindex[3]; k <= a.uindex[3]; k++)
941 for (int l = a.lindex[4]; l <= a.uindex[4]; l++)
942 // a[i][j][k][l]=xcomplex<utype>(m1+sqrt(sigma1)*gaussian(),
943 // m2+sqrt(sigma2)*gaussian());
944 \ a[i][j][k][l] = xcomplex<utype>(m1 + sigma1 * gaussian(), m2 + sigma2 * gaussian());
945 return a;
946 }
947
948 template <class utype>
949 xtensor4<xcomplex<utype>> // xcomplex xtensor4 of gaussians
950 gaussian(const xtensor4<xcomplex<utype>>& a, // real,imag (0,sigma1),(0,sigma2)
951 const utype& sigma1,
952 const utype& sigma2) {
953 return gaussian(a, utype(0.0), sigma1, utype(0.0), sigma2);
954 }
955
956 template <class utype>
957 xtensor4<xcomplex<utype>> // xcomplex xtensor4 of gaussians
958 gaussian(const xtensor4<xcomplex<utype>>& a, // real,imag (0,sigma),(0,sigma)
959 const utype& sigma) {
960 return gaussian(a, utype(0.0), sigma, utype(0.0), sigma);
961 }
962
963 template <class utype>
964 xtensor4<xcomplex<utype>> // xcomplex xtensor4 of gaussians
965 gaussian(const xtensor4<xcomplex<utype>>& a) { // real,imag in (0,1),(0,1)
966 return gaussian(a, utype(0.0), utype(1.0), utype(0.0), utype(1.0));
967 }
968} // namespace aurostd
969
970#endif
971// ----------------------------------------------------------------------------
972
973// ----------------------------------------------------------------------------
974// ----------------------------------------------------------------------------
975#ifdef __XTENSOR5_CPP
976
977namespace aurostd {
978 // namespace aurostd
979 template <class utype>
980 xtensor5<utype> // uniform xtensor5<utype> [x,y]
981 uniform(const xtensor5<utype>& a, const utype& x, const utype& y) {
982 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
983 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
984 for (int k = a.lindex[3]; k <= a.uindex[3]; k++)
985 for (int l = a.lindex[4]; l <= a.uindex[4]; l++)
986 for (int m = a.lindex[5]; m <= a.uindex[5]; m++) a[i][j][k][l][m] = (utype) x + (y - x) * uniform(utype(1.0));
987 return a;
988 }
989
990 template <class utype>
991 xtensor5<utype> // uniform xtensor5<utype> [0,y]
992 uniform(const xtensor5<utype>& a, const utype& y) {
993 return uniform(a, utype(0.0), utype(y));
994 }
995
996 template <class utype>
997 xtensor5<utype> // uniform xtensor5<utype> [0,1]
998 uniform(const xtensor5<utype>& a) {
999 return uniform(a, utype(0.0), utype(1.0));
1000 }
1001
1002 template <class utype>
1003 xtensor5<xcomplex<utype>> // xcomplex xtensor5 of uniforms
1004 uniform(const xtensor5<xcomplex<utype>>& a, // real,imag in ([x1,y1],[x2,y2])
1005 const utype& x1,
1006 const utype& y1,
1007 const utype& x2,
1008 const utype& y2) {
1009 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
1010 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
1011 for (int k = a.lindex[3]; k <= a.uindex[3]; k++)
1012 for (int l = a.lindex[4]; l <= a.uindex[4]; l++)
1013 for (int m = a.lindex[5]; m <= a.uindex[5]; m++) a[i][j][k][l][m] = xcomplex<utype>(x1 + (y1 - x1) * uniform(utype(1.0)), x2 + (y2 - x2) * uniform(utype(1.0)));
1014 return a;
1015 }
1016
1017 template <class utype>
1018 xtensor5<xcomplex<utype>> // xcomplex xtensor5 of uniforms
1019 uniform(const xtensor5<xcomplex<utype>>& a, // real,imag in ([0,x],[0,y])
1020 const utype& x,
1021 const utype& y) {
1022 return uniform(a, utype(0.0), x, utype(0.0), y);
1023 }
1024
1025 template <class utype>
1026 xtensor5<xcomplex<utype>> // xcomplex xtensor5 of uniforms
1027 uniform(const xtensor5<xcomplex<utype>>& a, // real,imag in ([0,y],[0,y])
1028 const utype& y) {
1029 return uniform(a, utype(0.0), y, utype(0.0), y);
1030 }
1031
1032 template <class utype>
1033 xtensor5<xcomplex<utype>> // xcomplex xtensor5 of uniforms
1034 uniform(const xtensor5<xcomplex<utype>>& a) { // real,imag in ([0,1],[0,1])
1035 return uniform(a, utype(0.0), utype(1.0), utype(0.0), utype(1.0));
1036 }
1037} // namespace aurostd
1038
1039// ----------------------------------------------------- gaussian distributions
1040
1041namespace aurostd {
1042 // namespace aurostd
1043 template <class utype>
1044 xtensor5<utype> // gaussian xtensor5<utype> (m,sigma)
1045 gaussian(const xtensor5<utype>& a, const utype& m, const utype& sigma) {
1046 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
1047 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
1048 for (int k = a.lindex[3]; k <= a.uindex[3]; k++)
1049 for (int l = a.lindex[4]; l <= a.uindex[4]; l++)
1050 for (int m = a.lindex[5]; m <= a.uindex[5]; m++)
1051 // a[i][j][k][l][m]=(utype) (utype) m+sqrt(sigma)*gaussian();
1052 a[i][j][k][l][m] = (utype) (utype) m + sigma * gaussian();
1053 return a;
1054 }
1055
1056 template <class utype>
1057 xtensor5<utype> // gaussian xtensor5<utype> (m=0,sigma)
1058 gaussian(const xtensor5<utype>& a, const utype& sigma) {
1059 return gaussian(a, utype(0.0), utype(sigma));
1060 }
1061
1062 template <class utype>
1063 xtensor5<utype> // gaussian xtensor5<utype> (m=0,sigma=1)
1064 gaussian(const xtensor5<utype>& a) {
1065 return gaussian(a, utype(0.0), utype(1.0));
1066 }
1067
1068 template <class utype>
1069 xtensor5<xcomplex<utype>> // xcomplex xtensor5 of gaussians
1070 gaussian(const xtensor5<xcomplex<utype>>& a, // real,imag(m1,sigma1),(m2,sigma2)
1071 const utype& m1,
1072 const utype& sigma1,
1073 const utype& m2,
1074 const utype& sigma2) {
1075 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
1076 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
1077 for (int k = a.lindex[3]; k <= a.uindex[3]; k++)
1078 for (int l = a.lindex[4]; l <= a.uindex[4]; l++)
1079 for (int m = a.lindex[5]; m <= a.uindex[5]; m++)
1080 // a[i][j][k][l][m]=xcomplex<utype>(m1+sqrt(sigma1)*gaussian(),
1081 // m2+sqrt(sigma2)*gaussian());
1082 a[i][j][k][l][m] = xcomplex<utype>(m1 + sigma1 * gaussian(), m2 + sigma2 * gaussian());
1083 return a;
1084 }
1085
1086 template <class utype>
1087 xtensor5<xcomplex<utype>> // xcomplex xtensor5 of gaussians
1088 gaussian(const xtensor5<xcomplex<utype>>& a, // real,imag (0,sigma1),(0,sigma2)
1089 const utype& sigma1,
1090 const utype& sigma2) {
1091 return gaussian(a, utype(0.0), sigma1, utype(0.0), sigma2);
1092 }
1093
1094 template <class utype>
1095 xtensor5<xcomplex<utype>> // xcomplex xtensor5 of gaussians
1096 gaussian(const xtensor5<xcomplex<utype>>& a, // real,imag (0,sigma),(0,sigma)
1097 const utype& sigma) {
1098 return gaussian(a, utype(0.0), sigma, utype(0.0), sigma);
1099 }
1100
1101 template <class utype>
1102 xtensor5<xcomplex<utype>> // xcomplex xtensor5 of gaussians
1103 gaussian(const xtensor5<xcomplex<utype>>& a) { // real,imag in (0,1),(0,1)
1104 return gaussian(a, utype(0.0), utype(1.0), utype(0.0), utype(1.0));
1105 }
1106} // namespace aurostd
1107
1108#endif
1109// ----------------------------------------------------------------------------
1110
1111// ----------------------------------------------------------------------------
1112// ----------------------------------------------------------------------------
1113#ifdef __XTENSOR6_CPP
1114
1115namespace aurostd {
1116 // namespace aurostd
1117 template <class utype>
1118 xtensor6<utype> // uniform xtensor6<utype> [x,y]
1119 uniform(const xtensor6<utype>& a, const utype& x, const utype& y) {
1120 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
1121 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
1122 for (int k = a.lindex[3]; k <= a.uindex[3]; k++)
1123 for (int l = a.lindex[4]; l <= a.uindex[4]; l++)
1124 for (int m = a.lindex[5]; m <= a.uindex[5]; m++)
1125 for (int n = a.lindex[6]; n <= a.uindex[6]; n++) a[i][j][k][l][m][n] = (utype) x + (y - x) * uniform(utype(1.0));
1126 return a;
1127 }
1128
1129 template <class utype>
1130 xtensor6<utype> // uniform xtensor6<utype> [0,y]
1131 uniform(const xtensor6<utype>& a, const utype& y) {
1132 return uniform(a, utype(0.0), utype(y));
1133 }
1134
1135 template <class utype>
1136 xtensor6<utype> // uniform xtensor6<utype> [0,1]
1137 uniform(const xtensor6<utype>& a) {
1138 return uniform(a, utype(0.0), utype(1.0));
1139 }
1140
1141 template <class utype>
1142 xtensor6<xcomplex<utype>> // xcomplex xtensor6 of uniforms
1143 uniform(const xtensor6<xcomplex<utype>>& a, // real,imag in ([x1,y1],[x2,y2])
1144 const utype& x1,
1145 const utype& y1,
1146 const utype& x2,
1147 const utype& y2) {
1148 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
1149 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
1150 for (int k = a.lindex[3]; k <= a.uindex[3]; k++)
1151 for (int l = a.lindex[4]; l <= a.uindex[4]; l++)
1152 for (int m = a.lindex[5]; m <= a.uindex[5]; m++)
1153 for (int n = a.lindex[6]; n <= a.uindex[6]; n++) a[i][j][k][l][m][n] = xcomplex<utype>(x1 + (y1 - x1) * uniform(utype(1.0)), x2 + (y2 - x2) * uniform(utype(1.0)));
1154 return a;
1155 }
1156
1157 template <class utype>
1158 xtensor6<xcomplex<utype>> // xcomplex xtensor6 of uniforms
1159 uniform(const xtensor6<xcomplex<utype>>& a, // real,imag in ([0,x],[0,y])
1160 const utype& x,
1161 const utype& y) {
1162 return uniform(a, utype(0.0), x, utype(0.0), y);
1163 }
1164
1165 template <class utype>
1166 xtensor6<xcomplex<utype>> // xcomplex xtensor6 of uniforms
1167 uniform(const xtensor6<xcomplex<utype>>& a, // real,imag in ([0,y],[0,y])
1168 const utype& y) {
1169 return uniform(a, utype(0.0), y, utype(0.0), y);
1170 }
1171
1172 template <class utype>
1173 xtensor6<xcomplex<utype>> // xcomplex xtensor6 of uniforms
1174 uniform(const xtensor6<xcomplex<utype>>& a) { // real,imag in ([0,1],[0,1])
1175 return uniform(a, utype(0.0), utype(1.0), utype(0.0), utype(1.0));
1176 }
1177} // namespace aurostd
1178
1179// ----------------------------------------------------- gaussian distributions
1180
1181namespace aurostd {
1182 // namespace aurostd
1183 template <class utype>
1184 xtensor6<utype> // gaussian xtensor6<utype> (m,sigma)
1185 gaussian(const xtensor6<utype>& a, const utype& m, const utype& sigma) {
1186 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
1187 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
1188 for (int k = a.lindex[3]; k <= a.uindex[3]; k++)
1189 for (int l = a.lindex[4]; l <= a.uindex[4]; l++)
1190 for (int m = a.lindex[5]; m <= a.uindex[5]; m++)
1191 for (int n = a.lindex[6]; n <= a.uindex[6]; n++)
1192 // a[i][j][k][l][m][n]=(utype) (utype) m+sqrt(sigma)*gaussian();
1193 a[i][j][k][l][m][n] = (utype) (utype) m + sigma * gaussian();
1194 return a;
1195 }
1196
1197 template <class utype>
1198 xtensor6<utype> // gaussian xtensor6<utype> (m=0,sigma)
1199 gaussian(const xtensor6<utype>& a, const utype& sigma) {
1200 return gaussian(a, utype(0.0), utype(sigma));
1201 }
1202
1203 template <class utype>
1204 xtensor6<utype> // gaussian xtensor6<utype> (m=0,sigma=1)
1205 gaussian(const xtensor6<utype>& a) {
1206 return gaussian(a, utype(0.0), utype(1.0));
1207 }
1208
1209 template <class utype>
1210 xtensor6<xcomplex<utype>> // xcomplex xtensor6 of gaussians
1211 gaussian(const xtensor6<xcomplex<utype>>& a, // real,imag(m1,sigma1),(m2,sigma2)
1212 const utype& m1,
1213 const utype& sigma1,
1214 const utype& m2,
1215 const utype& sigma2) {
1216 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
1217 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
1218 for (int k = a.lindex[3]; k <= a.uindex[3]; k++)
1219 for (int l = a.lindex[4]; l <= a.uindex[4]; l++)
1220 for (int m = a.lindex[5]; m <= a.uindex[5]; m++)
1221 for (int n = a.lindex[6]; n <= a.uindex[6]; n++)
1222 // a[i][j][k][l][m][n]=xcomplex<utype>(m1+sqrt(sigma1)*gaussian(),
1223 // m2+sqrt(sigma2)*gaussian());
1224 a[i][j][k][l][m][n] = xcomplex<utype>(m1 + sigma1 * gaussian(), m2 + sigma2 * gaussian());
1225 return a;
1226 }
1227
1228 template <class utype>
1229 xtensor6<xcomplex<utype>> // xcomplex xtensor6 of gaussians
1230 gaussian(const xtensor6<xcomplex<utype>>& a, // real,imag (0,sigma1),(0,sigma2)
1231 const utype& sigma1,
1232 const utype& sigma2) {
1233 return gaussian(a, utype(0.0), sigma1, utype(0.0), sigma2);
1234 }
1235
1236 template <class utype>
1237 xtensor6<xcomplex<utype>> // xcomplex xtensor6 of gaussians
1238 gaussian(const xtensor6<xcomplex<utype>>& a, // real,imag (0,sigma),(0,sigma)
1239 const utype& sigma) {
1240 return gaussian(a, utype(0.0), sigma, utype(0.0), sigma);
1241 }
1242
1243 template <class utype>
1244 xtensor6<xcomplex<utype>> // xcomplex xtensor6 of gaussians
1245 gaussian(const xtensor6<xcomplex<utype>>& a) { // real,imag in (0,1),(0,1)
1246 return gaussian(a, utype(0.0), utype(1.0), utype(0.0), utype(1.0));
1247 }
1248} // namespace aurostd
1249
1250#endif
1251// ----------------------------------------------------------------------------
1252
1253// ----------------------------------------------------------------------------
1254// ----------------------------------------------------------------------------
1255#ifdef __XTENSOR7_CPP
1256
1257namespace aurostd {
1258 // namespace aurostd
1259 template <class utype>
1260 xtensor7<utype> // uniform xtensor7<utype> [x,y]
1261 uniform(const xtensor7<utype>& a, const utype& x, const utype& y) {
1262 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
1263 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
1264 for (int k = a.lindex[3]; k <= a.uindex[3]; k++)
1265 for (int l = a.lindex[4]; l <= a.uindex[4]; l++)
1266 for (int m = a.lindex[5]; m <= a.uindex[5]; m++)
1267 for (int n = a.lindex[6]; n <= a.uindex[6]; n++)
1268 for (int o = a.lindex[7]; o <= a.uindex[7]; o++) a[i][j][k][l][m][n][o] = (utype) x + (y - x) * uniform(utype(1.0));
1269 return a;
1270 }
1271
1272 template <class utype>
1273 xtensor7<utype> // uniform xtensor7<utype> [0,y]
1274 uniform(const xtensor7<utype>& a, const utype& y) {
1275 return uniform(a, utype(0.0), utype(y));
1276 }
1277
1278 template <class utype>
1279 xtensor7<utype> // uniform xtensor7<utype> [0,1]
1280 uniform(const xtensor7<utype>& a) {
1281 return uniform(a, utype(0.0), utype(1.0));
1282 }
1283
1284 template <class utype>
1285 xtensor7<xcomplex<utype>> // xcomplex xtensor7 of uniforms
1286 uniform(const xtensor7<xcomplex<utype>>& a, // real,imag in ([x1,y1],[x2,y2])
1287 const utype& x1,
1288 const utype& y1,
1289 const utype& x2,
1290 const utype& y2) {
1291 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
1292 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
1293 for (int k = a.lindex[3]; k <= a.uindex[3]; k++)
1294 for (int l = a.lindex[4]; l <= a.uindex[4]; l++)
1295 for (int m = a.lindex[5]; m <= a.uindex[5]; m++)
1296 for (int n = a.lindex[6]; n <= a.uindex[6]; n++)
1297 for (int o = a.lindex[7]; o <= a.uindex[7]; o++) a[i][j][k][l][m][n][o] = xcomplex<utype>(x1 + (y1 - x1) * uniform(utype(1.0)), x2 + (y2 - x2) * uniform(utype(1.0)));
1298 return a;
1299 }
1300
1301 template <class utype>
1302 xtensor7<xcomplex<utype>> // xcomplex xtensor7 of uniforms
1303 uniform(const xtensor7<xcomplex<utype>>& a, // real,imag in ([0,x],[0,y])
1304 const utype& x,
1305 const utype& y) {
1306 return uniform(a, utype(0.0), x, utype(0.0), y);
1307 }
1308
1309 template <class utype>
1310 xtensor7<xcomplex<utype>> // xcomplex xtensor7 of uniforms
1311 uniform(const xtensor7<xcomplex<utype>>& a, // real,imag in ([0,y],[0,y])
1312 const utype& y) {
1313 return uniform(a, utype(0.0), y, utype(0.0), y);
1314 }
1315
1316 template <class utype>
1317 xtensor7<xcomplex<utype>> // xcomplex xtensor7 of uniforms
1318 uniform(const xtensor7<xcomplex<utype>>& a) { // real,imag in ([0,1],[0,1])
1319 return uniform(a, utype(0.0), utype(1.0), utype(0.0), utype(1.0));
1320 }
1321} // namespace aurostd
1322
1323// ----------------------------------------------------- gaussian distributions
1324
1325namespace aurostd {
1326 // namespace aurostd
1327 template <class utype>
1328 xtensor7<utype> // gaussian xtensor7<utype> (m,sigma)
1329 gaussian(const xtensor7<utype>& a, const utype& m, const utype& sigma) {
1330 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
1331 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
1332 for (int k = a.lindex[3]; k <= a.uindex[3]; k++)
1333 for (int l = a.lindex[4]; l <= a.uindex[4]; l++)
1334 for (int m = a.lindex[5]; m <= a.uindex[5]; m++)
1335 for (int n = a.lindex[6]; n <= a.uindex[6]; n++)
1336 for (int o = a.lindex[7]; o <= a.uindex[7]; o++)
1337 // a[i][j][k][l][m][n][o]=(utype) (utype) m+sqrt(sigma)*gaussian();
1338 a[i][j][k][l][m][n][o] = (utype) (utype) m + sigma * gaussian();
1339 return a;
1340 }
1341
1342 template <class utype>
1343 xtensor7<utype> // gaussian xtensor7<utype> (m=0,sigma)
1344 gaussian(const xtensor7<utype>& a, const utype& sigma) {
1345 return gaussian(a, utype(0.0), utype(sigma));
1346 }
1347
1348 template <class utype>
1349 xtensor7<utype> // gaussian xtensor7<utype> (m=0,sigma=1)
1350 gaussian(const xtensor7<utype>& a) {
1351 return gaussian(a, utype(0.0), utype(1.0));
1352 }
1353
1354 template <class utype>
1355 xtensor7<xcomplex<utype>> // xcomplex xtensor7 of gaussians
1356 gaussian(const xtensor7<xcomplex<utype>>& a, // real,imag(m1,sigma1),(m2,sigma2)
1357 const utype& m1,
1358 const utype& sigma1,
1359 const utype& m2,
1360 const utype& sigma2) {
1361 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
1362 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
1363 for (int k = a.lindex[3]; k <= a.uindex[3]; k++)
1364 for (int l = a.lindex[4]; l <= a.uindex[4]; l++)
1365 for (int m = a.lindex[5]; m <= a.uindex[5]; m++)
1366 for (int n = a.lindex[6]; n <= a.uindex[6]; n++)
1367 for (int o = a.lindex[7]; o <= a.uindex[7]; o++)
1368 // a[i][j][k][l][m][n][o]=xcomplex<utype>(m1+sqrt(sigma1)*gaussian(),
1369 // m2+sqrt(sigma2)*gaussian());
1370 a[i][j][k][l][m][n][o] = xcomplex<utype>(m1 + sigma1 * gaussian(), m2 + sigma2 * gaussian());
1371 return a;
1372 }
1373
1374 template <class utype>
1375 xtensor7<xcomplex<utype>> // xcomplex xtensor7 of gaussians
1376 gaussian(const xtensor7<xcomplex<utype>>& a, // real,imag (0,sigma1),(0,sigma2)
1377 const utype& sigma1,
1378 const utype& sigma2) {
1379 return gaussian(a, utype(0.0), sigma1, utype(0.0), sigma2);
1380 }
1381
1382 template <class utype>
1383 xtensor7<xcomplex<utype>> // xcomplex xtensor7 of gaussians
1384 gaussian(const xtensor7<xcomplex<utype>>& a, // real,imag (0,sigma),(0,sigma)
1385 const utype& sigma) {
1386 return gaussian(a, utype(0.0), sigma, utype(0.0), sigma);
1387 }
1388
1389 template <class utype>
1390 xtensor7<xcomplex<utype>> // xcomplex xtensor7 of gaussians
1391 gaussian(const xtensor7<xcomplex<utype>>& a) { // real,imag in (0,1),(0,1)
1392 return gaussian(a, utype(0.0), utype(1.0), utype(0.0), utype(1.0));
1393 }
1394} // namespace aurostd
1395
1396#endif
1397// ----------------------------------------------------------------------------
1398
1399// ----------------------------------------------------------------------------
1400// ----------------------------------------------------------------------------
1401#ifdef __XTENSOR8_CPP
1402
1403namespace aurostd {
1404 // namespace aurostd
1405 template <class utype>
1406 xtensor8<utype> // uniform xtensor8<utype> [x,y]
1407 uniform(const xtensor8<utype>& a, const utype& x, const utype& y) {
1408 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
1409 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
1410 for (int k = a.lindex[3]; k <= a.uindex[3]; k++)
1411 for (int l = a.lindex[4]; l <= a.uindex[4]; l++)
1412 for (int m = a.lindex[5]; m <= a.uindex[5]; m++)
1413 for (int n = a.lindex[6]; n <= a.uindex[6]; n++)
1414 for (int o = a.lindex[7]; o <= a.uindex[7]; o++)
1415 for (int p = a.lindex[8]; p <= a.uindex[8]; p++) a[i][j][k][l][m][n][o][p] = (utype) x + (y - x) * uniform(utype(1.0));
1416 return a;
1417 }
1418
1419 template <class utype>
1420 xtensor8<utype> // uniform xtensor8<utype> [0,y]
1421 uniform(const xtensor8<utype>& a, const utype& y) {
1422 return uniform(a, utype(0.0), utype(y));
1423 }
1424
1425 template <class utype>
1426 xtensor8<utype> // uniform xtensor8<utype> [0,1]
1427 uniform(const xtensor8<utype>& a) {
1428 return uniform(a, utype(0.0), utype(1.0));
1429 }
1430
1431 template <class utype>
1432 xtensor8<xcomplex<utype>> // xcomplex xtensor8 of uniforms
1433 uniform(const xtensor8<xcomplex<utype>>& a, // real,imag in ([x1,y1],[x2,y2])
1434 const utype& x1,
1435 const utype& y1,
1436 const utype& x2,
1437 const utype& y2) {
1438 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
1439 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
1440 for (int k = a.lindex[3]; k <= a.uindex[3]; k++)
1441 for (int l = a.lindex[4]; l <= a.uindex[4]; l++)
1442 for (int m = a.lindex[5]; m <= a.uindex[5]; m++)
1443 for (int n = a.lindex[6]; n <= a.uindex[6]; n++)
1444 for (int o = a.lindex[7]; o <= a.uindex[7]; o++)
1445 for (int p = a.lindex[8]; p <= a.uindex[8]; p++) a[i][j][k][l][m][n][o][p] = xcomplex<utype>(x1 + (y1 - x1) * uniform(utype(1.0)), x2 + (y2 - x2) * uniform(utype(1.0)));
1446 return a;
1447 }
1448
1449 template <class utype>
1450 xtensor8<xcomplex<utype>> // xcomplex xtensor8 of uniforms
1451 uniform(const xtensor8<xcomplex<utype>>& a, // real,imag in ([0,x],[0,y])
1452 const utype& x,
1453 const utype& y) {
1454 return uniform(a, utype(0.0), x, utype(0.0), y);
1455 }
1456
1457 template <class utype>
1458 xtensor8<xcomplex<utype>> // xcomplex xtensor8 of uniforms
1459 uniform(const xtensor8<xcomplex<utype>>& a, // real,imag in ([0,y],[0,y])
1460 const utype& y) {
1461 return uniform(a, utype(0.0), y, utype(0.0), y);
1462 }
1463
1464 template <class utype>
1465 xtensor8<xcomplex<utype>> // xcomplex xtensor8 of uniforms
1466 uniform(const xtensor8<xcomplex<utype>>& a) { // real,imag in ([0,1],[0,1])
1467 return uniform(a, utype(0.0), utype(1.0), utype(0.0), utype(1.0));
1468 }
1469} // namespace aurostd
1470
1471// ----------------------------------------------------- gaussian distributions
1472
1473namespace aurostd {
1474 // namespace aurostd
1475 template <class utype>
1476 xtensor8<utype> // gaussian xtensor8<utype> (m,sigma)
1477 gaussian(const xtensor8<utype>& a, const utype& m, const utype& sigma) {
1478 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
1479 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
1480 for (int k = a.lindex[3]; k <= a.uindex[3]; k++)
1481 for (int l = a.lindex[4]; l <= a.uindex[4]; l++)
1482 for (int m = a.lindex[5]; m <= a.uindex[5]; m++)
1483 for (int n = a.lindex[6]; n <= a.uindex[6]; n++)
1484 for (int o = a.lindex[7]; o <= a.uindex[7]; o++)
1485 for (int p = a.lindex[8]; p <= a.uindex[8]; p++)
1486 // a[i][j][k][l][m][n][o][p]=(utype) (utype) m+sqrt(sigma)*gaussian();
1487 a[i][j][k][l][m][n][o][p] = (utype) (utype) m + sigma * gaussian();
1488 return a;
1489 }
1490
1491 template <class utype>
1492 xtensor8<utype> // gaussian xtensor8<utype> (m=0,sigma)
1493 gaussian(const xtensor8<utype>& a, const utype& sigma) {
1494 return gaussian(a, utype(0.0), utype(sigma));
1495 }
1496
1497 template <class utype>
1498 xtensor8<utype> // gaussian xtensor8<utype> (m=0,sigma=1)
1499 gaussian(const xtensor8<utype>& a) {
1500 return gaussian(a, utype(0.0), utype(1.0));
1501 }
1502
1503 template <class utype>
1504 xtensor8<xcomplex<utype>> // xcomplex xtensor8 of gaussians
1505 gaussian(const xtensor8<xcomplex<utype>>& a, // real,imag(m1,sigma1),(m2,sigma2)
1506 const utype& m1,
1507 const utype& sigma1,
1508 const utype& m2,
1509 const utype& sigma2) {
1510 for (int i = a.lindex[1]; i <= a.uindex[1]; i++)
1511 for (int j = a.lindex[2]; j <= a.uindex[2]; j++)
1512 for (int k = a.lindex[3]; k <= a.uindex[3]; k++)
1513 for (int l = a.lindex[4]; l <= a.uindex[4]; l++)
1514 for (int m = a.lindex[5]; m <= a.uindex[5]; m++)
1515 for (int n = a.lindex[6]; n <= a.uindex[6]; n++)
1516 for (int o = a.lindex[7]; o <= a.uindex[7]; o++)
1517 for (int p = a.lindex[8]; p <= a.uindex[8]; p++)
1518 // a[i][j][k][l][m][n][o][p]=xcomplex<utype>(m1+sqrt(sigma1)*gaussian(),
1519 // m2+sqrt(sigma2)*gaussian());
1520 a[i][j][k][l][m][n][o][p] = xcomplex<utype>(m1 + sigma1 * gaussian(), m2 + sigma2 * gaussian());
1521 return a;
1522 }
1523
1524 template <class utype>
1525 xtensor8<xcomplex<utype>> // xcomplex xtensor8 of gaussians
1526 gaussian(const xtensor8<xcomplex<utype>>& a, // real,imag (0,sigma1),(0,sigma2)
1527 const utype& sigma1,
1528 const utype& sigma2) {
1529 return gaussian(a, utype(0.0), sigma1, utype(0.0), sigma2);
1530 }
1531
1532 template <class utype>
1533 xtensor8<xcomplex<utype>> // xcomplex xtensor8 of gaussians
1534 gaussian(const xtensor8<xcomplex<utype>>& a, // real,imag (0,sigma),(0,sigma)
1535 const utype& sigma) {
1536 return gaussian(a, utype(0.0), sigma, utype(0.0), sigma);
1537 }
1538
1539 template <class utype>
1540 xtensor8<xcomplex<utype>> // xcomplex xtensor8 of gaussians
1541 gaussian(const xtensor8<xcomplex<utype>>& a) { // real,imag in (0,1),(0,1)
1542 return gaussian(a, utype(0.0), utype(1.0), utype(0.0), utype(1.0));
1543 }
1544} // namespace aurostd
1545
1546#endif
1547
1548// ----------------------------------------------------------------------------
1549
1550#endif // _AUROSTD_XRANDOM_IMPLEMENTATIONS_
1551
1552// **************************************************************************
1553// * *
1554// * STEFANO CURTAROLO - Duke University 2003-2024 *
1555// * *
1556// **************************************************************************
This file contains the preprocessor macros to ensure a proper instantiation of all aurostd functions.
#define AST_GEN_1(type_selection)
autogenerate 1D code based on AST_TEMPLATE
#define AST_UTYPE_NUM
#define _AUROSTD_XRANDOM_RAN1_IA
#define _AUROSTD_XRANDOM_RAN2_IA1
#define _AUROSTD_XRANDOM_RAN1_RNMX
#define _AUROSTD_XRANDOM_RAN3_MBIG
#define _AUROSTD_XRANDOM_RAN2_IA2
#define _AUROSTD_XRANDOM_RAN2_IMM1
#define _AUROSTD_XRANDOM_RAN0_IQ
#define _AUROSTD_XRANDOM_RAN0_IR
#define _AUROSTD_XRANDOM_RAN2_IQ1
#define _AUROSTD_XRANDOM_RAN2_NTAB
#define _AUROSTD_XRANDOM_RAN2_AM
#define _AUROSTD_XRANDOM_RAN0_AM
#define _AUROSTD_XRANDOM_RAN0_MASK
#define _AUROSTD_XRANDOM_RAN1_IM
#define _AUROSTD_XRANDOM_RAN1_AM
#define _AUROSTD_XRANDOM_RAN2_IR1
#define _AUROSTD_XRANDOM_RAN0_IA
#define _AUROSTD_XRANDOM_RAN2_IM1
#define _AUROSTD_XRANDOM_RAN2_IR2
static long int _idum[1]
#define _AUROSTD_XRANDOM_RAN1_IQ
#define _AUROSTD_XRANDOM_RAN2_RNMX
#define _AUROSTD_XRANDOM_RAN1_NTAB
#define _AUROSTD_XRANDOM_RAN3_MZ
#define _AUROSTD_XRANDOM_RAN3_MSEED
#define _AUROSTD_XRANDOM_RAN0_IM
#define _AUROSTD_XRANDOM_RAN1_IR
#define _AUROSTD_XRANDOM_RAN2_NDIV
#define _AUROSTD_XRANDOM_RAN2_IQ2
#define _AUROSTD_XRANDOM_RAN2_IM2
#define _AUROSTD_XRANDOM_RAN3_FAC
double expdev()
utype uniform(const utype &x)
double gaussian()
double ran0()
utype mean(const vector< utype > vec)
unsigned long long int getTID()
double ran2()
double ran3()
double laplacedev()
xcomplex< utype > log(const xcomplex< utype > &x)
long int _random_initialize()
double ran1()