maximum absolute asymmetry between a and b asymmetry: (a - b) / (a + b) This is more stable than relative error if one of the values fluctuates towards zero. n: number of values to compare. expected_vals: optional vector of expected values for a. If expected_vals is not empty, filter out all comparisons where a does not match any of the expected values. Needed for noncontinuous gradients where the
| 196 | // expected_vals: optional vector of expected values for a. If expected_vals is not empty, filter out all comparisons where |
| 197 | // a does not match any of the expected values. Needed for noncontinuous gradients where the numerical calculation can fail. |
| 198 | static double mean_abs_asymm(const float * a, const float * b, const size_t n, const std::vector<float> & expected_vals) { |
| 199 | double sum = 0.0f; |
| 200 | |
| 201 | size_t nvalid = 0; |
| 202 | for (size_t i = 0; i < n; i++) { |
| 203 | if (!expected_vals.empty()) { |
| 204 | bool matches_any = false; |
| 205 | for (const float & ev : expected_vals) { |
| 206 | if (fabsf(a[i] - ev) < 1e-3f) { |
| 207 | matches_any = true; |
| 208 | break; |
| 209 | } |
| 210 | } |
| 211 | if (!matches_any) { |
| 212 | continue; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | const float asymm = (a[i] - b[i]) / (a[i] + b[i]); |
| 217 | |
| 218 | sum += fabsf(asymm); |
| 219 | nvalid++; |
| 220 | } |
| 221 | |
| 222 | return sum/nvalid; |
| 223 | } |
| 224 | |
| 225 | // utils for printing the variables of the test cases |
| 226 |