# HG changeset patch # User Chris Cannam # Date 1618226961 -3600 # Mon Apr 12 12:29:21 2021 +0100 # Node ID a6cb2dc34ad9e145dbb7afb263c89db763266e35 # Parent 13251adcfb3f53ed780093fcf1dc87d4fcee58ba Add min, max, rms diff --git a/bqvec/VectorOps.h b/bqvec/VectorOps.h --- a/bqvec/VectorOps.h +++ b/bqvec/VectorOps.h @@ -1170,6 +1170,60 @@ } /** + * v_min + * + * Return the minimum of the values in the vector \arg vec, of length + * \arg count. For an empty vector, return 0.0. + */ +template +inline T v_min(const T *const BQ_R__ vec, const int count) +{ + if (count == 0) return T(0); + T min = vec[0]; + for (int i = 1; i < count; ++i) { + T v = vec[i]; + if (v < min) min = v; + } + return min; +} + +/** + * v_max + * + * Return the maximum of the values in the vector \arg vec, of length + * \arg count. For an empty vector, return 0.0. + */ +template +inline T v_max(const T *const BQ_R__ vec, const int count) +{ + if (count == 0) return T(0); + T max = vec[0]; + for (int i = 1; i < count; ++i) { + T v = vec[i]; + if (v > max) max = v; + } + return max; +} + +/** + * v_rms + * + * Return the RMS value of the values in the vector \arg vec, of + * length \arg count. For an empty vector, return 0.0. + */ +template +inline T v_rms(const T *const BQ_R__ vec, const int count) +{ + T t = T(0); + if (count == 0) return t; + for (int i = 0; i < count; ++i) { + t += vec[i] * vec[i]; + } + t /= T(count); + return sqrt(t); +} + +/** * v_mean * * Return the mean of the values in the vector \arg vec, of length