| 3895 | } |
| 3896 | |
| 3897 | void 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 | |
| 3918 | void validate_oneQubitDepashingProb(qreal prob, const char* caller) { |
| 3919 |
no test coverage detected