25void mat::random_unitary(
const std::vector <double>& phi_v,
const std::vector <double>& psi_v,
const std::vector <double>& chi_v,
double alpha)
27 int dim = chi_v.size();
35 for(
int j=1; j<=dim-1; ++j)
39 for(
int i=j; i>=1; --i)
59 z = algebra::ComplexHelper::construct(psi);
63 z = algebra::ComplexHelper::construct(chi);
67 z = algebra::ComplexHelper::construct(-chi);
71 z = algebra::ComplexHelper::construct(-psi);
76 E.multiply(temp, temp2);
87 Complex c = cos(alpha) + I*sin(alpha);
91bool matrix::eigenValues(std::vector <double>& values)
93 int n, lda, info, lwork, lrwork, liwork;
100 Complex wkopt, *work;
102 double *w =
new double[n];
106 for(
int r=0; r<n; ++r)
108 for(
int c=0; c<n; ++c)
113 a(r,c) = (*this)(r,c);
122 LAPACK_zheevd(
"N",
"Upper", &n, a.getElements(), &lda, w, &wkopt, &lwork, &rwkopt, &lrwork, &iwkopt, &liwork, &info);
123 lwork = (int)creal(wkopt);
124 work =
new Complex[lwork];
125 lrwork = (int)rwkopt;
126 rwork =
new double[lrwork];
128 iwork =
new int[liwork];
130 LAPACK_zheevd(
"N",
"Upper", &n, a.getElements(), &lda, w, work, &lwork, rwork, &lwork, iwork, &liwork, &info);
135 for(
int i=0; i<n; ++i)
136 values.push_back(w[i]);
147void matrix::tensor(matrix* B, matrix* output)
152 output->create(getRows()*B->getRows(), getCols()*B->getCols());
154 for(
int r=0; r<output->getRows(); ++r)
156 for(
int c=0; c<output->getCols(); ++c)
158 int aRow = r / B->getRows();
159 int aCol = c / B->getCols();
160 int bRow = r % B->getRows();
161 int bCol = c % B->getCols();
163 output->setDirect(r, c, getDirect(aRow, aCol)* B->getDirect(bRow, bCol));
168bool matrix::multiply(matrix& B, matrix& output,
char TRANSB)
171 std::cout <<
"Warning: matrix transpose not implemented in multiply function; result will be wrong\n";
173 output.create(getRows(), B.getCols());
175 for(
int row=0; row<output.getRows(); ++row)
177 for(
int col=0; col<output.getCols(); ++col){
179 for(
int k=0; k<getCols(); ++k)
180 sum = sum + ( (*
this)(row,k) * B(k,col) );
182 output(row, col) = sum;