OSDN Git Service

removes destructor of QCalcUnit
[qcad/qcad.git] / calcunits / QC_pauliZ.cpp
1 //---------------------------------------------------------------------------
2 // Pauli Z gate
3 //---------------------------------------------------------------------------
4 #include "QC_pauliZ.h"
5 //---------------------------------------------------------------------------
6 /**
7  *  Constructor
8  */
9 QC_pauliZ::QC_pauliZ(int _Target) : QCalcUnit() {
10     Target = _Target;
11 }
12 //---------------------------------------------------------------------------
13 /**
14  *  Calculate
15  */
16 void
17 QC_pauliZ::calc(int target, double R[], double I[], int NumberOfBits) {
18
19     unsigned int state = 1<< (NumberOfBits - 1);
20     for (unsigned int i=0;i<state;i++) {
21         unsigned int ix1 = insert1(i,target);
22
23         //Pauli Z
24
25         R[ix1] = -R[ix1];
26         I[ix1] = -I[ix1];
27     }
28 }
29 //---------------------------------------------------------------------------
30 void
31 QC_pauliZ::Calc(QBits *qBits) {
32     int N = qBits->GetNumberOfQBits();
33     double *R = qBits->GetBitsR();//Real Part
34     double *I = qBits->GetBitsI();//Imaginary Part
35
36     QC_pauliZ::calc(Target, R, I, N);
37 }
38 //---------------------------------------------------------------------------
39 #ifdef __USE__MPI
40 void
41 QC_pauliZ::calcmpi(int t1, double R[], double I[], int N) {
42     double r0 = 0.0;
43     double i0 = 0.0;
44     double r1 = 0.0;
45     double i1 = 0.0;
46     unsigned int ix0, ix1;
47
48     for (int i = 0; i < (1 << (N - 1)); i++) {
49         // Obtain indices of state:
50         ix0 = QCalcUnit::insert0(i, t1);
51         ix1 = QCalcUnit::insert1(i, t1);
52
53         bool bstore = setup(R, I, ix0, ix1, r0, i0, r1, i1);
54         if (bstore) {
55             double nr0 = r0;
56             double ni0 = i0;
57             double nr1 = -r1;
58             double ni1 = -i1;
59             // Store:
60             store(R, I, ix0, ix1, nr0, ni0, nr1, ni1);
61         }
62     }
63 }
64 #endif
65 //---------------------------------------------------------------------------
66