Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
matrix_real.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_real.h"
25 #include "matrix_real_float.h"
26 #include <cstring>
27 #include <iostream>
28 #include "tbb/tbb.h"
29 #include <math.h>
30 
31 
37 
38 }
39 
47 Matrix_real::Matrix_real( double* data_in, int rows_in, int cols_in) : matrix_base<double>(data_in, rows_in, cols_in) {
48 
49 }
50 
51 
60 Matrix_real::Matrix_real( double* data_in, int rows_in, int cols_in, int stride_in) : matrix_base<double>(data_in, rows_in, cols_in, stride_in) {
61 
62 }
63 
64 
71 Matrix_real::Matrix_real( int rows_in, int cols_in) : matrix_base<double>(rows_in, cols_in) {
72 
73 
74 }
75 
76 
84 Matrix_real::Matrix_real( int rows_in, int cols_in, int stride_in) : matrix_base<double>(rows_in, cols_in, stride_in) {
85 
86 }
87 
88 
89 
95 
96 }
97 
106  return *this;
107 }
108 
115 
117 
118  // logical variable indicating whether the matrix needs to be conjugated in CBLAS operations
119  ret.conjugated = conjugated;
120  // logical variable indicating whether the matrix needs to be transposed in CBLAS operations
121  ret.transposed = transposed;
122  // 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)
123  ret.owner = true;
124 
125  memcpy( ret.data, data, rows*stride*sizeof(double));
126 
127  return ret;
128 
129 }
130 
131 void
133 
135 
136 }
137 
138 void
140 
141  if (target.rows != rows || target.cols != cols || target.stride != stride) {
142  target = Matrix_real_float(rows, cols, stride);
143  }
144 
145  for (int row=0; row<rows; row++) {
146  for (int col=0; col<cols; col++) {
147  const int idx = row*stride + col;
148  target[idx] = static_cast<float>(data[idx]);
149  }
150  }
151 
152  if (target.is_conjugated() != conjugated) {
153  target.conjugate();
154  }
155  if (target.is_transposed() != transposed) {
156  target.transpose();
157  }
158 
159 }
160 
161 
166 bool
168 
169  for (int idx=0; idx < rows*cols; idx++) {
170  if ( std::isnan(data[idx]) ) {
171  return true;
172  }
173  }
174 
175  return false;
176 
177 
178 }
179 
180 
181 
Class to store single-precision real arrays and properties.
bool owner
logical value indicating whether the class instance is the owner of the stored data or not...
Definition: matrix_base.hpp:57
Matrix_real copy() const
Call to create a copy of the matrix.
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
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
void operator=(const matrix_base &mtx)
Assignment operator.
int rows
The number of rows.
Definition: matrix_base.hpp:42
int cols
The number of columns.
Definition: matrix_base.hpp:44
bool isnan()
Call to check the array for NaN entries.
void copy_to(Matrix_real &target) const
Copy the matrix to a reusable double-precision target matrix.
void copy_to(matrix_base< scalar > &target) const
Copy the current matrix storage into a reusable target matrix.
Matrix_real()
Default constructor of the class.
Definition: matrix_real.cpp:36
void transpose()
Call to transpose (or un-transpose) the matrix for CBLAS functions.
Matrix_real & operator=(const Matrix_real &mtx)
Assignment operator of the class.
bool is_conjugated() const
Call to get whether the matrix should be conjugated in CBLAS functions or not.
void conjugate()
Call to conjugate (or un-conjugate) the matrix for CBLAS functions.
bool is_transposed() const
Call to get whether the matrix should be conjugated in CBLAS functions or not.
Class to store data of complex arrays and its properties.
Definition: matrix_real.h:41