Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
matrix_template.cpp
Go to the documentation of this file.
2 #include "include/QGDTypes.h"
3 #include <cstring>
4 #include <iostream>
5 #include <cmath>
6 
7 template<typename ComplexType>
9 
10 template<typename ComplexType>
11 Matrix_T<ComplexType>::Matrix_T(ComplexType* data_in, int rows_in, int cols_in)
12  : matrix_base<ComplexType>(data_in, rows_in, cols_in) {}
13 
14 template<typename ComplexType>
15 Matrix_T<ComplexType>::Matrix_T(ComplexType* data_in, int rows_in, int cols_in, int stride_in)
16  : matrix_base<ComplexType>(data_in, rows_in, cols_in, stride_in) {}
17 
18 template<typename ComplexType>
19 Matrix_T<ComplexType>::Matrix_T(int rows_in, int cols_in)
20  : matrix_base<ComplexType>(rows_in, cols_in) {}
21 
22 template<typename ComplexType>
23 Matrix_T<ComplexType>::Matrix_T(int rows_in, int cols_in, int stride_in)
24  : matrix_base<ComplexType>(rows_in, cols_in, stride_in) {}
25 
26 template<typename ComplexType>
28  : matrix_base<ComplexType>(other) {}
29 
30 template<typename ComplexType>
32  : matrix_base<ComplexType>(std::move(other)) {}
33 
34 template<typename ComplexType>
36  if (this != &other) {
38  }
39  return *this;
40 }
41 
42 template<typename ComplexType>
44  if (this != &other) {
45  matrix_base<ComplexType>::operator=(std::move(other));
46  }
47  return *this;
48 }
49 
50 template<typename ComplexType>
52  Matrix_T<ComplexType> result(this->rows, this->cols, this->stride);
53  result.conjugated = this->conjugated;
54  result.transposed = this->transposed;
55  std::memcpy(result.data, this->data, this->rows * this->stride * sizeof(ComplexType));
56  return result;
57 }
58 
59 template<typename ComplexType>
61  for (int idx = 0; idx < this->rows * this->cols; idx++) {
62  if (std::isnan(this->data[idx].real) || std::isnan(this->data[idx].imag)) {
63  return true;
64  }
65  }
66  return false;
67 }
68 
69 template<typename ComplexType>
71  std::cout << "\nThe stored matrix:\n";
72  for (int row_idx = 0; row_idx < this->rows; row_idx++) {
73  for (int col_idx = 0; col_idx < this->cols; col_idx++) {
74  int element_idx = row_idx * this->stride + col_idx;
75  std::cout << " (" << this->data[element_idx].real
76  << ", " << this->data[element_idx].imag << "*i)";
77  }
78  std::cout << "\n";
79  }
80  std::cout << "\n";
81 }
82 
83 // Explicit instantiation
84 template class Matrix_T<QGD_Complex16>;
85 template class Matrix_T<QGD_Complex8>;
86 
87 // Verify size after instantiation
88 static_assert(sizeof(Matrix_T<QGD_Complex16>) == CACHELINE,
89  "Matrix_T<QGD_Complex16> size must equal exactly one CACHELINE");
90 static_assert(sizeof(Matrix_T<QGD_Complex8>) == CACHELINE,
91  "Matrix_T<QGD_Complex8> size must equal exactly one CACHELINE");
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
void print_matrix() const
ComplexType * 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
#define CACHELINE
Definition: QGDTypes.h:33
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
Matrix_T copy() const
Custom types for the SQUANDER package.
Matrix_T & operator=(const Matrix_T &other)