AFLOW
 
Loading...
Searching...
No Matches
aurostd_xvector.h
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-2011
7
8#ifndef _AUROSTD_XVECTOR_H_
9#define _AUROSTD_XVECTOR_H_
10
11#include <deque>
12#include <functional>
13#include <initializer_list>
14#include <ostream>
15#include <string>
16#include <vector>
17
18#include <sys/types.h>
19
20#include "aurostd_defs.h"
21#include "aurostd_xcomplex.h"
22
23#define _AUROSTD_XVECTOR_DEFAULT_SIZE_ 3
24
25#define BOUNDARY_CONDITIONS_NONE 0
26#define BOUNDARY_CONDITIONS_PERIODIC 1
27
28#define _AUROSTD_XVECTOR_TOLERANCE_IDENTITY_ AUROSTD_IDENTITY_TOL // 1.0e-6
29#define _AUROSTD_XVECTOR_TOLERANCE_ROUNDOFF_ AUROSTD_ROUNDOFF_TOL // 1.0e-6
30
31#define CONV_SHAPE_FULL 0 // CO20190520
32#define CONV_SHAPE_SAME 1 // CO20190520
33#define CONV_SHAPE_VALID 2 // CO20190520
34
35// -------------------------------------------------------------- class xvector
36
37namespace aurostd {
38 template <class utype> class xmatrix; // forward declaration //CO20191110
39 // namespace aurostd
40 template <class utype> class xvector {
41 public:
42 // xvector(); // default constructor
43 // xvector(int); // default constructor
44 xvector(int = 3, int = 1); // default constructor
45 xvector(const std::initializer_list<utype>); // initializer_list constructor //HE20220616
46 xvector(const xvector<utype>&); // copy constructor
47 xvector(const xmatrix<utype>&); // copy constructor //CO20191110
48 // xvector (const xmatrix<utype>&); // make a vector of a xmatrix
49 xvector<utype>& operator=(const xvector<utype>&); // assignment
50 xvector<utype>& operator=(const std::initializer_list<utype>); // initializer_list assignment //HE20220616
51 // operator xvector<utype>() { return *this;}; // IBM_CPP
52 ~xvector(); // default destructor
53 utype& operator[](int) const; // indicize
54 utype& operator()(int) const; // indicize
55 utype& operator()(int, bool) const; // indicize boundary conditions
57 xvector<utype>& operator+=(const std::initializer_list<utype>); // HE20220616
58 xvector<utype>& operator+=(utype); // CO20180409
60 xvector<utype>& operator-=(utype); // CO20180409
61 xvector<utype>& operator-=(const std::initializer_list<utype>); // HE20220616
62 xvector<utype>& operator*=(utype r); //(const utype& r) //CO20171130 - v*=v[1] doesn't work //CO20180409
63 xvector<utype>& operator/=(utype r); //(const utype& r) //CO20171130 - v/=v[1] doesn't work //CO20180409
64 // xvector<utype>& operator *=(const xvector<utype>&);
65 // xvector<utype>& operator /=(const xvector<utype>&);
66 // friend std::ostream& operator<<<utype>(std::ostream&,const xvector<utype>&);
67 // friend std::ostream& operator< <utype>(std::ostream&,const xvector<utype>&);
70 // operations
71 void set(const utype&);
72 void reset();
73 void clear();
74 void null(); // CO20200731 - to create null vector
75 void resize(int = 3, int nl = 1); // CO20201111
76 // HE20220915 START
77 // xvector manipulation without copy (pointer manipulation)
78 void shift(int new_lrows);
79 // HE20220915 END
80 private:
81 utype* corpus;
82 // bool isfloat,iscomplex;
83 char size;
84 long int vsize;
85 typedef typename std::initializer_list<utype>::const_iterator ili; // initializer list iterator //HE20220616
86
87 // NECESSARY PRIVATE CLASS METHODS - START
88 void init(); // HE20220515
89 void free(); // CO20190808
90 void copy(const xvector<utype>& b); // CO20190808
91 void copy(const xmatrix<utype>& b); // CO20190808
92 void copy(const std::initializer_list<utype> l); // HE20220616
93 void refresh(); // CO20190808 - refresh internal properties dependent on lrows, urows, utype
94
95 // NECESSARY END CLASS METHODS - END
96 };
97} // namespace aurostd
98
99// ----------------------------------------------------------------------------
100// ------------------------- primitives for template<class utype> xvector<utype>
101
102// ----------------------------------------------------------------------------
103// ------------------------------------------------- unary and binary operators
104
105namespace aurostd {
106 // namespace aurostd
107 // template<class utype> std::ostream& operator<<(std::ostream&,const xvector<utype>&);
108
109 template <class utype> std::ostream& operator<<(std::ostream&, const xvector<utype>&) __xprototype;
110
111 template <class utype> xvector<utype> operator+(const xvector<utype>&) __xprototype;
112
113 template <class utype> xvector<utype> operator-(const xvector<utype>&) __xprototype;
114
115 template <class utype> xvector<utype> operator+(const xvector<utype>&, const xvector<utype>&) __xprototype;
116
117 template <class utype> xvector<utype> operator-(const xvector<utype>&, const xvector<utype>&) __xprototype;
118
119 template <class utype> xvector<utype> operator%(const xvector<utype>&, const xvector<utype>&) __xprototype;
120
121 template <class utype> xvector<utype> operator+(const utype, const xvector<utype>&) __xprototype;
122
123 template <class utype> xvector<utype> operator+(const xvector<utype>&, const utype) __xprototype;
124
125 template <class utype, class stype> xvector<utype> operator+(const stype, const xvector<utype>&) __xprototype;
126
127 template <class utype, class stype> xvector<utype> operator+(const xvector<utype>&, const stype) __xprototype;
128
129 template <class utype> xvector<utype> operator-(const utype, const xvector<utype>&) __xprototype;
130
131 template <class utype> xvector<utype> operator-(const xvector<utype>&, const utype) __xprototype;
132
133 template <class utype, class stype> xvector<utype> operator-(const stype, const xvector<utype>&) __xprototype;
134
135 template <class utype, class stype> xvector<utype> operator-(const xvector<utype>&, const stype) __xprototype;
136
137 template <class utype> xvector<utype> operator*(const utype, const xvector<utype>&) __xprototype;
138
139 template <class utype> xvector<utype> operator*(const xvector<utype>&, const utype) __xprototype;
140
141 template <class utype, class stype> xvector<utype> operator*(const stype, const xvector<utype>&) __xprototype;
142
143 template <class utype, class stype> xvector<utype> operator*(const xvector<utype>&, const stype) __xprototype;
144
145 template <class utype> xvector<utype> operator/(const utype, const xvector<utype>&) __xprototype;
146
147 template <class utype> xvector<utype> operator/(const xvector<utype>&, const utype) __xprototype;
148
149 template <class utype, class stype> xvector<utype> operator/(const stype, const xvector<utype>&) __xprototype;
150
151 template <class utype, class stype> xvector<utype> operator/(const xvector<utype>&, const stype) __xprototype;
152
153 // ME20200329 - real * complex vector
154 template <class utype> xvector<xcomplex<utype>> operator*(utype, const xvector<xcomplex<utype>>&);
155
156 template <class utype> xvector<xcomplex<utype>> operator*(const xvector<xcomplex<utype>>&, utype);
157
158 template <class utype> xvector<xcomplex<utype>> operator/(const xvector<xcomplex<utype>>&, utype);
159
160 template <class utype> xvector<utype> operator<<(const xvector<utype>&, const xvector<utype>&) __xprototype;
161
162 template <class utype> xvector<utype> operator<<(const xvector<utype>&, const utype) __xprototype;
163
164 template <class utype> xvector<utype> operator<<(const utype, const xvector<utype>&) __xprototype;
165
166 template <class utype> utype operator*(const xvector<utype>&, const xvector<utype>&) __xprototype;
167
168 template <class utype> utype scalar_product(const xvector<utype>&, const xvector<utype>&) __xprototype;
169
170 template <class utype> xvector<utype> vector_product(const xvector<utype>&, const xvector<utype>&) __xprototype;
171
172 template <class utype> xvector<utype> elementwise_product(const xvector<utype>&, const xvector<utype>&) __xprototype; // SD20220422
173
174 template <class utype> utype elements_product(const xvector<utype>&) __xprototype; // SD20220617
175
176 // ME20200327
177 template <class utype> xmatrix<utype> outer_product(const xvector<utype>&, const xvector<utype>&) __xprototype;
178
179 template <class utype>
180 xvector<char> // is xvector > scalar ?
181 operator>(const xvector<utype>&, const utype&) __xprototype;
182
183 template <class utype>
184 xvector<char> // is xvector < scalar ?
185 operator<(const xvector<utype>&, const utype&) __xprototype;
186
187 template <class utype>
188 xvector<char> // is xvector == scalar ?
189 operator==(const xvector<utype>&, const utype&) __xprototype;
190
191 template <class utype>
192 xvector<char> // is xvector > xvector ?
194
195 template <class utype>
196 xvector<char> // is xvector < xvector ?
198
199 template <class utype> bool identical(const xvector<utype>&, const xvector<utype>&, const utype&) __xprototype;
200
201 template <class utype> bool identical(const xvector<xcomplex<utype>>&, const xvector<xcomplex<utype>>&, const utype&) __xprototype;
202
203 template <class utype> bool identical(const xvector<utype>&, utype tol = (utype) _AUROSTD_XVECTOR_TOLERANCE_IDENTITY_) __xprototype; // DX20210503
204
205 template <class utype> bool identical(const xvector<xcomplex<utype>>&, utype tol = (utype) _AUROSTD_XVECTOR_TOLERANCE_IDENTITY_) __xprototype; // DX20210503
206
207 template <class utype> bool identical(const xvector<utype>&, const xvector<utype>&) __xprototype;
208
209 template <class utype> bool identical(const xvector<xcomplex<utype>>&, const xvector<xcomplex<utype>>&) __xprototype;
210
211 template <class utype> bool operator==(const xvector<utype>&, const xvector<utype>&) __xprototype;
212
213 template <class utype> bool isdifferent(const xvector<utype>&, const xvector<utype>&, const utype&) __xprototype;
214
215 template <class utype> bool isdifferent(const xvector<utype>&, const xvector<utype>&) __xprototype;
216
217 template <class utype> bool isequal(const xvector<utype>&, const xvector<utype>&, const utype&) __xprototype;
218
219 template <class utype> bool isequal(const xvector<utype>&, const xvector<utype>&) __xprototype;
220
221 template <class utype> bool isequal(const xvector<xcomplex<utype>>&, const xvector<xcomplex<utype>>&) __xprototype;
222
223 template <class utype> bool operator!=(const xvector<utype>&, const xvector<utype>&) __xprototype;
224
225 template <class utype> bool isinteger(const xvector<utype>&, const utype& tol = (utype) 0.01) __xprototype; // CO20180409
226
227 template <class utype>
228 bool iszero(const xvector<utype>&, double tol = (double) _AUROSTD_XVECTOR_TOLERANCE_IDENTITY_) __xprototype; // ME20180702 //CO20191201 - 1e-7 seems arbitrary //CO20230313 - utype clang warnings
229
230} // namespace aurostd
231
232// ----------------------------------------------------------- xvector example types
233namespace aurostd {
234 // CO20180419
235 template <class utype> xvector<utype> null_xv() __xprototype; // CO20200731 - friend so it can access refresh()
236 template <class utype> xvector<utype> ones_xv(int = 3, int = 1) __xprototype;
237 template <class utype> xvector<utype> box_filter_xv(int window, int lrows = 1) __xprototype;
238 template <class utype> int gaussian_filter_get_window(utype sigma) __xprototype; // CO20220627
239 template <class utype> xvector<utype> gaussian_filter_xv(utype sigma) __xprototype; // if you need lrows!=1, use shift()
240 template <class utype> xvector<utype> gaussian_filter_xv(utype sigma, int window, int lrows = 1) __xprototype; // CO20190419
241} // namespace aurostd
242
243namespace aurostd {
244
245 // CAST ON XVECTORS
246
247 template <class utype> xvector<long double> xlongdouble(const xvector<utype>&) __xprototype;
248
249 template <class utype> xvector<double> xdouble(const xvector<utype>&) __xprototype;
250
251 template <class utype> xvector<utype> mod(const xvector<utype>&, utype d) __xprototype; // CO20200127
252
253 template <class utype> xvector<utype> mod_floored(const xvector<utype>&, utype d) __xprototype; // SD20220117
254
255 template <class utype> xvector<double> floor(const xvector<utype>&) __xprototype;
256
257 template <class utype> xvector<double> ceil(const xvector<utype>&) __xprototype;
258
259 template <class utype> xvector<double> round(const xvector<utype>&) __xprototype;
260
261 template <class utype> xvector<double> trunc(const xvector<utype>&) __xprototype;
262
263 template <class utype> xvector<float> xfloat(const xvector<utype>&) __xprototype;
264
265 template <class utype> xvector<utype> pow(const xvector<utype>&, const utype d) __xprototype; // SD20220324
266
267 template <class utype> xvector<utype> pow(const xvector<utype>&, const xvector<utype>&) __xprototype; // SD20220324
268
269 template <class utype> xvector<long int> xlongint(const xvector<utype>&) __xprototype;
270
271 template <class utype> xvector<int> xint(const xvector<utype>&) __xprototype;
272
273 template <class utype> xvector<char> xchar(const xvector<utype>&) __xprototype;
274
275 template <class utype> std::vector<utype> xvector2vector(const xvector<utype>&) __xprototype;
276
277 template <class utype> xvector<utype> vector2xvector(const std::vector<utype>&, int lrows = 1) __xprototype; // CO20180409
278 template <class utype> xvector<utype> vector2xvector(const std::vector<std::string>&, int lrows = 1) __xprototype; // CO20180409
279
280 template <class out_type, class in_type> xvector<out_type> xvector2utype(const xvector<in_type>& in_vec) __xprototype;
281 ; // HE20220906
282 // OPERATIONS ON XVECTORS
283
284 template <class utype> void set(xvector<utype>&, const utype&) __xprototype;
285
286 template <class utype> void reset(xvector<utype>&) __xprototype;
287
288 template <class utype> void clear(xvector<utype>&) __xprototype;
289
290 template <class utype> xvector<utype> vabs(const xvector<utype>&) __xprototype;
291
292 template <class utype> xvector<utype> abs(const xvector<utype>&) __xprototype;
293
294 template <class utype> xvector<utype> sign(const xvector<utype>&) __xprototype;
295
296 template <class utype> xvector<utype> nint(const xvector<utype>&) __xprototype;
297
298 template <class utype> utype modulus(const xvector<utype>&) __xprototype;
299
300 template <class utype> utype modulussquare(const xvector<utype>&) __xprototype;
301
302 template <class utype> utype modulus2(const xvector<utype>&) __xprototype;
303
304 template <class utype> utype sum(const xvector<utype>&) __xprototype;
305
306 template <class utype> utype min(const xvector<utype>&) __xprototype;
307
308 template <class utype> utype min(const xvector<utype>&, int&) __xprototype;
309
310 template <class utype> int mini(const xvector<utype>&) __xprototype;
311
312 template <class utype> utype max(const xvector<utype>&) __xprototype;
313
314 template <class utype> utype max(const xvector<utype>&, int&) __xprototype;
315
316 template <class utype> int maxi(const xvector<utype>&) __xprototype;
317
318 template <class utype>
319 xvector<utype> // clear values too small
320 roundoff(const xvector<utype>&, utype tol = (utype) _AUROSTD_XVECTOR_TOLERANCE_ROUNDOFF_) __xprototype; // claar values too small //CO20180409
321
322 void GCD(const xvector<int>&, int&); // get GCD of xvector //CO20180409 //CO20191201
323 void GCD(const xvector<int>& va, const xvector<int>& vb, xvector<int>& vgcd); // CO20191201
324 void GCD(const xvector<int>& va, const xvector<int>& vb, xvector<int>& vgcd, xvector<int>& vx, xvector<int>& vy); // CO20191201
325 int LCM(const xvector<int>&); // get LCM of xvector //CO20180520
326
327 template <class utype>
328 void reduceByGCD(const xvector<utype>& in_V, // simply divide by GCD (useful for compounds) //CO20180409
329 xvector<utype>& out_V, // simply divide by GCD (useful for compounds) //CO20180409
330 utype tol = (utype) _AUROSTD_XVECTOR_TOLERANCE_IDENTITY_) __xprototype; // simply divide by GCD (useful for compounds) //CO20180409 //CO20191201
331
332 void GCD(const std::vector<int>&, int&); // get GCD of vector //DX20191125 (modeled after CO's xvector version) //CO20191201
333 int LCM(const std::vector<int>&); // get LCM of vector //DX20191125 (modeled after CO's xvector version)
334
335 template <class utype>
336 void reduceByGCD(const std::vector<utype>& in_V, // simply divide by GCD (useful for compounds) //DX20191125 (modeled after CO's xvector version)
337 std::vector<utype>& out_V, // simply divide by GCD (useful for compounds) //DX20191125 (modeled after CO's xvector version)
338 utype tol = (utype) _AUROSTD_XVECTOR_TOLERANCE_IDENTITY_) __xprototype; // simply divide by GCD (useful for compounds) //DX20191125 (modeled after CO's xvector version) //CO20191201
339
340 void GCD(const std::deque<int>&, int& gcd); // get GCD of deque //DX20191125 (modeled after CO's xvector version) //CO20191201
341 int LCM(const std::deque<int>&); // get LCM of deque //DX20191125 (modeled after CO's xvector version)
342
343 template <class utype>
344 void reduceByGCD(const std::deque<utype>& in_V, // simply divide by GCD (useful for compounds) //DX20191125 (modeled after CO's xvector version)
345 std::deque<utype>& out_V, // simply divide by GCD (useful for compounds) //DX20191125 (modeled after CO's xvector version)
346 utype tol = (utype) _AUROSTD_XVECTOR_TOLERANCE_IDENTITY_) __xprototype; // simply divide by GCD (useful for compounds) //DX20191125 (modeled after CO's xvector version) //CO20191201
347
348 template <class utype> xvector<utype> normalizeSumToOne(const xvector<utype>& in_V,
349 const utype& tol = (utype) _AUROSTD_XVECTOR_TOLERANCE_ROUNDOFF_) __xprototype; // CO20180801
350
351 template <class utype>
352 void // swap
353 swap(xvector<utype>&, const int&, const int&) __xprototype; // swap
354
355 // Complex operations
356 template <class utype> xvector<utype> conj(const xvector<utype>&) __xprototype;
357
358 // EXPONENTIAL OPERATIONS
359
360 template <class utype> xvector<utype> exp(const xvector<utype>&) __xprototype;
361
362 template <class utype> xvector<utype> log(const xvector<utype>&) __xprototype;
363
364 template <class utype> xvector<utype> log10(const xvector<utype>&) __xprototype;
365
366 // TRIDIMENSIONAL OPERATIONS
367
368 template <class utype> utype distance(const xvector<utype>&, const xvector<utype>&) __xprototype;
369
370 // TRIGONOMETRIC OPERATIONS
371
372 template <class utype> xvector<utype> sin(const xvector<utype>&) __xprototype;
373
374 template <class utype> xvector<utype> cos(const xvector<utype>&) __xprototype;
375
376 template <class utype> xvector<utype> asin(const xvector<utype>&) __xprototype;
377
378 template <class utype> xvector<utype> acos(const xvector<utype>&) __xprototype;
379
380 template <class utype> xvector<utype> tan(const xvector<utype>&) __xprototype;
381
382 template <class utype> xvector<utype> atan(const xvector<utype>&) __xprototype;
383
384 template <class utype> xvector<utype> sec(const xvector<utype>&) __xprototype;
385
386 template <class utype> xvector<utype> cosec(const xvector<utype>&) __xprototype;
387
388 // HYPERBOLIC TRIGONOMETRIC OPERATIONS
389
390 template <class utype> xvector<utype> sinh(const xvector<utype>&) __xprototype;
391
392 template <class utype> xvector<utype> asinh(const xvector<utype>&) __xprototype;
393
394 template <class utype> xvector<utype> cosh(const xvector<utype>&) __xprototype;
395
396 template <class utype> xvector<utype> acosh(const xvector<utype>&) __xprototype;
397
398 template <class utype> xvector<utype> tanh(const xvector<utype>&) __xprototype;
399
400 template <class utype> xvector<utype> atanh(const xvector<utype>&) __xprototype;
401
402 template <class utype> xvector<utype> cotanh(const xvector<utype>&) __xprototype;
403
404 template <class utype> xvector<utype> acotanh(const xvector<utype>&) __xprototype;
405
406 template <class utype> xvector<utype> sech(const xvector<utype>&) __xprototype;
407
408 template <class utype> xvector<utype> cosech(const xvector<utype>&) __xprototype;
409
410 // TRIGONOMETRIC OPERATIONS BETWEEN TWO VECTORS
411
412 template <class utype>
413 double // cos of angle between two vectors
414 cos(const xvector<utype>&, const xvector<utype>&) __xprototype;
415 template <class utype>
416 double // cos of angle between two vectors
417 getcos(const xvector<utype>&, const xvector<utype>&) __xprototype;
418
419 template <class utype>
420 double // sin of angle between two vectors
421 sin(const xvector<utype>&, const xvector<utype>&) __xprototype;
422 template <class utype>
423 double // sin of angle between two vectors
424 getsin(const xvector<utype>&, const xvector<utype>&) __xprototype;
425
426 template <class utype>
427 double // angle between two vectors in radiants
428 angle(const xvector<utype>&, const xvector<utype>&) __xprototype;
429 template <class utype>
430 double // angle between two vectors in radiants
431 getangle(const xvector<utype>&, const xvector<utype>&) __xprototype;
432
433 template <class utype>
434 double // angle between three vectors in radiants
435 angle(const xvector<utype>&, const xvector<utype>&, const xvector<utype>&) __xprototype;
436 template <class utype>
437 double // angle between three vectors in radiants
438 getangle(const xvector<utype>&, const xvector<utype>&, const xvector<utype>&) __xprototype;
439
440 template <class utype>
441 bool // determine if two vectors are collinear //CO20180409
442 isCollinear(const xvector<utype>& v0, const xvector<utype>& v1, const utype& tol = _AUROSTD_XVECTOR_TOLERANCE_IDENTITY_) __xprototype;
443
444 template <class utype>
445 double // area encapsulated by ordered points (on the same plane) //HE20210511
446 areaPointsOnPlane(const std::vector<xvector<utype>>& points) __xprototype;
447 template <class utype>
448 xvector<uint> // return vertex indexes based on their angle around a central normal vector //HE20220523
449 sortPolygonVertices(const std::vector<xvector<utype>>& points, const xvector<utype>& normal);
450 template <class utype>
451 void// HE20220916
452 sortPolyhedronFacets(const std::vector<xvector<utype>>& points, std::vector<std::vector<uint>>& facets, std::vector<xvector<utype>>& normals);
453 template <class utype>
454 double // volume defined by points, facets and all outward or inward facing normals (needs to be consistent) //HE20210511
455 volume(const std::vector<xvector<utype>>& points, const std::vector<std::vector<uint>>& facets, const std::vector<xvector<utype>>& normals) __xprototype;
456 double // volume defined by points and ordered facets //HE20210511
457 volume(const std::vector<xvector<int>>& points, const std::vector<std::vector<uint>>& facets, bool convex = false);
458 template <class utype>
459 double // volume defined by points and ordered facets //HE20210511
460 volume(const std::vector<xvector<utype>>& points, const std::vector<std::vector<uint>>& facets, bool convex = false) __xprototype;
461
462 template <class utype>
463 double // numerical integration over a convex 3D solid //HE20220906
464 convex_volume_integral(const std::vector<xvector<utype>>& points, const std::vector<std::vector<uint>>& facets, const std::function<double(const xvector<double>& point)>& func);
465 template <class utype>
466 double // numerical integration over a convex 3D solid //HE20220906
467 convex_volume_integral_triangle(const std::vector<xvector<utype>>& points, const std::vector<std::vector<uint>>& facets, const std::function<double(const xvector<double>& point)>& func);
468 template <class utype>
469 double // numerical integration over a tetrahedron //HE20220906
470 tetrahedron_integral(const std::vector<xvector<utype>>& points, const std::function<double(const xvector<double>& point)>& func);
471
472 template <class utype>
473 xvector<utype> // get centroid of data points //CO20180409
474 getCentroid(const std::vector<xvector<utype>>& points) __xprototype;
475 template <class utype>
476 xvector<utype> // get centroid of data points with weights //DX20200728
477 getCentroid(const std::vector<xvector<utype>>& points, const std::vector<utype>& weights) __xprototype;
478
479 template <class utype>
480 xvector<double> // get centroid of data points //CO20180409
481 getCentroidPBC(const std::vector<xvector<utype>>& points, const xmatrix<utype>& lattice) __xprototype;
482 template <class utype>
483 xvector<double> // get centroid of data points with weights //DX20200728
484 getCentroidPBC(const std::vector<xvector<utype>>& points, const std::vector<utype>& weights, const xmatrix<utype>& lattice) __xprototype;
485
486 // TRIGONOMETRIC OPERATIONS BETWEEN TWO GENERAL VECTORS //CO20180409
487 template <class utype> xvector<double> getGeneralAngles(const xvector<utype>& vec, const utype& tol = _AUROSTD_XVECTOR_TOLERANCE_IDENTITY_); // CO20180409
488
489 template <class utype> double getGeneralAngle(const xvector<utype>& _vec, int _i, const utype& tol = _AUROSTD_XVECTOR_TOLERANCE_IDENTITY_); // CO20180409
490
491 template <class utype> xvector<utype> getGeneralNormal(const std::vector<xvector<utype>>& _directive_vectors); // CO20180409
492
493 template <class utype> xvector<utype> pointLineIntersection(const xvector<utype>& a, const xvector<utype>& n, const xvector<utype>& p); // CO20180520
494
495 template <class utype> bool linePlaneIntersect(const xvector<utype>& p0, const xvector<utype>& n, const xvector<utype>& l0, const xvector<utype>& l, double& d, xvector<utype>& intersection); // CO20180520
496
497 template <class utype> xvector<utype> getVectorProjection(const xvector<utype>& b, const xvector<utype>& a); // ME20200511
498 template <class utype> xvector<utype> getModeratedVectorProjection(const xvector<utype> c, const xvector<utype>& b, const xvector<utype>& a); // ME20200511
499
500 // grid generation
501 xvector<double> linspace(const double start, const double stop, const int n);
502 xvector<double> linspace(const double start, const double stop, const double n);
503
504 // SIMPLE SORT ROUTINES
505 template <class utype>
506 void // WRAP TO SHELL SHORT
508
509 template <class utype>
510 xvector<utype> // SHELLSORT
512
513 template <class utype>
514 xvector<utype> // HEAPSORT
515 heapsort(const xvector<utype>& a) __xprototype;
516
517 template <class utype>
518 xvector<utype> // QUICKSORT
520
521 template <class utype1, class utype2>
522 void // QUICKSORT
523 quicksort2(unsigned long n, xvector<utype1>&, xvector<utype2>&) __xprototype;
524
525 template <class utype1, class utype2, class utype3>
526 void // QUICKSORT
527 quicksort3(unsigned long n, xvector<utype1>&, xvector<utype2>&, xvector<utype3>&) __xprototype;
528
529 template <class utype1, class utype2, class utype3, class utype4>
530 void // QUICKSORT
531 quicksort4(unsigned long n, xvector<utype1>&, xvector<utype2>&, xvector<utype3>&, xvector<utype4>&) __xprototype;
532
533 template <class utype>
534 xvector<utype> // SSORT shortcup for SHELLSORT
535 ssort(const xvector<utype>& a) {
536 return shellsort(a);
537 }
538
539 template <class utype>
540 xvector<utype> // HPSORT shortcup for HEAPSORT
542 return heapsort(a);
543 }
544
545 // template<class utype> xvector<utype> // QSORT shortcup for QUICKSORT
546 // sort(const xvector<utype>& a) { return heapsort(a);}
547
548 template <class utype>
549 xvector<utype> // SORT shortcup for HPSORT
551 return quicksort(a);
552 }
553
554 template <class utype1, class utype2>
555 void // QUICKSORT
556 sort2(unsigned long n, xvector<utype1>& a, xvector<utype2>& b) {
557 quicksort2(n, a, b);
558 }
559
560 template <class utype1, class utype2, class utype3>
561 void // QUICKSORT
563 quicksort3(n, a, b, c);
564 }
565
566 template <class utype1, class utype2, class utype3, class utype4>
567 void // QUICKSORT
569 quicksort4(n, a, b, c, d);
570 }
571} // namespace aurostd
572
573namespace aurostd { // CO20190419
574 template <class utype> class compareVecElement {
575 public:
576 compareVecElement(uint ind = 0, bool ascending = true);
577 bool operator()(const std::vector<utype>& a, const std::vector<utype>& b);
578 bool operator()(const xvector<utype>& a, const xvector<utype>& b);
579
580 private:
581 uint m_uindex_sort; // keep in memory so we don't rely on many conversions per sort
582 int m_iindex_sort; // keep in memory so we don't rely on many conversions per sort
583 bool m_ascending_sort; // m_ascending_sort==true is ascending sort, ==false is descending sort, NB this can be different than using rbegin()/rend(), see sort(ids...) in XRD analysis in aflow_pflow_funcs.cpp
584 };
585 template <class utype> bool compareVecElements(const std::vector<utype>& a, const std::vector<utype>& b);
586 template <class utype> bool compareXVecElements(const aurostd::xvector<utype>& a, const aurostd::xvector<utype>& b);
587} // namespace aurostd
588
589namespace aurostd { // CO20190419
590 // SOME STATS STUFF
591 template <class utype> utype mean(const xvector<utype>& a); // CO20190520
592 template <class utype> utype meanWeighted(const xvector<utype>& a, const xvector<utype>& weights); // CO20190520
593 template <class utype> utype meanWeighted(const xvector<utype>& a, const xvector<utype>& weights, utype& sum_weights); // CO20190520
594 template <class utype> utype var(const xvector<utype>& a, int ddof = 1); // CO20190520
595 template <class utype> utype stddev(const xvector<utype>& a, int ddof = 1); // CO20190520
596 template <class utype> utype mode(const xvector<utype>& a); // CO20190520
597 template <class utype> utype correlation_Pearson_fast(const xvector<utype>& a, const xvector<utype>& b, int ddof = 1); // CO20190520
598 template <class utype> utype correlation_Pearson_fast(const xvector<utype>& a, utype mean_a, utype stddev_a, const xvector<utype>& b, utype mean_b, utype stddev_b, int ddof = 1); // CO20190520
599 template <class utype> utype correlation_Pearson_slow(const xvector<utype>& a, const xvector<utype>& b); // CO20190520
600 template <class utype> void getQuartiles(const xvector<utype>& _a, utype& q1, utype& q2, utype& q3); // CO20171202
601 template <class utype> utype getMAD(const xvector<utype>& _a, utype median = (utype) AUROSTD_NAN); // CO20171202, absolute deviation around the median (MAD)
602 template <class utype> xvector<utype> convolution(const xvector<utype>& signal_input, const xvector<utype>& response_input, int SHAPE = CONV_SHAPE_FULL); // CO20190419
603 template <class utype> xvector<utype> convolution(const xvector<utype>& signal_input, const xvector<utype>& response_input, std::vector<uint>& sum_counts, int SHAPE = CONV_SHAPE_FULL); // CO20190419
604 template <class utype> xvector<utype> moving_average(const xvector<utype>& signal_input, int window); // CO20190419
605} // namespace aurostd
606
607namespace aurostd { // CO20190620
608 // signal processing
609 template <class utype>
610 std::vector<int> getPeaks(const xvector<utype>& signal_input, uint smoothing_iterations = 4, uint avg_window = 4, int width_maximum = 1, double significance_multiplier = 1.0); // CO20190620
611 template <class utype>
612 std::vector<int> getPeaks(const xvector<utype>& signal_input, xvector<utype>& signal_smooth, uint smoothing_iterations = 4, uint avg_window = 4, int width_maximum = 1, double significance_multiplier = 1.0); // CO20190620
613
614 template <class utype> std::vector<xvector<double>> histogram(const xvector<utype>& data, uint bins, double minimum_data, double maximum_data);
615 template <class utype> std::vector<xvector<double>> histogram(const xvector<utype>& data, uint bins); // AZ20230204
616 template <class utype> std::vector<xvector<double>> histogram(const xvector<utype>& data, uint max_bins, uint bin_mode); // AZ20230204
617
618} // namespace aurostd
619
620namespace aurostd {
621 // differenitation
622 xvector<double> diffSG(const xvector<double>& f, double dx); // AS20210901
623} // namespace aurostd
624
625// ----------------------------------------------------------------------------
626// ----------------------------------------------------------------------------
627
628#endif // _AUROSTD_XVECTOR_H_
629
630// ***************************************************************************
631// * *
632// * Aflow STEFANO CURTAROLO - Duke University 2003-2024 *
633// * *
634// ***************************************************************************
return false
unsigned uint
Definition aurostd.h:39
#define __xprototype
#define AUROSTD_NAN
#define _AUROSTD_XVECTOR_TOLERANCE_IDENTITY_
#define CONV_SHAPE_FULL
#define _AUROSTD_XVECTOR_TOLERANCE_ROUNDOFF_
bool operator()(const xvector< utype > &a, const xvector< utype > &b)
bool operator()(const std::vector< utype > &a, const std::vector< utype > &b)
compareVecElement(uint ind=0, bool ascending=true)
xvector< utype > & operator-=(const xvector< utype > &)
xvector< utype > & operator*=(utype r)
void shift(int new_lrows)
shift the lower row bound of an xmatrix to a new value
xvector(int=3, int=1)
xvector< utype > & operator+=(const xvector< utype > &)
utype & operator[](int) const
xvector< utype > & operator=(const xvector< utype > &)
utype & operator()(int) const
xvector< utype > & operator/=(utype r)
std::initializer_list< utype >::const_iterator ili
void resize(int=3, int nl=1)
resize a xvector to the given dimensions
void set(const utype &)
void copy(const xvector< utype > &b)
xmatrix< utype > sec(const xmatrix< utype > &) __xprototype
utype scalar_product(const xvector< utype > &a, const xvector< utype > &b)
void sort2(unsigned long n, xvector< utype1 > &a, xvector< utype2 > &b)
xvector< utype > elementwise_product(const xvector< utype > &a, const xvector< utype > &b)
xvector< utype > sech(const xvector< utype > &) __xprototype
xcomplex< utype > exp(const xcomplex< utype > &x)
double convex_volume_integral_triangle(const std::vector< xvector< utype > > &points, const std::vector< std::vector< uint > > &facets, const std::function< double(const xvector< double > &point)> &func)
utype mod(utype x, utype y)
bool isinteger(const xmatrix< utype > &a, const utype &tol)
xmatrix< utype > tanh(const xmatrix< utype > &) __xprototype
xmatrix< utype > tan(const xmatrix< utype > &) __xprototype
xcomplex< utype > cos(const xcomplex< utype > &x)
int LCM(int a, int b)
void set(xmatrix< utype > &a, const utype &s)
bool compareXVecElements(const aurostd::xvector< utype > &a, const aurostd::xvector< utype > &b)
void sort3(unsigned long n, xvector< utype1 > &a, xvector< utype2 > &b, xvector< utype3 > &c)
xmatrix< double > xdouble(const xmatrix< utype > &a) __xprototype
xmatrix< utype > outer_product(const xvector< utype > &a, const xvector< utype > &b)
xvector< utype > acotanh(const xvector< utype > &) __xprototype
void quicksort2(unsigned long n, xvector< utype1 > &, xvector< utype2 > &) __xprototype
xvector< utype > vector_product(const xvector< utype > &a, const xvector< utype > &b)
xmatrix< utype > sign(const xmatrix< utype > &a)
utype modulus(const xmatrix< utype > &a)
xvector< utype > qsort(const xvector< utype > &a)
xvector< utype > getVectorProjection(const xvector< utype > &b, const xvector< utype > &a)
void GCD(const xmatrix< int > &ma, const xmatrix< int > &mb, xmatrix< int > &mgcd)
utype abs(const xcomplex< utype > &x)
xcomplex< utype > sin(const xcomplex< utype > &x)
xvector< utype > operator%(const xvector< utype > &a, const xvector< utype > &b)
utype meanWeighted(const xvector< utype > &a, const xvector< utype > &weights)
utype modulussquare(const xmatrix< utype > &a)
xmatrix< utype > asinh(const xmatrix< utype > &) __xprototype
xvector< double > linspace(const double start, const double stop, const int n)
vector< utype > clear(vector< utype > &v)
xvector< utype > moving_average(const xvector< utype > &signal_input, int window)
xmatrix< utype > asin(const xmatrix< utype > &) __xprototype
xvector< double > getGeneralAngles(const xvector< utype > &vec, const utype &tol=_AUROSTD_XVECTOR_TOLERANCE_IDENTITY_)
xmatrix< int > xint(const xmatrix< utype > &a) __xprototype
bool isCollinear(const xvector< utype > &v0, const xvector< utype > &v1, const utype &tol=_AUROSTD_XVECTOR_TOLERANCE_IDENTITY_) __xprototype
xmatrix< utype > acos(const xmatrix< utype > &) __xprototype
vector< utype > reset(vector< utype > &v)
xvector< utype > getModeratedVectorProjection(const xvector< utype > c, const xvector< utype > &b, const xvector< utype > &a)
utype distance(const xvector< utype > &, const xvector< utype > &) __xprototype
double areaPointsOnPlane(const std::vector< xvector< utype > > &points) __xprototype
xcomplex< utype > operator+(const xcomplex< utype > &x, const xcomplex< utype > &y)
xvector< utype > cosech(const xvector< utype > &) __xprototype
xvector< double > getCentroidPBC(const std::vector< xvector< utype > > &points, const xmatrix< utype > &lattice) __xprototype
xmatrix< utype > atan(const xmatrix< utype > &) __xprototype
xvector< double > diffSG(const xvector< double > &f, double dx)
xvector< utype > cotanh(const xvector< utype > &) __xprototype
xmatrix< utype > acosh(const xmatrix< utype > &) __xprototype
void quicksort3(unsigned long n, xvector< utype1 > &, xvector< utype2 > &, xvector< utype3 > &) __xprototype
utype angle(utype x1, utype x2, utype x3, utype y1, utype y2, utype y3)
utype mean(const vector< utype > vec)
xvector< utype > vector2xvector(const std::vector< utype > &, int lrows=1) __xprototype
void quicksort4(unsigned long n, xvector< utype1 > &, xvector< utype2 > &, xvector< utype3 > &, xvector< utype4 > &) __xprototype
__xprototype
Definition aurostd.h:175
xvector< utype > convolution(const xvector< utype > &signal_input, const xvector< utype > &response_input, int SHAPE=CONV_SHAPE_FULL)
void reduceByGCD(const xvector< utype > &in_V, xvector< utype > &out_V, utype tol=(utype) _AUROSTD_XVECTOR_TOLERANCE_IDENTITY_) __xprototype
utype mode(const xvector< utype > &a)
xmatrix< utype > ceil(const xmatrix< utype > &a)
double tetrahedron_integral(const std::vector< xvector< utype > > &points, const std::function< double(const xvector< double > &point)> &func)
xvector< utype > getCentroid(const std::vector< xvector< utype > > &points) __xprototype
xmatrix< utype > log10(const xmatrix< utype > &) __xprototype
xmatrix< utype > floor(const xmatrix< utype > &a)
double volume(const std::vector< xvector< utype > > &points, const std::vector< std::vector< uint > > &facets, const std::vector< xvector< utype > > &normals) __xprototype
bool isequal(const xcomplex< utype > &a, const xcomplex< utype > &b, utype _tol_)
bool isdifferent(const xcomplex< utype > &a, const xcomplex< utype > &b, utype _tol_)
xvector< char > operator<(const xvector< utype > &a, const utype &b)
xvector< utype > getGeneralNormal(const std::vector< xvector< utype > > &_directive_vectors)
utype max(const vector< utype > vec)
xvector< utype > shellsort(const xvector< utype > &a) __xprototype
bool iszero(utype a)
xmatrix< utype > cosec(const xmatrix< utype > &) __xprototype
xcomplex< utype > pow(const xcomplex< utype > &x, const xcomplex< utype > &y)
std::vector< int > getPeaks(const xvector< utype > &signal_input, uint smoothing_iterations=4, uint avg_window=4, int width_maximum=1, double significance_multiplier=1.0)
double getangle(const xvector< utype > &, const xvector< utype > &) __xprototype
void sort4(unsigned long n, xvector< utype1 > &a, xvector< utype2 > &b, xvector< utype3 > &c, xvector< utype4 > &d)
xvector< utype > heapsort(const xvector< utype > &a) __xprototype
void swap(xvector< utype > &, const int &, const int &) __xprototype
utype mod_floored(utype x, utype y)
floored mod function e.g. std::fmod(-4.0,+1.1)= -0.7; std::fmod(-4.0,-1.1)= -0.7 std::remainder(-4....
xcomplex< utype > operator*(const xcomplex< utype > &x, const xcomplex< utype > &y)
int maxi(const xvector< utype > &) __xprototype
xmatrix< utype > atanh(const xmatrix< utype > &) __xprototype
bool compareVecElements(const std::vector< utype > &a, const std::vector< utype > &b)
xcomplex< utype > sinh(const xcomplex< utype > &x)
xvector< utype > ssort(const xvector< utype > &a)
bool operator==(const xcomplex< utype > &x, const xcomplex< utype > &y)
xvector< char > operator>(const xvector< utype > &a, const utype &b)
xvector< utype > ones_xv(int nh, int nl) __xprototype
int gaussian_filter_get_window(utype sigma) __xprototype
xcomplex< utype > cosh(const xcomplex< utype > &x)
xcomplex< utype > log(const xcomplex< utype > &x)
bool identical(vector< utype > v1, vector< utype > v2, utype epsilon)
utype modulus2(const xmatrix< utype > &a)
xmatrix< long int > xlongint(const xmatrix< utype > &a) __xprototype
utype min(const vector< utype > vec)
utype sum(const vector< utype > vec)
xvector< utype > vabs(const xvector< utype > &) __xprototype
xvector< utype > gaussian_filter_xv(utype sigma) __xprototype
void sort(vector< utype1 > &arr)
bool linePlaneIntersect(const xvector< utype > &p0, const xvector< utype > &n, const xvector< utype > &l0, const xvector< utype > &l, double &d, xvector< utype > &intersection)
void sortPolyhedronFacets(const std::vector< xvector< utype > > &points, std::vector< std::vector< uint > > &facets, std::vector< xvector< utype > > &normals)
xvector< utype > normalizeSumToOne(const xvector< utype > &in_V, const utype &tol=(utype) _AUROSTD_XVECTOR_TOLERANCE_ROUNDOFF_) __xprototype
xmatrix< utype > nint(const xmatrix< utype > &a)
std::vector< xvector< double > > histogram(const xvector< utype > &data, uint bins, double minimum_data, double maximum_data)
xvector< utype > box_filter_xv(int window, int lrows) __xprototype
xcomplex< utype > conj(const xcomplex< utype > &x)
void getQuartiles(const xvector< utype > &_a, utype &q1, utype &q2, utype &q3)
vector< utype > xvector2vector(const xvector< utype > &xvec)
double convex_volume_integral(const std::vector< xvector< utype > > &points, const std::vector< std::vector< uint > > &facets, const std::function< double(const xvector< double > &point)> &func)
int mini(const xvector< utype > &) __xprototype
xvector< utype > pointLineIntersection(const xvector< utype > &a, const xvector< utype > &n, const xvector< utype > &p)
xvector< utype > hpsort(const xvector< utype > &a)
utype getMAD(const xvector< utype > &_a, utype median=(utype) AUROSTD_NAN)
xmatrix< utype > roundoff(const xmatrix< utype > &a, utype _tol_)
double getGeneralAngle(const xvector< utype > &_vec, int _i, const utype &tol=_AUROSTD_XVECTOR_TOLERANCE_IDENTITY_)
xmatrix< long double > xlongdouble(const xmatrix< utype > &a) __xprototype
b64_encoder_proxy operator<<(std::ostream &os, b64_encoder_creator)
xmatrix< char > xchar(const xmatrix< utype > &a) __xprototype
xcomplex< utype > operator-(const xcomplex< utype > &x, const xcomplex< utype > &y)
xvector< out_type > xvector2utype(const xvector< in_type > &in_vec) __xprototype
xvector< utype > quicksort(const xvector< utype > &) __xprototype
xcomplex< utype > operator/(const xcomplex< utype > &x, const xcomplex< utype > &y)
double getcos(const xvector< utype > &, const xvector< utype > &) __xprototype
xvector< uint > sortPolygonVertices(const std::vector< xvector< utype > > &points, const xvector< utype > &normal)
xmatrix< float > xfloat(const xmatrix< utype > &a) __xprototype
utype correlation_Pearson_fast(const xvector< utype > &a, const xvector< utype > &b, int ddof=1)
utype stddev(const xvector< utype > &a, int ddof=1)
xmatrix< utype > trunc(const xmatrix< utype > &a)
utype correlation_Pearson_slow(const xvector< utype > &a, const xvector< utype > &b)
utype elements_product(const xvector< utype > &a)
utype var(const xvector< utype > &a, int ddof=1)
double getsin(const xvector< utype > &, const xvector< utype > &) __xprototype
xmatrix< utype > round(const xmatrix< utype > &a)
xvector< utype > null_xv() __xprototype