12 #ifndef UTILITY_IMP_H_
13 #define UTILITY_IMP_H_
26 for(
unsigned long i = 0; i < in.n_elem; i++)
28 if (!arma::is_finite(in(i)))
43 float eps=arma::Datum<float>::eps;
44 for(
unsigned long i = 0; i < in.n_elem; i++)
46 if (in(i) <= 0.0f + eps and in(i) >= 0.0f - eps)
63 float eps=arma::Datum<float>::eps,
66 unsigned int total_count = 0;
67 unsigned int count = 0;
68 unsigned int first_five = 0;
69 if (a.n_elem != b.n_elem)
73 for (
unsigned int i = 0; i < a.n_elem; i++)
75 if (!(a(i) <= b(i) + eps and a(i) >= b(i) - eps))
78 if (verbose && first_five <= 5)
80 std::cout.precision(15);
81 std::cout <<
"diff pixel " << i <<
" (" << a(i) <<
" -> " << b(i) <<
")" << std::endl;
85 std::cout <<
"etc..." << std::endl;
95 std::cout << count <<
"/" << total_count <<
" elements differ ("
96 << (
static_cast<float>(count)/total_count)*100.0 <<
"%)" << std::endl;
97 T rms = arma::sqrt(arma::square(a) - arma::square(b));
98 std::cout <<
"Max difference was: " << rms.max() <<
"(epsilon " << eps <<
")" << std::endl;
112 const bool verbose=
false,
113 float eps=arma::Datum<float>::eps)
115 if (a.n_elem != b.n_elem)
119 for (
unsigned int i = 0; i < a.n_elem; i++)
121 if (!(arma::is_finite(a(i))) && !(arma::is_finite(b(i))))
126 if (!(a(i) <= b(i) + eps and a(i) >= b(i) - eps))
147 unsigned int total_count = 0;
148 unsigned int count = 0;
149 unsigned int first_five = 0;
151 if (a.n_elem != b.n_elem)
155 for (
unsigned int i = 0; i < a.n_elem; i++)
160 scale = pow(10.0, -1*ceil(log10(fabs(static_cast<double>(a(i))))));
162 double tolerance = pow(10.0, -1*num_sig_figs);
163 double a_scaled = a(i)*scale;
164 double b_scaled = b(i)*scale;
166 if (!(a_scaled <= b_scaled + tolerance and a_scaled >= b_scaled - tolerance))
172 std::cout.precision(15);
173 std::cout <<
"Diff pixel " << i <<
" (" << a(i) <<
" -> " << b(i) <<
")" << std::endl;
177 std::cout <<
"etc..." << std::endl;
187 float percent_count = (
static_cast<float>(count)/total_count)*100.0;
188 std::cout << count <<
"/" << total_count <<
" elements differ ("
189 << percent_count <<
"%)" << std::endl;
190 T rms = arma::sqrt(arma::square(a) - arma::square(b));
191 std::cout <<
"Max difference was: " << rms.max() <<
"(sig figs " << num_sig_figs <<
")" << std::endl;
192 return percent_count;
void nan_to_zero(T &in)
nan_to_zero removes NaN values from a Armadillo data structure, replacing them with 0...
Definition: utility_imp.h:24
void zero_to_one(T &in)
zero_to_one replaces 0's in an Armadillo data structure with 1's.
Definition: utility_imp.h:41
bool arma_cmp(const T &a, const T &b, const bool verbose, float eps)
arma_cmp compares two Armadillo objects for equality +- epsilon.
Definition: utility_imp.h:110
int arma_cmp_num(const T &a, const T &b, float eps)
float arma_cmp_sig_figs(const T &a, const T &b, int num_sig_figs)
arma_cmp compares two Armadillo objects for equality. Instead of using a tolerance, test number of significant figures.
Definition: utility_imp.h:143