MCPcopy Create free account
hub / github.com/QuEST-Kit/QuEST / getNormalised

Function getNormalised

tests/deprecated/test_utilities.cpp:557–579  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

555}
556
557QVector 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
581QVector getRandomStateVector(int numQb) {
582 return getNormalised(getRandomQVector(1<<numQb));

Callers 3

getRandomStateVectorFunction · 0.70
getOrthonormalisedRowsFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected