aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@cct.lsu.edu>2010-04-26 18:02:33 -0500
committerBarry Wardell <barry.wardell@gmail.com>2011-12-14 16:45:40 +0000
commit8d523eaf8968d1a3edebb3bf54401c5c45432645 (patch)
treec5e3cb1f25f8dc6ef7eb68a36a60d94faf434c5a
parent9d6a57b44aecc62cc20f6c66850fadeac9832521 (diff)
CarpetLib: Add minloc1 and maxloc1 to vect class
-rw-r--r--Carpet/CarpetLib/src/vect.hh24
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;