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

Function validate_probabilities

quest/src/core/validation.cpp:3897–3916  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3895}
3896
3897void validate_probabilities(qreal* probs, int numProbs, const char* caller) {
3898
3899 // we assume that numProbs>0 was prior validated
3900
3901 /// @todo like above, should we permit -eps <= prob <= 1+eps?
3902
3903 for (int i=0; i<numProbs; i++)
3904 assertThat(probs[i] >= 0 && probs[i] <= 1, report::INVALID_PROBS, caller);
3905
3906 if (isNumericalValidationDisabled())
3907 return;
3908
3909 // check sum=1 using numerically stable sum, because our users deserve the best ;)
3910 // note numProbs is expected small (the caller accepts just as many Quregs) so we
3911 // are safe to allocate this vector without internal checks
3912 qreal total = util_getSum(util_getVector(probs, numProbs));
3913
3914 qreal dist = std::abs(total - 1);
3915 assertThat(dist <= global_validationEpsilon, report::PROBS_DO_NOT_SUM_TO_ONE, caller);
3916}
3917
3918void validate_oneQubitDepashingProb(qreal prob, const char* caller) {
3919

Callers 1

setQuregToMixtureFunction · 0.85

Calls 4

assertThatFunction · 0.85
util_getSumFunction · 0.85
util_getVectorFunction · 0.85

Tested by

no test coverage detected