poulpy/spqlios/lib/test/testlib/reim4_elem.h
spqlios/lib/test/testlib/reim4_elem.hRaw
1#ifndef SPQLIOS_REIM4_ELEM_H
2#define SPQLIOS_REIM4_ELEM_H
3
4#include "test_commons.h"
5
6/** @brief test class representing one single reim4 element */
7class reim4_elem {
8 public:
9 /** @brief 8 components (4 real parts followed by 4 imag parts) */
10 double value[8];
11 /** @brief constructs from 4 real parts and 4 imaginary parts */
12 reim4_elem(const double* re, const double* im);
13 /** @brief constructs from 8 components */
14 explicit reim4_elem(const double* layout);
15 /** @brief zero */
16 reim4_elem();
17 /** @brief saves the real parts to re and the 4 imag to im */
18 void save_re_im(double* re, double* im) const;
19 /** @brief saves the 8 components to reim4 */
20 void save_as(double* reim4) const;
21 static reim4_elem zero();
22};
23
24/** @brief checks for equality */
25bool operator==(const reim4_elem& x, const reim4_elem& y);
26/** @brief random gaussian reim4 of stdev 1 and mean 0 */
27reim4_elem gaussian_reim4();
28/** @brief addition */
29reim4_elem operator+(const reim4_elem& x, const reim4_elem& y);
30reim4_elem& operator+=(reim4_elem& x, const reim4_elem& y);
31/** @brief subtraction */
32reim4_elem operator-(const reim4_elem& x, const reim4_elem& y);
33reim4_elem& operator-=(reim4_elem& x, const reim4_elem& y);
34/** @brief product */
35reim4_elem operator*(const reim4_elem& x, const reim4_elem& y);
36std::ostream& operator<<(std::ostream& out, const reim4_elem& x);
37/** @brief distance in infty norm */
38double infty_dist(const reim4_elem& x, const reim4_elem& y);
39
40/** @brief test class representing the view of one reim of m complexes */
41class reim4_array_view {
42 uint64_t size; ///< size of the reim array
43 double* data; ///< pointer to the start of the array
44 public:
45 /** @brief ininitializes a view at an existing given address */
46 reim4_array_view(uint64_t size, double* data);
47 ;
48 /** @brief gets the i-th element */
49 reim4_elem get(uint64_t i) const;
50 /** @brief sets the i-th element */
51 void set(uint64_t i, const reim4_elem& value);
52};
53
54/** @brief test class representing the view of one matrix of nrowsxncols reim4's */
55class reim4_matrix_view {
56 uint64_t nrows; ///< number of rows
57 uint64_t ncols; ///< number of columns
58 double* data; ///< pointer to the start of the matrix
59 public:
60 /** @brief ininitializes a view at an existing given address */
61 reim4_matrix_view(uint64_t nrows, uint64_t ncols, double* data);
62 /** @brief gets the i-th element */
63 reim4_elem get(uint64_t row, uint64_t col) const;
64 /** @brief sets the i-th element */
65 void set(uint64_t row, uint64_t col, const reim4_elem& value);
66};
67
68/** @brief test class representing the view of one reim of m complexes */
69class reim_view {
70 uint64_t m; ///< (complex) dimension of the reim polynomial
71 double* data; ///< address of the start of the reim polynomial
72 public:
73 /** @brief ininitializes a view at an existing given address */
74 reim_view(uint64_t m, double* data);
75 ;
76 /** @brief extracts the i-th reim4 block (i<m/4) */
77 reim4_elem get_blk(uint64_t i);
78 /** @brief sets the i-th reim4 block (i<m/4) */
79 void set_blk(uint64_t i, const reim4_elem& value);
80};
81
82/** @brief view of one contiguous reim vector */
83class reim_vector_view {
84 uint64_t m; ///< (complex) dimension of the reim polynomial
85 uint64_t nrows; ///< number of reim polynomials
86 double* data; ///< address of the start of the reim polynomial
87
88 public:
89 /** @brief ininitializes a view at an existing given address */
90 reim_vector_view(uint64_t m, uint64_t nrows, double* data);
91 /** @brief view of the given reim */
92 reim_view row(uint64_t row);
93};
94
95#endif // SPQLIOS_REIM4_ELEM_H