34 using size_type = std::size_t;
43 OpCounter(
const T& t,
typename std::enable_if<std::is_same<T,int>::value
and !std::is_same<F,int>::value>::type* =
nullptr)
65 explicit operator F()
const
84 os <<
"OC(" << f._v <<
")";
88 friend std::istringstream& operator>>(std::istringstream&
iss,
OpCounter& f)
109 size_type addition_count;
110 size_type multiplication_count;
111 size_type division_count;
115 size_type sqrt_count;
116 size_type comparison_count;
120 , multiplication_count(0)
126 , comparison_count(0)
132 multiplication_count = 0;
138 comparison_count = 0;
142 template<
typename Stream>
145 os <<
"additions: " << addition_count << std::endl
146 <<
"multiplications: " << multiplication_count << std::endl
147 <<
"divisions: " << division_count << std::endl
148 <<
"exp: " << exp_count << std::endl
149 <<
"pow: " << pow_count << std::endl
150 <<
"sin: " << sin_count << std::endl
151 <<
"sqrt: " << sqrt_count << std::endl
152 <<
"comparisons: " << comparison_count << std::endl
154 <<
"total: " << addition_count + multiplication_count + division_count + exp_count + pow_count + sin_count + sqrt_count + comparison_count << std::endl;
166 return addition_count + multiplication_count + division_count + exp_count + pow_count + sin_count + sqrt_count + comparison_count;
171 addition_count +=
rhs.addition_count;
172 multiplication_count +=
rhs.multiplication_count;
173 division_count +=
rhs.division_count;
174 exp_count +=
rhs.exp_count;
175 pow_count +=
rhs.pow_count;
176 sin_count +=
rhs.sin_count;
177 sqrt_count +=
rhs.sqrt_count;
178 comparison_count +=
rhs.comparison_count;
182 Counters operator-(
const Counters&
rhs)
185 r.addition_count = addition_count -
rhs.addition_count;
186 r.multiplication_count = multiplication_count -
rhs.multiplication_count;
187 r.division_count = division_count -
rhs.division_count;
188 r.exp_count = exp_count -
rhs.exp_count;
189 r.pow_count = pow_count -
rhs.pow_count;
190 r.sin_count = sin_count -
rhs.sin_count;
191 r.sqrt_count = sqrt_count -
rhs.sqrt_count;
192 r.comparison_count = comparison_count -
rhs.comparison_count;
198 static void additions(std::size_t n)
200 counters.addition_count += n;
203 static void multiplications(std::size_t n)
205 counters.multiplication_count += n;
208 static void divisions(std::size_t n)
210 counters.division_count += n;
219 template<
typename Stream>
228 return counters.totalOperationCount(
doReset);
231 static Counters counters;
236 typename OpCounter<F>::Counters OpCounter<F>::counters;
245 ++OpCounter<F>::counters.addition_count;
255 OpCounter<F> operator+(
const OpCounter<F>& a,
const OpCounter<F>& b)
257 ++OpCounter<F>::counters.addition_count;
258 return {a._v + b._v};
262 OpCounter<F> operator+(
const OpCounter<F>& a,
const F& b)
264 ++OpCounter<F>::counters.addition_count;
269 OpCounter<F> operator+(
const F& a,
const OpCounter<F>& b)
271 ++OpCounter<F>::counters.addition_count;
275 template<
typename F,
typename T>
276 typename std::enable_if<
277 std::is_arithmetic<T>::value,
280 operator+(
const OpCounter<F>& a,
const T& b)
282 ++OpCounter<F>::counters.addition_count;
286 template<
typename F,
typename T>
287 typename std::enable_if<
288 std::is_arithmetic<T>::value,
291 operator+(
const T& a,
const OpCounter<F>& b)
293 ++OpCounter<F>::counters.addition_count;
298 OpCounter<F>& operator+=(OpCounter<F>& a,
const OpCounter<F>& b)
300 ++OpCounter<F>::counters.addition_count;
306 OpCounter<F>& operator+=(OpCounter<F>& a,
const F& b)
308 ++OpCounter<F>::counters.addition_count;
313 template<
typename F,
typename T>
314 typename std::enable_if<
315 std::is_arithmetic<T>::value,
318 operator+=(OpCounter<F>& a,
const T& b)
320 ++OpCounter<F>::counters.addition_count;
330 OpCounter<F> operator-(
const OpCounter<F>& a,
const OpCounter<F>& b)
332 ++OpCounter<F>::counters.addition_count;
333 return {a._v - b._v};
337 OpCounter<F> operator-(
const OpCounter<F>& a,
const F& b)
339 ++OpCounter<F>::counters.addition_count;
344 OpCounter<F> operator-(
const F& a,
const OpCounter<F>& b)
346 ++OpCounter<F>::counters.addition_count;
350 template<
typename F,
typename T>
351 typename std::enable_if<
352 std::is_arithmetic<T>::value,
355 operator-(
const OpCounter<F>& a,
const T& b)
357 ++OpCounter<F>::counters.addition_count;
361 template<
typename F,
typename T>
362 typename std::enable_if<
363 std::is_arithmetic<T>::value,
366 operator-(
const T& a,
const OpCounter<F>& b)
368 ++OpCounter<F>::counters.addition_count;
373 OpCounter<F>& operator-=(OpCounter<F>& a,
const OpCounter<F>& b)
375 ++OpCounter<F>::counters.addition_count;
381 OpCounter<F>& operator-=(OpCounter<F>& a,
const F& b)
383 ++OpCounter<F>::counters.addition_count;
388 template<
typename F,
typename T>
389 typename std::enable_if<
390 std::is_arithmetic<T>::value,
393 operator-=(OpCounter<F>& a,
const T& b)
395 ++OpCounter<F>::counters.addition_count;
406 OpCounter<F> operator*(
const OpCounter<F>& a,
const OpCounter<F>& b)
408 ++OpCounter<F>::counters.multiplication_count;
409 return {a._v * b._v};
413 OpCounter<F> operator*(
const OpCounter<F>& a,
const F& b)
415 ++OpCounter<F>::counters.multiplication_count;
420 OpCounter<F> operator*(
const F& a,
const OpCounter<F>& b)
422 ++OpCounter<F>::counters.multiplication_count;
426 template<
typename F,
typename T>
427 typename std::enable_if<
428 std::is_arithmetic<T>::value,
431 operator*(
const OpCounter<F>& a,
const T& b)
433 ++OpCounter<F>::counters.multiplication_count;
437 template<
typename F,
typename T>
438 typename std::enable_if<
439 std::is_arithmetic<T>::value,
442 operator*(
const T& a,
const OpCounter<F>& b)
444 ++OpCounter<F>::counters.multiplication_count;
449 OpCounter<F>& operator*=(OpCounter<F>& a,
const OpCounter<F>& b)
451 ++OpCounter<F>::counters.multiplication_count;
457 OpCounter<F>& operator*=(OpCounter<F>& a,
const F& b)
459 ++OpCounter<F>::counters.multiplication_count;
464 template<
typename F,
typename T>
465 typename std::enable_if<
466 std::is_arithmetic<T>::value,
469 operator*=(OpCounter<F>& a,
const T& b)
471 ++OpCounter<F>::counters.multiplication_count;
482 OpCounter<F> operator/(
const OpCounter<F>& a,
const OpCounter<F>& b)
484 ++OpCounter<F>::counters.division_count;
485 return {a._v / b._v};
489 OpCounter<F> operator/(
const OpCounter<F>& a,
const F& b)
491 ++OpCounter<F>::counters.division_count;
496 OpCounter<F> operator/(
const F& a,
const OpCounter<F>& b)
498 ++OpCounter<F>::counters.division_count;
502 template<
typename F,
typename T>
503 typename std::enable_if<
504 std::is_arithmetic<T>::value,
507 operator/(
const OpCounter<F>& a,
const T& b)
509 ++OpCounter<F>::counters.division_count;
513 template<
typename F,
typename T>
514 typename std::enable_if<
515 std::is_arithmetic<T>::value,
518 operator/(
const T& a,
const OpCounter<F>& b)
520 ++OpCounter<F>::counters.division_count;
525 OpCounter<F>& operator/=(OpCounter<F>& a,
const OpCounter<F>& b)
527 ++OpCounter<F>::counters.division_count;
533 OpCounter<F>& operator/=(OpCounter<F>& a,
const F& b)
535 ++OpCounter<F>::counters.division_count;
540 template<
typename F,
typename T>
541 typename std::enable_if<
542 std::is_arithmetic<T>::value,
545 operator/=(OpCounter<F>& a,
const T& b)
547 ++OpCounter<F>::counters.division_count;
564 bool operator<(
const OpCounter<F>& a,
const OpCounter<F>& b)
566 ++OpCounter<F>::counters.comparison_count;
567 return {a._v < b._v};
571 bool operator<(
const OpCounter<F>& a,
const F& b)
573 ++OpCounter<F>::counters.comparison_count;
578 bool operator<(
const F& a,
const OpCounter<F>& b)
580 ++OpCounter<F>::counters.comparison_count;
584 template<
typename F,
typename T>
585 bool operator<(
const OpCounter<F>& a,
const T& b)
587 ++OpCounter<F>::counters.comparison_count;
591 template<
typename F,
typename T>
592 bool operator<(
const T& a,
const OpCounter<F>& b)
594 ++OpCounter<F>::counters.comparison_count;
604 bool operator<=(
const OpCounter<F>& a,
const OpCounter<F>& b)
606 ++OpCounter<F>::counters.comparison_count;
607 return {a._v <= b._v};
611 bool operator<=(
const OpCounter<F>& a,
const F& b)
613 ++OpCounter<F>::counters.comparison_count;
618 bool operator<=(
const F& a,
const OpCounter<F>& b)
620 ++OpCounter<F>::counters.comparison_count;
624 template<
typename F,
typename T>
625 bool operator<=(
const OpCounter<F>& a,
const T& b)
627 ++OpCounter<F>::counters.comparison_count;
631 template<
typename F,
typename T>
632 bool operator<=(
const T& a,
const OpCounter<F>& b)
634 ++OpCounter<F>::counters.comparison_count;
644 bool operator>(
const OpCounter<F>& a,
const OpCounter<F>& b)
646 ++OpCounter<F>::counters.comparison_count;
647 return {a._v > b._v};
651 bool operator>(
const OpCounter<F>& a,
const F& b)
653 ++OpCounter<F>::counters.comparison_count;
658 bool operator>(
const F& a,
const OpCounter<F>& b)
660 ++OpCounter<F>::counters.comparison_count;
664 template<
typename F,
typename T>
665 bool operator>(
const OpCounter<F>& a,
const T& b)
667 ++OpCounter<F>::counters.comparison_count;
671 template<
typename F,
typename T>
672 bool operator>(
const T& a,
const OpCounter<F>& b)
674 ++OpCounter<F>::counters.comparison_count;
684 bool operator>=(
const OpCounter<F>& a,
const OpCounter<F>& b)
686 ++OpCounter<F>::counters.comparison_count;
687 return {a._v >= b._v};
691 bool operator>=(
const OpCounter<F>& a,
const F& b)
693 ++OpCounter<F>::counters.comparison_count;
698 bool operator>=(
const F& a,
const OpCounter<F>& b)
700 ++OpCounter<F>::counters.comparison_count;
704 template<
typename F,
typename T>
705 bool operator>=(
const OpCounter<F>& a,
const T& b)
707 ++OpCounter<F>::counters.comparison_count;
711 template<
typename F,
typename T>
712 bool operator>=(
const T& a,
const OpCounter<F>& b)
714 ++OpCounter<F>::counters.comparison_count;
724 bool operator!=(
const OpCounter<F>& a,
const OpCounter<F>& b)
726 ++OpCounter<F>::counters.comparison_count;
727 return {a._v != b._v};
731 bool operator!=(
const OpCounter<F>& a,
const F& b)
733 ++OpCounter<F>::counters.comparison_count;
738 bool operator!=(
const F& a,
const OpCounter<F>& b)
740 ++OpCounter<F>::counters.comparison_count;
744 template<
typename F,
typename T>
745 bool operator!=(
const OpCounter<F>& a,
const T& b)
747 ++OpCounter<F>::counters.comparison_count;
751 template<
typename F,
typename T>
752 bool operator!=(
const T& a,
const OpCounter<F>& b)
754 ++OpCounter<F>::counters.comparison_count;
764 bool operator==(
const OpCounter<F>& a,
const OpCounter<F>& b)
766 ++OpCounter<F>::counters.comparison_count;
767 return {a._v == b._v};
771 bool operator==(
const OpCounter<F>& a,
const F& b)
773 ++OpCounter<F>::counters.comparison_count;
778 bool operator==(
const F& a,
const OpCounter<F>& b)
780 ++OpCounter<F>::counters.comparison_count;
784 template<
typename F,
typename T>
785 bool operator==(
const OpCounter<F>& a,
const T& b)
787 ++OpCounter<F>::counters.comparison_count;
791 template<
typename F,
typename T>
792 bool operator==(
const T& a,
const OpCounter<F>& b)
794 ++OpCounter<F>::counters.comparison_count;
805 OpCounter<F> exp(
const OpCounter<F>& a)
807 ++OpCounter<F>::counters.exp_count;
808 return {std::exp(a._v)};
812 OpCounter<F> pow(
const OpCounter<F>& a,
const OpCounter<F>& b)
814 ++OpCounter<F>::counters.pow_count;
815 return {std::pow(a._v,b._v)};
819 OpCounter<F> pow(
const OpCounter<F>& a,
const F& b)
821 ++OpCounter<F>::counters.pow_count;
822 return {std::pow(a._v,b)};
825 template<
typename F,
typename T>
826 OpCounter<F> pow(
const OpCounter<F>& a,
const T& b)
828 ++OpCounter<F>::counters.pow_count;
829 return {std::pow(a._v,b)};
833 OpCounter<F> pow(
const F& a,
const OpCounter<F>& b)
835 ++OpCounter<F>::counters.pow_count;
836 return {std::pow(a,b._v)};
839 template<
typename F,
typename T>
840 OpCounter<F> pow(
const T& a,
const OpCounter<F>& b)
842 ++OpCounter<F>::counters.pow_count;
843 return {std::pow(a,b._v)};
847 OpCounter<F> sin(
const OpCounter<F>& a)
849 ++OpCounter<F>::counters.sin_count;
850 return {std::sin(a._v)};
854 OpCounter<F> cos(
const OpCounter<F>& a)
856 ++OpCounter<F>::counters.sin_count;
857 return {std::cos(a._v)};
861 OpCounter<F> sqrt(
const OpCounter<F>& a)
863 ++OpCounter<F>::counters.sqrt_count;
864 return {std::sqrt(a._v)};
868 OpCounter<F>
abs(
const OpCounter<F>& a)
870 ++OpCounter<F>::counters.comparison_count;
871 return {std::abs(a._v)};
Class with mathematical matrix operations.
Definition densematrix.hh:33
Definition opcounter.hh:30
static size_type totalOperationCount(bool doReset=false)
Return total number of operations.
Definition opcounter.hh:226
static void reportOperations(Stream &os, bool doReset=false)
Report operations to stream object.
Definition opcounter.hh:220
T abs(const T &t)
our own abs class that works also for multiprecision types
Definition lr.hh:55
Struct storing the number of operations.
Definition opcounter.hh:107
void reportOperations(Stream &os, bool doReset=false)
Report operations to stream object.
Definition opcounter.hh:143
size_type totalOperationCount(bool doReset=false)
Get total number of operations.
Definition opcounter.hh:161