| 555 | } |
| 556 | |
| 557 | QVector getNormalised(QVector vec) { |
| 558 | |
| 559 | // compute the vec norm via Kahan summation to suppress numerical error |
| 560 | qreal norm = 0; |
| 561 | qreal y, t, c; |
| 562 | c = 0; |
| 563 | |
| 564 | for (size_t i=0; i<vec.size(); i++) { |
| 565 | y = real(vec[i])*real(vec[i]) - c; |
| 566 | t = norm + y; |
| 567 | c = ( t - norm ) - y; |
| 568 | norm = t; |
| 569 | |
| 570 | y = imag(vec[i])*imag(vec[i]) - c; |
| 571 | t = norm + y; |
| 572 | c = ( t - norm ) - y; |
| 573 | norm = t; |
| 574 | } |
| 575 | |
| 576 | for (size_t i=0; i<vec.size(); i++) |
| 577 | vec[i] /= sqrt(norm); |
| 578 | return vec; |
| 579 | } |
| 580 | |
| 581 | QVector getRandomStateVector(int numQb) { |
| 582 | return getNormalised(getRandomQVector(1<<numQb)); |
no outgoing calls
no test coverage detected