Sequential Quantum Gate Decomposer  v1.9.3
Powerful decomposition of general unitarias into one- and two-qubit gates gates
matrix.cpp
Go to the documentation of this file.
1 /*
2 Created on Fri Jun 26 14:13:26 2020
3 Copyright 2020 Peter Rakyta, Ph.D.
4 
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8 
9  http://www.apache.org/licenses/LICENSE-2.0
10 
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 
17 
18 @author: Peter Rakyta, Ph.D.
19 */
24 #include "matrix.h"
25 #include <cstring>
26 #include <iostream>
27 #include "tbb/tbb.h"
28 #include <math.h>
29 
30 
31 
37 
38 }
39 
47 Matrix::Matrix( QGD_Complex16* data_in, int rows_in, int cols_in) : matrix_base<QGD_Complex16>(data_in, rows_in, cols_in) {
48 
49 }
50 
51 
60 Matrix::Matrix( QGD_Complex16* data_in, int rows_in, int cols_in, int stride_in) : matrix_base<QGD_Complex16>(data_in, rows_in, cols_in, stride_in) {
61 
62 }
63 
64 
71 Matrix::Matrix( int rows_in, int cols_in) : matrix_base<QGD_Complex16>(rows_in, cols_in) {
72 
73 
74 }
75 
76 
84 Matrix::Matrix( int rows_in, int cols_in, int stride_in) : matrix_base<QGD_Complex16>(rows_in, cols_in, stride_in) {
85 
86 }
87 
88 
89 
95 
96 }
97 
98 
99 
104 Matrix
106 
107  Matrix ret = Matrix(rows, cols, stride);
108 
109  // logical variable indicating whether the matrix needs to be conjugated in CBLAS operations
110  ret.conjugated = conjugated;
111  // logical variable indicating whether the matrix needs to be transposed in CBLAS operations
112  ret.transposed = transposed;
113  // logical value indicating whether the class instance is the owner of the stored data or not. (If true, the data array is released in the destructor)
114  ret.owner = true;
115 
116  memcpy( ret.data, data, rows*stride*sizeof(QGD_Complex16));
117 
118  return ret;
119 
120 }
121 
122 
127 bool
129 
130  for (int idx=0; idx < rows*cols; idx++) {
131  if ( std::isnan(data[idx].real) || std::isnan(data[idx].imag) ) {
132  return true;
133  }
134  }
135 
136  return false;
137 
138 
139 }
140 
141 
142 
143 
147 void
149 
150  std::cout << std::endl << "The stored matrix:" << std::endl;
151 
152  for ( int row_idx=0; row_idx < rows; row_idx++ ) {
153  for ( int col_idx=0; col_idx < cols; col_idx++ ) {
154  int element_idx = row_idx*stride + col_idx;
155  std::cout << " (" << data[element_idx].real << ", " << data[element_idx].imag << "*i)";
156  }
157 
158  std::cout << std::endl;
159  }
160  std::cout << std::endl << std::endl << std::endl;
161 
162 }
163 
164 
165 
166 
bool isnan()
Call to check the array for NaN entries.
Definition: matrix.cpp:128
Matrix()
Default constructor of the class.
Definition: matrix.cpp:36
bool owner
logical value indicating whether the class instance is the owner of the stored data or not...
Definition: matrix_base.hpp:57
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)
Definition: matrix_base.hpp:46
scalar * data
pointer to the stored data
Definition: matrix_base.hpp:48
void print_matrix() const
Call to prints the stored matrix on the standard output.
Definition: matrix.cpp:148
bool transposed
logical variable indicating whether the matrix needs to be transposed in CBLAS operations ...
Definition: matrix_base.hpp:55
bool conjugated
logical variable indicating whether the matrix needs to be conjugated in CBLAS operations ...
Definition: matrix_base.hpp:53
Base Class to store data of arrays and its properties.
Definition: matrix_base.hpp:38
int rows
The number of rows.
Definition: matrix_base.hpp:42
int cols
The number of columns.
Definition: matrix_base.hpp:44
Header file of complex array storage array with automatic and thread safe reference counting...
Structure type representing complex numbers in the SQUANDER package.
Definition: QGDTypes.h:38
Class to store data of complex arrays and its properties.
Definition: matrix.h:38
Matrix copy()
Call to create a copy of the matrix.
Definition: matrix.cpp:105
double real
the real part of a complex number
Definition: QGDTypes.h:40
double imag
the imaginary part of a complex number
Definition: QGDTypes.h:42