| 248 | /// \return the number of errors |
| 249 | template <typename T> |
| 250 | inline int compare_vectors(buffer<T>& y, buffer<T>& y_ref, int print_errors = 16, float abs_tol = 1e-1, float rel_tol = 1e-1){ |
| 251 | int total_errors = 0; |
| 252 | for (int i = 0; i < y.size(); i++){ |
| 253 | if (std::abs(y[i] - y_ref[i]) > abs_tol && std::abs(y[i] - y_ref[i]) / std::abs(y_ref[i]) > rel_tol){ |
| 254 | if (total_errors < print_errors){ |
| 255 | header_print("err ", "Error: y[" << i << "] = " << y[i] << " != y_ref[" << i << "] = " << y_ref[i]); |
| 256 | } |
| 257 | total_errors++; |
| 258 | } |
| 259 | } |
| 260 | if (total_errors > 0){ |
| 261 | header_print("err ", "Total errors: " << total_errors); |
| 262 | } |
| 263 | return total_errors; |
| 264 | } |
| 265 | |
| 266 | /// \brief print the matrix |
| 267 | /// \param matrix the matrix |