-
Notifications
You must be signed in to change notification settings - Fork 55
/
statecreps.cpp
58 lines (49 loc) · 1.49 KB
/
statecreps.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#define NULL 0
#include <iostream>
#include <complex>
#include <assert.h>
#include <algorithm> // std::find
#include "statecreps.h"
//#include <pthread.h>
//using namespace std::complex_literals;
//#define DEBUG(x) x
#define DEBUG(x)
namespace CReps_statevec {
/****************************************************************************\
|* StateCRep *|
\****************************************************************************/
StateCRep::StateCRep(INT dim) {
//DEBUG std::cout << "StateCRep initialized w/dim = " << dim << std::endl;
_dataptr = new dcomplex[dim];
for(INT i=0; i<dim; i++) _dataptr[i] = 0;
_dim = dim;
_ownmem = true;
}
StateCRep::StateCRep(dcomplex* data, INT dim, bool copy) {
//DEGUG std::cout << "StateCRep initialized w/dim = " << dim << std::endl;
if(copy) {
_dataptr = new dcomplex[dim];
for(INT i=0; i<dim; i++) {
_dataptr[i] = data[i];
}
} else {
_dataptr = data;
}
_dim = dim;
_ownmem = copy;
}
StateCRep::~StateCRep() {
if(_ownmem && _dataptr != NULL)
delete [] _dataptr;
}
void StateCRep::print(const char* label) {
std::cout << label << " = [";
for(INT i=0; i<_dim; i++) std::cout << _dataptr[i] << " ";
std::cout << "]" << std::endl;
}
void StateCRep::copy_from(StateCRep* st) {
assert(_dim == st->_dim);
for(INT i=0; i<_dim; i++)
_dataptr[i] = st->_dataptr[i];
}
}