41 throw "wrong dimension";
62 srand (static_cast<unsigned int>(time(NULL)));
64 for (
int idx=0; idx<
dim*(
dim-1)/2; idx++) {
65 vargamma[idx] = (2*double(rand())/double(RAND_MAX)-1)*2*
M_PI;
88 std::stringstream sstream;
94 sstream <<
"Wring number of parameters in Random_Orthogonal::Construct_Orthogonal_Matrix" << std::endl;
96 print(sstream, verbose_level);
102 memset( vargamma_mtx.
get_data(), 0, vargamma_mtx.
size()*
sizeof(double) );
104 for (
int idx=0; idx<
dim; idx++) {
105 for (
int jdx=idx+1; jdx<
dim; jdx++) {
106 vargamma_mtx[idx*vargamma_mtx.
stride + jdx] = vargamma[gamma_index];
154 for (
int ndx=2; ndx<=
dim; ndx++) {
162 for (
int row_idx=0; row_idx<ndx-1; row_idx++) {
165 tn[ndx*tn.
stride -1] = 1.0;
168 for (
int col_idx=0; col_idx<ndx; col_idx++) {
174 sl[0] = -tn[col_idx*tn.stride + ndx-1];
177 Tn_new[col_idx] = tn[col_idx]*cos(vargamma_mtx[ndx-1]) - sl[0]*sin(vargamma_mtx[ndx-1]);
180 for (
int row_idx=1; row_idx<ndx; row_idx++) {
183 sl[row_idx] = tn[kdx*tn.stride+col_idx] * sin(vargamma_mtx[kdx*dim+ndx-1]) + sl[kdx] * cos(vargamma_mtx[kdx*dim+ndx-1]);
185 if ( row_idx == ndx-1 ) {
186 Tn_new[row_idx*Tn_new.
stride + col_idx] = - sl[row_idx];
189 Tn_new[row_idx*Tn_new.
stride + col_idx] = tn[row_idx*tn.stride + col_idx] * cos(vargamma_mtx[row_idx*dim+ndx-1]) - sl[row_idx] * sin(vargamma_mtx[row_idx*dim+ndx-1]);
205 for (
int idx=0; idx<ret.
size(); idx++) {
206 ret[idx].real = Tn[idx];
226 throw std::string(
"Wrong number of parameters in Random_Orthogonal::Construct_Orthogonal_Matrix(float32)");
231 memset( vargamma_mtx.
get_data(), 0, vargamma_mtx.
size()*
sizeof(float) );
233 for (
int idx=0; idx<
dim; idx++) {
234 for (
int jdx=idx+1; jdx<
dim; jdx++) {
235 vargamma_mtx[idx*vargamma_mtx.
stride + jdx] = vargamma[gamma_index];
245 for (
int ndx=2; ndx<=
dim; ndx++) {
253 for (
int row_idx=0; row_idx<ndx-1; row_idx++) {
256 tn[ndx*tn.
stride -1] = 1.0f;
260 float c0_gamma, s0_gamma;
262 for (
int col_idx=0; col_idx<ndx; col_idx++) {
268 sl[0] = -tn[col_idx*tn.stride + ndx-1];
271 Tn_new[col_idx] = tn[col_idx]*c0_gamma - sl[0]*s0_gamma;
274 for (
int row_idx=1; row_idx<ndx; row_idx++) {
279 sl[row_idx] = tn[kdx*tn.stride+col_idx] * s_k + sl[kdx] * c_k;
281 if ( row_idx == ndx-1 ) {
282 Tn_new[row_idx*Tn_new.
stride + col_idx] = -sl[row_idx];
287 Tn_new[row_idx*Tn_new.
stride + col_idx] = tn[row_idx*tn.stride + col_idx] * c_r - sl[row_idx] * s_r;
299 for (
int idx=0; idx<ret.
size(); idx++) {
300 ret[idx].real = Tn[idx];
void qgd_sincos< float >(float x, float *s, float *c)
void print(const std::stringstream &sstream, int verbose_level=1) const
Call to print output messages in the function of the verbosity level.
Class to store single-precision real arrays and properties.
int stride
The column stride of the array. (The array elements in one row are a_0, a_1, ... a_{cols-1}, 0, 0, 0, 0. The number of zeros is stride-cols)
Random_Orthogonal(int dim_in)
Constructor of the class.
Structure type representing single-precision complex numbers.
Header file for a class containing basic methods for setting up the verbosity level.
scalar * get_data() const
Call to get the pointer to the stored data.
int rows
The number of rows.
int cols
The number of columns.
Umtx
The unitary to be decomposed.
Matrix Construct_Orthogonal_Matrix()
Call to create a random unitary.
Double-precision complex matrix (float64).
int size() const
Call to get the number of the allocated elements.
int dim
The number of rows in the created unitary.
Single-precision complex matrix (float32).
Class to store data of complex arrays and its properties.