diff options
author | Erik Schnetter <schnetter@cct.lsu.edu> | 2010-04-26 18:02:33 -0500 |
---|---|---|
committer | Barry Wardell <barry.wardell@gmail.com> | 2011-12-14 16:45:40 +0000 |
commit | 8d523eaf8968d1a3edebb3bf54401c5c45432645 (patch) | |
tree | c5e3cb1f25f8dc6ef7eb68a36a60d94faf434c5a | |
parent | 9d6a57b44aecc62cc20f6c66850fadeac9832521 (diff) |
CarpetLib: Add minloc1 and maxloc1 to vect class
-rw-r--r-- | Carpet/CarpetLib/src/vect.hh | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Carpet/CarpetLib/src/vect.hh b/Carpet/CarpetLib/src/vect.hh index d7d648b7a..9f6ad4ef4 100644 --- a/Carpet/CarpetLib/src/vect.hh +++ b/Carpet/CarpetLib/src/vect.hh @@ -474,6 +474,18 @@ inline int maxloc (const vect<T,D>& a) return r; } +/** Return the index of the last maximum element. */ +template<typename T,int D> +inline int maxloc1 (const vect<T,D>& a) CCTK_ATTRIBUTE_PURE; +template<typename T,int D> +inline int maxloc1 (const vect<T,D>& a) +{ + ASSERT_VECT (D>0); + int r(D-1); + for (int d=D-2; d>=0; --d) if (a[d]>a[r]) r=d; + return r; +} + /** Return the index of the first minimum element. */ template<typename T,int D> inline int minloc (const vect<T,D>& a) CCTK_ATTRIBUTE_PURE; @@ -486,6 +498,18 @@ inline int minloc (const vect<T,D>& a) return r; } +/** Return the index of the last minimum element. */ +template<typename T,int D> +inline int minloc1 (const vect<T,D>& a) CCTK_ATTRIBUTE_PURE; +template<typename T,int D> +inline int minloc1 (const vect<T,D>& a) +{ + ASSERT_VECT (D>0); + int r(D-1); + for (int d=D-2; d>=0; --d) if (a[d]<a[r]) r=d; + return r; +} + /** Return the n-dimensional linear array index. */ template<typename T,int D> inline T index (const vect<T,D>& lsh, const vect<T,D>& ind) CCTK_ATTRIBUTE_PURE; |