diff options
Diffstat (limited to 'src/jtutil')
-rw-r--r-- | src/jtutil/README | 6 | ||||
-rw-r--r-- | src/jtutil/array.cc | 67 | ||||
-rw-r--r-- | src/jtutil/array.hh | 21 | ||||
-rw-r--r-- | src/jtutil/cpm_map.cc | 27 | ||||
-rw-r--r-- | src/jtutil/cpm_map.hh | 12 | ||||
-rw-r--r-- | src/jtutil/error_exit.cc | 17 | ||||
-rw-r--r-- | src/jtutil/fuzzy.cc | 33 | ||||
-rw-r--r-- | src/jtutil/linear_map.cc | 36 | ||||
-rw-r--r-- | src/jtutil/linear_map.hh | 12 | ||||
-rw-r--r-- | src/jtutil/make.code.defn | 14 | ||||
-rw-r--r-- | src/jtutil/miscfp.cc | 39 | ||||
-rw-r--r-- | src/jtutil/norm.cc | 31 | ||||
-rw-r--r-- | src/jtutil/round.cc | 26 | ||||
-rw-r--r-- | src/jtutil/test_array.cc | 2 | ||||
-rw-r--r-- | src/jtutil/test_array2.cc | 2 | ||||
-rw-r--r-- | src/jtutil/test_cpm_map.cc | 3 | ||||
-rw-r--r-- | src/jtutil/test_error_exit.cc | 2 | ||||
-rw-r--r-- | src/jtutil/test_fuzzy.cc | 3 | ||||
-rw-r--r-- | src/jtutil/test_linear_map.cc | 3 | ||||
-rw-r--r-- | src/jtutil/test_modulo.cc | 3 | ||||
-rw-r--r-- | src/jtutil/test_norm.cc | 3 | ||||
-rw-r--r-- | src/jtutil/test_round.cc | 2 | ||||
-rw-r--r-- | src/jtutil/util.hh | 5 |
23 files changed, 166 insertions, 203 deletions
diff --git a/src/jtutil/README b/src/jtutil/README index 31ac7aa..1b6ea5e 100644 --- a/src/jtutil/README +++ b/src/jtutil/README @@ -1,8 +1,6 @@ This directory holds low-level utility code in the C++ namespace jtutil::. -Apart from this namespace being inside this thorn's global AHFinderDirect:: -namespace, this code isn't specific to this project -- it's things like -min/max templates, multidimensional array classes, fuzzy arithmetic -routines, etc. +This code is not specific to this project -- it's things like min/max +templates, multidimensional array classes, fuzzy arithmetic routines, etc. array<fp> is a template class (templated on the integer or floating-point diff --git a/src/jtutil/array.cc b/src/jtutil/array.cc index c8e5c47..b6fbc99 100644 --- a/src/jtutil/array.cc +++ b/src/jtutil/array.cc @@ -33,12 +33,6 @@ #include "util.hh" #include "array.hh" -// everything in this file is inside these namespaces -namespace AHFinderDirect - { -namespace jtutil - { - //****************************************************************************** //****************************************************************************** //****************************************************************************** @@ -46,6 +40,8 @@ namespace jtutil // // This function constructs an array1d object. // +namespace jtutil + { template <typename T> array1d<T>::array1d(int min_i_in, int max_i_in, T *array_in /* = NULL */, @@ -77,18 +73,22 @@ if (we_own_array_) operator()(i) = T(0); } } + } // namespace jtutil:: //****************************************************************************** // // This function destroys an array1d object. // +namespace jtutil + { template <typename T> array1d<T>::~array1d() { if (we_own_array_) then delete[] array_; } + } // namespace jtutil:: //****************************************************************************** //****************************************************************************** @@ -97,6 +97,8 @@ if (we_own_array_) // // This function constructs an array2d object. // +namespace jtutil + { template <typename T> array2d<T>::array2d(int min_i_in, int max_i_in, int min_j_in, int max_j_in, @@ -135,18 +137,22 @@ if (we_own_array_) } } } + } // namespace jtutil:: //****************************************************************************** // // This function destroys an array2d object. // +namespace jtutil + { template <typename T> array2d<T>::~array2d() { if (we_own_array_) then delete[] array_; } + } // namespace jtutil:: //****************************************************************************** //****************************************************************************** @@ -155,6 +161,8 @@ if (we_own_array_) // // This function constructs an array3d object. // +namespace jtutil + { template <typename T> array3d<T>::array3d(int min_i_in, int max_i_in, int min_j_in, int max_j_in, @@ -202,18 +210,22 @@ if (we_own_array_) } } } + } // namespace jtutil:: //****************************************************************************** // // This function destroys an array3d object. // +namespace jtutil + { template <typename T> array3d<T>::~array3d() { if (we_own_array_) then delete[] array_; } + } // namespace jtutil:: //****************************************************************************** //****************************************************************************** @@ -223,6 +235,8 @@ if (we_own_array_) // // This function constructs an array4d object. // +namespace jtutil + { template <typename T> array4d<T>::array4d(int min_i_in, int max_i_in, int min_j_in, int max_j_in, @@ -278,6 +292,7 @@ if (we_own_array_) } } } + } // namespace jtutil:: #endif /* NOT_USED */ //****************************************************************************** @@ -286,12 +301,15 @@ if (we_own_array_) // // This function destroys an array4d object. // +namespace jtutil + { template <typename T> array4d<T>::~array4d() { if (we_own_array_) then delete[] array_; } + } // namespace jtutil:: #endif /* NOT_USED */ //****************************************************************************** @@ -302,40 +320,33 @@ if (we_own_array_) // ***** template instantiations ***** // -template class array1d<int>; +template class jtutil::array1d<int>; // FIXME: we shouldn't have to instantiate these both, the const one // is actually trivially derivable from the non-const one. :( -template class array1d< void *>; -template class array1d<const void *>; +template class jtutil::array1d< void *>; +template class jtutil::array1d<const void *>; #ifdef STANDALONE_TEST - template class array1d<float>; - template class array2d<float>; - template class array3d<float>; + template class jtutil::array1d<float>; + template class jtutil::array2d<float>; + template class jtutil::array3d<float>; #ifdef NOT_USED - template class array4d<float>; + template class jtutil::array4d<float>; #endif - template class array1d<double>; - template class array2d<double>; - template class array3d<double>; + template class jtutil::array1d<double>; + template class jtutil::array2d<double>; + template class jtutil::array3d<double>; #ifdef NOT_USED - template class array4d<double>; + template class jtutil::array4d<double>; #endif #else // full-fledged Cactus thorn - template class array1d<CCTK_REAL>; + template class jtutil::array1d<CCTK_REAL>; - template class array2d<CCTK_INT>; - template class array2d<CCTK_REAL>; + template class jtutil::array2d<CCTK_INT>; + template class jtutil::array2d<CCTK_REAL>; - template class array3d<CCTK_REAL>; + template class jtutil::array3d<CCTK_REAL>; #endif - -//****************************************************************************** -//****************************************************************************** -//****************************************************************************** - - } // namespace jtutil - } // namespace AHFinderDirect diff --git a/src/jtutil/array.hh b/src/jtutil/array.hh index 14a023e..bf70628 100644 --- a/src/jtutil/array.hh +++ b/src/jtutil/array.hh @@ -62,14 +62,10 @@ // #endif -// everything in this file is inside these namespaces -namespace AHFinderDirect - { -namespace jtutil - { - //****************************************************************************** +namespace jtutil + { template <typename T> class array1d { @@ -150,9 +146,12 @@ private: bool we_own_array_; // true ==> array_ --> new[] array which we own // false ==> array_ --> client-owned storage }; + } // namespace jtutil:: //****************************************************************************** +namespace jtutil + { template <typename T> class array2d { @@ -244,9 +243,12 @@ private: bool we_own_array_; // true ==> array_ --> new[] array which we own // false ==> array_ --> client-owned storage }; + } // namespace jtutil:: //****************************************************************************** +namespace jtutil + { template <typename T> class array3d { @@ -346,10 +348,13 @@ private: bool we_own_array_; // true ==> array_ --> new[] array which we own // false ==> array_ --> client-owned storage }; + } // namespace jtutil:: //****************************************************************************** #ifdef NOT_USED +namespace jtutil + { template <typename T> class array4d { @@ -464,11 +469,9 @@ private: bool we_own_array_; // true ==> array_ --> new[] array which we own // false ==> array_ --> client-owned storage }; + } // namespace jtutil:: #endif /* NOT_USED */ //****************************************************************************** - } // namespace jtutil - } // namespace AHFinderDirect - #endif /* AHFINDERDIRECT__ARRAY_HH */ diff --git a/src/jtutil/cpm_map.cc b/src/jtutil/cpm_map.cc index 1a44b20..09ab35a 100644 --- a/src/jtutil/cpm_map.cc +++ b/src/jtutil/cpm_map.cc @@ -14,12 +14,7 @@ #include "stdc.h" #include "util.hh" #include "cpm_map.hh" - -// everything in this file is inside these namespaces -namespace AHFinderDirect - { -namespace jtutil - { +using jtutil::error_exit; //****************************************************************************** //****************************************************************************** @@ -30,6 +25,8 @@ namespace jtutil // specified fixed point (must be integer or half-integer) and domain. // The sample point need not be in the map's domain/range. // +namespace jtutil + { template <typename fp_t> cpm_map<fp_t>::cpm_map(int min_i_in, int max_i_in, fp_t fixed_point) @@ -53,6 +50,7 @@ assert( fuzzy<fp_t>::ceiling(fixed_point) ); } + } // namespace jtutil:: //****************************************************************************** @@ -61,6 +59,8 @@ assert( // specified by a sample point sample_i --> sample_j and by sign. // The sample point need not be in the map's domain/range. // +namespace jtutil + { template <typename fp_t> cpm_map<fp_t>::cpm_map(int min_i_in, int max_i_in, int sample_i, int sample_j, @@ -73,6 +73,7 @@ cpm_map<fp_t>::cpm_map(int min_i_in, int max_i_in, // verify that we have setup correct assert( map_unchecked(sample_i) == sample_j ); } + } // namespace jtutil:: //****************************************************************************** @@ -84,6 +85,8 @@ assert( map_unchecked(sample_i) == sample_j ); // is never ok) and by sign. The sample point need not be in the map's // domain/range. // +namespace jtutil + { template <typename fp_t> cpm_map<fp_t>::cpm_map(int min_i_in, int max_i_in, fp_t sample_i, fp_t sample_j, @@ -112,6 +115,7 @@ assert( (map_is_plus_in ? fuzzy<fp_t>::floor (sample_j) : fuzzy<fp_t>::ceiling(sample_j)) ); } + } // namespace jtutil:: //****************************************************************************** //****************************************************************************** @@ -121,12 +125,5 @@ assert( // ***** template instantiations ***** // -template class cpm_map<float>; -template class cpm_map<double>; - -//****************************************************************************** -//****************************************************************************** -//****************************************************************************** - - } // namespace jtutil - } // namespace AHFinderDirect +template class jtutil::cpm_map<float>; +template class jtutil::cpm_map<double>; diff --git a/src/jtutil/cpm_map.hh b/src/jtutil/cpm_map.hh index 1c63e8d..6b14ab3 100644 --- a/src/jtutil/cpm_map.hh +++ b/src/jtutil/cpm_map.hh @@ -25,14 +25,10 @@ // #endif -// everything in this file is inside these namespaces -namespace AHFinderDirect - { -namespace jtutil - { - //****************************************************************************** +namespace jtutil + { template <typename fp_t> class cpm_map { @@ -136,10 +132,8 @@ private: int offset_; bool map_is_plus_; }; + } // namespace jtutil:: //****************************************************************************** - } // namespace jtutil - } // namespace AHFinderDirect - #endif /* AHFINDERDIRECT__CPM_MAP_HH */ diff --git a/src/jtutil/error_exit.cc b/src/jtutil/error_exit.cc index ffffa1e..fd8e2d8 100644 --- a/src/jtutil/error_exit.cc +++ b/src/jtutil/error_exit.cc @@ -18,12 +18,6 @@ #include "config.h" #include "stdc.h" -// everything in this file is inside these namespaces -namespace AHFinderDirect - { -namespace jtutil - { - //****************************************************************************** // @@ -54,6 +48,9 @@ namespace jtutil // args... = (in) Any additional arguments are (presumably) used in formatting // the error message string. // +namespace jtutil + { +extern "C" /*VARARGS*/ int error_exit(int msg_level, const char *format, ...) { @@ -78,14 +75,10 @@ if ((len > 0) && (buffer[len-1] == '\n')) then abort(); else exit(msg_level); #else - CCTK_VWarn(msg_level, __LINE__, __FILE__, CCTK_THORNSTRING, "%s", buffer); + CCTK_VWarn(0, __LINE__, __FILE__, CCTK_THORNSTRING, "%s", buffer); #endif // if we got here, evidently msg_level wasn't drastic enough abort(); /*NOTREACHED*/ } - -//****************************************************************************** - - } // namespace jtutil - } // namespace AHFinderDirect + } // namespace jtutil:: diff --git a/src/jtutil/fuzzy.cc b/src/jtutil/fuzzy.cc index e444c30..d3e4314 100644 --- a/src/jtutil/fuzzy.cc +++ b/src/jtutil/fuzzy.cc @@ -11,39 +11,40 @@ // #include <stdlib.h> -#include <stdio.h> #include "stdc.h" #include "util.hh" -// everything in this file is inside these namespaces -namespace AHFinderDirect - { -namespace jtutil - { - //****************************************************************************** +namespace jtutil + { template <typename fp_t> bool fuzzy<fp_t>::EQ(fp_t x, fp_t y) { -fp_t max_abs = max(jtutil::abs(x), jtutil::abs(y)); -fp_t epsilon = max(tolerance_, tolerance_*max_abs); +fp_t max_abs = jtutil::max(jtutil::abs(x), jtutil::abs(y)); +fp_t epsilon = jtutil::max(tolerance_, tolerance_*max_abs); return jtutil::abs(x-y) <= epsilon; } + } // namespace jtutil:: //****************************************************************************** +namespace jtutil + { template <typename fp_t> bool fuzzy<fp_t>::is_integer(fp_t x) { int i = round<fp_t>::to_integer(x); return EQ(x, fp_t(i)); } + } // namespace jtutil:: //****************************************************************************** +namespace jtutil + { template <typename fp_t> int fuzzy<fp_t>::floor(fp_t x) { @@ -51,9 +52,12 @@ return fuzzy<fp_t>::is_integer(x) ? round<fp_t>::to_integer(x) : round<fp_t>::floor(x); } + } // namespace jtutil:: //****************************************************************************** +namespace jtutil + { template <typename fp_t> int fuzzy<fp_t>::ceiling(fp_t x) { @@ -61,6 +65,7 @@ return fuzzy<fp_t>::is_integer(x) ? round<fp_t>::to_integer(x) : round<fp_t>::ceiling(x); } + } // namespace jtutil:: //****************************************************************************** //****************************************************************************** @@ -75,6 +80,8 @@ return fuzzy<fp_t>::is_integer(x) // me figure out the correct syntax here! // +namespace jtutil + { // initializations of fuzzy::tolerance for each instantation we're going to make template <> float fuzzy<float>::tolerance_ = 1.0e-5; // about 100 * FLT_EPSILON @@ -85,10 +92,4 @@ template <> // template instantiations template class fuzzy<float>; template class fuzzy<double>; - -//****************************************************************************** -//****************************************************************************** -//****************************************************************************** - - } // namespace jtutil - } // namespace AHFinderDirect + } // namespace jtutil:: diff --git a/src/jtutil/linear_map.cc b/src/jtutil/linear_map.cc index b44b466..636675e 100644 --- a/src/jtutil/linear_map.cc +++ b/src/jtutil/linear_map.cc @@ -16,12 +16,7 @@ #include "stdc.h" #include "util.hh" #include "linear_map.hh" - -// everything in this file is inside these namespaces -namespace AHFinderDirect - { -namespace jtutil - { +using jtutil::error_exit; //****************************************************************************** //****************************************************************************** @@ -32,6 +27,8 @@ namespace jtutil // // This function constructs a linear_map<fp_t> object. // +namespace jtutil + { template <typename fp_t> linear_map<fp_t>::linear_map(int min_int_in, int max_int_in, fp_t min_fp_in, fp_t delta_fp_in, fp_t max_fp_in) @@ -40,6 +37,7 @@ linear_map<fp_t>::linear_map(int min_int_in, int max_int_in, { constructor_common(min_fp_in, max_fp_in); } + } // namespace jtutil:: //****************************************************************************** @@ -47,6 +45,8 @@ constructor_common(min_fp_in, max_fp_in); // This function constructs a linear_map<fp_t> object with a subrange // of an existing one. // +namespace jtutil + { template <typename fp_t> linear_map<fp_t>::linear_map(const linear_map<fp_t> &lm_in, int min_int_in, int max_int_in) // subrange @@ -65,6 +65,7 @@ if (! (is_in_range(min_int_in) && is_in_range(max_int_in)) ) constructor_common(lm_in.fp_of_int_unchecked(min_int_in), lm_in.fp_of_int_unchecked(max_int_in)); } + } // namespace jtutil:: //****************************************************************************** @@ -72,6 +73,8 @@ constructor_common(lm_in.fp_of_int_unchecked(min_int_in), // This function does the common argument validation and setup for // all the constructors of class linear_map<fp_t>:: . // +namespace jtutil + { template <typename fp_t> void linear_map<fp_t>::constructor_common(fp_t min_fp_in, fp_t max_fp_in) // assumes @@ -98,6 +101,7 @@ if (fuzzy<fp_t>::NE(fp_of_int_unchecked(max_int()), max_fp_in)) double(min_fp_in), double(delta_fp()), double(max_fp_in)); /*NOTREACHED*/ } + } // namespace jtutil:: //****************************************************************************** @@ -105,6 +109,8 @@ if (fuzzy<fp_t>::NE(fp_of_int_unchecked(max_int()), max_fp_in)) // This function converts fp --> int coordinate, returning the result // as an fp (which need not be fuzzily integral). // +namespace jtutil + { template <typename fp_t> fp_t linear_map<fp_t>::fp_int_of_fp(fp_t x) const @@ -121,6 +127,7 @@ if (! is_in_range(x)) return inverse_delta_ * (x - origin_); } + } // namespace jtutil:: //****************************************************************************** @@ -133,6 +140,8 @@ return inverse_delta_ * (x - origin_); // Having to explicitly specify the namespace for jtutil::round<fp_t>:: // is ++ugly. :( // +namespace jtutil + { template <typename fp_t> int linear_map<fp_t>::int_of_fp(fp_t x, noninteger_action nia /* = nia_error */) const @@ -187,6 +196,7 @@ default: return 0; // dummy return to quiet gcc // (which doesn't grok that error_exit() never returns) } + } // namespace jtutil:: //****************************************************************************** @@ -200,6 +210,8 @@ return 0; // dummy return to quiet gcc // Having to explicitly specify the namespace for jtutil::round<fp_t>:: // is ++ugly. :( // +namespace jtutil + { template <typename fp_t> int linear_map<fp_t>::delta_int_of_delta_fp (fp_t delta_x, noninteger_action nia /* = nia_error */) @@ -259,6 +271,7 @@ default: return 0; // dummy return to quiet gcc // (which doesn't grok that error_exit() never returns) } + } // namespace jtutil:: //****************************************************************************** //****************************************************************************** @@ -268,12 +281,5 @@ return 0; // dummy return to quiet gcc // ***** template instantiation ***** // -template class linear_map<float>; -template class linear_map<double>; - -//****************************************************************************** -//****************************************************************************** -//****************************************************************************** - - } // namespace jtutil - } // namespace AHFinderDirect +template class jtutil::linear_map<float>; +template class jtutil::linear_map<double>; diff --git a/src/jtutil/linear_map.hh b/src/jtutil/linear_map.hh index 6125a36..48c0f2d 100644 --- a/src/jtutil/linear_map.hh +++ b/src/jtutil/linear_map.hh @@ -26,14 +26,10 @@ // #endif -// everything in this file is inside these namespaces -namespace AHFinderDirect - { -namespace jtutil - { - //***************************************************************************** +namespace jtutil + { template <typename fp_t> class linear_map { @@ -143,10 +139,8 @@ private: // bounds (inclusive) const int min_int_, max_int_; }; + } // namespace jtutil:: //****************************************************************************** - } // namespace jtutil - } // namespace AHFinderDirect - #endif /* AHFINDERDIRECT__LINEAR_MAP_HH */ diff --git a/src/jtutil/make.code.defn b/src/jtutil/make.code.defn index f9bcd04..c188744 100644 --- a/src/jtutil/make.code.defn +++ b/src/jtutil/make.code.defn @@ -7,17 +7,3 @@ SRCS = array.cc cpm_map.cc fuzzy.cc linear_map.cc norm.cc round.cc \ # Subdirectories containing source files SUBDIRS = - -# disable automatic template instantiation on DEC Alphas cxx compiler -ifeq ($(shell uname), OSF1) - ifeq ($(CXX), cxx) - CXXFLAGS += -nopt - endif -endif - -# disable automagic template instantiation on SGI Irix CC compiler -ifneq (,$(findstring IRIX,$(shell uname))) - ifeq ($(notdir $(CXX)), CC) - CXXFLAGS += -no_auto_include - endif -endif diff --git a/src/jtutil/miscfp.cc b/src/jtutil/miscfp.cc index 519f7e0..87a0272 100644 --- a/src/jtutil/miscfp.cc +++ b/src/jtutil/miscfp.cc @@ -23,12 +23,6 @@ #include "stdc.h" #include "util.hh" -// everything in this file is inside these namespaces -namespace AHFinderDirect - { -namespace jtutil - { - //****************************************************************************** //****************************************************************************** //****************************************************************************** @@ -37,12 +31,15 @@ namespace jtutil // This function computes the floating point "signum" function (as in APL), // signum(x) = -1.0, 0.0, or +1.0, according to the sign of x. // +namespace jtutil + { double signum(double x) { if (x == 0.0) then return 0.0; else return (x > 0.0) ? 1.0 : -1.0; } + } // namespace jtutil:: //****************************************************************************** @@ -61,10 +58,13 @@ if (x == 0.0) // unwarranted IEEE exceptions if any of |x|, |y|, or |z| is close to // the overflow and/or underflow threshold. // +namespace jtutil + { double hypot3(double x, double y, double z) { return sqrt(x*x + y*y + z*z); } + } // namespace jtutil:: //****************************************************************************** @@ -81,11 +81,14 @@ return sqrt(x*x + y*y + z*z); // some real $R$, i.e. it returns the angle between the positive $x$ axis and // the line joining the origin and the point $(x,y)$. // +namespace jtutil + { double arctan_xy(double x, double y) { // note reversed argument order (y,x) in std::atan2() function return ((x == 0.0) && (y == 0.0)) ? 0.0 : atan2(y,x); } + } // namespace jtutil:: //****************************************************************************** @@ -93,6 +96,8 @@ return ((x == 0.0) && (y == 0.0)) ? 0.0 : atan2(y,x); // This function reduces x modulo xmod to be (fuzzily) in the range // [xmin, xmax] , or does an error_exit() if no such value exists. // +namespace jtutil + { double modulo_reduce(double x, double xmod, double xmin, double xmax) { double xx = x; @@ -108,24 +113,27 @@ double xx = x; } if (! (fuzzy<double>::GE(xx, xmin) && fuzzy<double>::LE(xx, xmax)) ) - then error_exit(ERROR_EXIT, + then jtutil::error_exit(ERROR_EXIT, "***** modulo_reduce(): no modulo value is fuzzily within specified range!\n" " x = %g xmod = %g\n" " [xmin,xmax] = [%g,%g]\n" " ==> xx = %g\n" , - x, xmod, - xmin, xmax, - xx); /*NOTREACHED*/ + x, xmod, + xmin, xmax, + xx); /*NOTREACHED*/ return xx; } + } // namespace jtutil:: //****************************************************************************** // // This function sets a C-style array to all zeros. // +namespace jtutil + { template <typename fp_t> void zero_C_array(int N, fp_t array[]) { @@ -134,6 +142,7 @@ template <typename fp_t> array[i] = 0; } } + } // namespace jtutil:: //****************************************************************************** //****************************************************************************** @@ -143,11 +152,7 @@ template <typename fp_t> // ***** template instantiations ***** // +namespace jtutil + { template void zero_C_array<CCTK_REAL>(int, CCTK_REAL[]); - -//****************************************************************************** -//****************************************************************************** -//****************************************************************************** - - } // namespace jtutil - } // namespace AHFinderDirect + } // namespace jtutil:: diff --git a/src/jtutil/norm.cc b/src/jtutil/norm.cc index 5c9b699..5ff72a9 100644 --- a/src/jtutil/norm.cc +++ b/src/jtutil/norm.cc @@ -16,12 +16,6 @@ #include "util.hh" -// everything in this file is inside these namespaces -namespace AHFinderDirect - { -namespace jtutil - { - //***************************************************************************** //***************************************************************************** //***************************************************************************** @@ -29,6 +23,8 @@ namespace jtutil // // This function constructs a norm object. // +namespace jtutil + { template <typename fp_t> norm<fp_t>::norm() : N_(0L), @@ -36,12 +32,15 @@ template <typename fp_t> max_abs_value_(0.0), min_abs_value_(0.0), max_value_(0.0), min_value_(0.0) { } + } //***************************************************************************** // // This function resets a norm object to its initial state // +namespace jtutil + { template <typename fp_t> void norm<fp_t>::reset() { @@ -53,12 +52,15 @@ min_abs_value_ = 0.0; max_value_ = 0.0; min_value_ = 0.0; } + } //***************************************************************************** // // This function updates the norms with a new data point x . // +namespace jtutil + { template <typename fp_t> void norm<fp_t>::data(fp_t x) { @@ -74,19 +76,29 @@ max_value_ = (N_ == 0) ? x : jtutil::max(max_value_, x); ++N_; } + } // namespace jtutil:: //****************************************************************************** // // these functions compute the corresponding norms // +namespace jtutil + { template<typename fp_t> fp_t norm<fp_t>::mean() const { return sum_/fp_t(N_); } template<typename fp_t> + fp_t norm<fp_t>::std_dev() const + { + if (is_empty()) return fp_t(0); + return sqrt(jtutil::max(fp_t(0),fp_t(N_)*sum2_-sum_*sum_))/fp_t(N_); + } +template<typename fp_t> fp_t norm<fp_t>::two_norm() const { return sqrt(sum2_); } template<typename fp_t> fp_t norm<fp_t>::rms_norm() const { assert(is_nonempty()); return sqrt(sum2_/fp_t(N_)); } + } // namespace jtutil:: //****************************************************************************** //****************************************************************************** @@ -98,10 +110,3 @@ template<typename fp_t> template class jtutil::norm<float>; template class jtutil::norm<double>; - -//****************************************************************************** -//****************************************************************************** -//****************************************************************************** - - } // namespace jtutil - } // namespace AHFinderDirect diff --git a/src/jtutil/round.cc b/src/jtutil/round.cc index 3c2d7e6..6559944 100644 --- a/src/jtutil/round.cc +++ b/src/jtutil/round.cc @@ -14,12 +14,6 @@ #include "stdc.h" #include "util.hh" -// everything in this file is inside these namespaces -namespace AHFinderDirect - { -namespace jtutil - { - //****************************************************************************** //****************************************************************************** //****************************************************************************** @@ -35,6 +29,8 @@ namespace jtutil //****************************************************************************** // round to nearest integer, up for exact tie +namespace jtutil + { template <typename fp_t> int round<fp_t>::to_integer(fp_t x) { @@ -42,9 +38,12 @@ return (x >= 0.0) ? int(x + 0.5) // eg 3.6 --> int(4.1) = 4 : - int( (-x) + 0.5 ); // eg -3.6 --> - int(4.1) = -4 } + } // namespace jtutil:: //****************************************************************************** +namespace jtutil + { template <typename fp_t> int round<fp_t>::floor(fp_t x) { @@ -52,9 +51,12 @@ return (x >= 0.0) ? int(x) : - ceiling(-x); } + } // namespace jtutil:: //****************************************************************************** +namespace jtutil + { template <typename fp_t> int round<fp_t>::ceiling(fp_t x) { @@ -62,6 +64,7 @@ return (x >= 0.0) ? int(x) + (x != fp_t(int(x))) : - floor(-x); } + } // namespace jtutil:: //****************************************************************************** //****************************************************************************** @@ -71,12 +74,5 @@ return (x >= 0.0) // ***** template instantiations ***** // -template class round<float>; -template class round<double>; - -//****************************************************************************** -//****************************************************************************** -//****************************************************************************** - - } // namespace jtutil - } // namespace AHFinderDirect +template class jtutil::round<float>; +template class jtutil::round<double>; diff --git a/src/jtutil/test_array.cc b/src/jtutil/test_array.cc index 2b413c4..56c2a0c 100644 --- a/src/jtutil/test_array.cc +++ b/src/jtutil/test_array.cc @@ -9,8 +9,6 @@ #include "util.hh" #include "array.hh" -using namespace AHFinderDirect; - using jtutil::fuzzy; using jtutil::array1d; using jtutil::array2d; diff --git a/src/jtutil/test_array2.cc b/src/jtutil/test_array2.cc index c89e209..9015cbd 100644 --- a/src/jtutil/test_array2.cc +++ b/src/jtutil/test_array2.cc @@ -9,8 +9,6 @@ #include "util.hh" #include "array.hh" -using namespace AHFinderDirect; - void print( jtutil::array2d<double>& Aref); void cprint(const jtutil::array2d<double>& Aref); diff --git a/src/jtutil/test_cpm_map.cc b/src/jtutil/test_cpm_map.cc index cdb5c7c..070321a 100644 --- a/src/jtutil/test_cpm_map.cc +++ b/src/jtutil/test_cpm_map.cc @@ -7,9 +7,6 @@ #include "stdc.h" #include "util.hh" #include "cpm_map.hh" - -using namespace AHFinderDirect; - using jtutil::cpm_map; //****************************************************************************** diff --git a/src/jtutil/test_error_exit.cc b/src/jtutil/test_error_exit.cc index fd4e170..a1b568e 100644 --- a/src/jtutil/test_error_exit.cc +++ b/src/jtutil/test_error_exit.cc @@ -4,8 +4,6 @@ #include <stdio.h> #include "stdc.h" - -using namespace AHFinderDirect; using jtutil::error_exit; int main() diff --git a/src/jtutil/test_fuzzy.cc b/src/jtutil/test_fuzzy.cc index 3566f61..437df36 100644 --- a/src/jtutil/test_fuzzy.cc +++ b/src/jtutil/test_fuzzy.cc @@ -12,9 +12,6 @@ #include "stdc.h" #include "util.hh" - -using namespace AHFinderDirect; - using jtutil::error_exit; using jtutil::fuzzy; diff --git a/src/jtutil/test_linear_map.cc b/src/jtutil/test_linear_map.cc index 29b8974..f38d362 100644 --- a/src/jtutil/test_linear_map.cc +++ b/src/jtutil/test_linear_map.cc @@ -7,9 +7,6 @@ #include "stdc.h" #include "util.hh" #include "linear_map.hh" - -using namespace AHFinderDirect; - using jtutil::fuzzy; using jtutil::linear_map; diff --git a/src/jtutil/test_modulo.cc b/src/jtutil/test_modulo.cc index a32ba2b..c587ea6 100644 --- a/src/jtutil/test_modulo.cc +++ b/src/jtutil/test_modulo.cc @@ -6,9 +6,6 @@ #include "stdc.h" #include "util.hh" - -using namespace AHFinderDirect; - using jtutil::error_exit; using jtutil::fuzzy; diff --git a/src/jtutil/test_norm.cc b/src/jtutil/test_norm.cc index 6eec312..f9c8d47 100644 --- a/src/jtutil/test_norm.cc +++ b/src/jtutil/test_norm.cc @@ -7,9 +7,6 @@ #include "stdc.h" #include "util.hh" - -using namespace AHFinderDirect; - using jtutil::norm; using jtutil::fuzzy; diff --git a/src/jtutil/test_round.cc b/src/jtutil/test_round.cc index dc90584..5e3354a 100644 --- a/src/jtutil/test_round.cc +++ b/src/jtutil/test_round.cc @@ -6,8 +6,6 @@ #include "stdc.h" #include "util.hh" - -using namespace AHFinderDirect; using jtutil::round; // diff --git a/src/jtutil/util.hh b/src/jtutil/util.hh index d59485a..d3a9c1a 100644 --- a/src/jtutil/util.hh +++ b/src/jtutil/util.hh @@ -9,9 +9,6 @@ // "stdc.h" // -// everything in this file is inside these namespaces -namespace AHFinderDirect - { namespace jtutil { @@ -102,6 +99,7 @@ class norm public: // get norms etc fp_t mean() const; + fp_t std_dev() const; // sqrt(sum (x_i - average of x_i)^2 / N) fp_t two_norm() const; // sqrt(sum x_i^2) fp_t rms_norm() const; // sqrt(average of x_i^2) fp_t infinity_norm() const { return max_abs_value_; } @@ -211,6 +209,5 @@ public: //****************************************************************************** } // namespace jtutil - } // namespace AHFinderDirect #endif /* AHFINDERDIRECT__UTIL_HH */ |