From 8ffa2d3b246c381e46f9da6ee77fcc0a720e31ca Mon Sep 17 00:00:00 2001 From: Garry Boyer Date: Thu, 5 Apr 2007 02:05:47 +0000 Subject: [PATCH] hi --- fastlib/base/cc.h | 3 +-- fastlib/base/compiler_impl.h | 4 ++-- fastlib/base/debug.h | 2 +- fastlib/data/dataset.cc | 4 +++- fastlib/la/matrix.h | 28 ++++++++++++++++++++++------ fastlib/la/uselapack.cc | 5 ++++- fastlib/la/uselapack.h | 8 ++++---- fastlib/math/math.h | 18 ++++++++++++++++++ fastlib/script/buildsys.py | 5 +++-- 9 files changed, 58 insertions(+), 19 deletions(-) diff --git a/fastlib/base/cc.h b/fastlib/base/cc.h index 7e9879087c..1592fc3ed3 100644 --- a/fastlib/base/cc.h +++ b/fastlib/base/cc.h @@ -73,10 +73,9 @@ inline T max(T a, T b) { * make a suitable assignment operator. */ #define CC_ASSIGNMENT_OPERATOR(cl) \ - const cl&operator=(const cl&o) \ + public: const cl&operator=(const cl&o) \ {if(this!=&o){this->~cl();new(this)cl(o);}return *this;} - /** * Defines inequality comparators for this class, given the friend * operator less-than has already been defined. diff --git a/fastlib/base/compiler_impl.h b/fastlib/base/compiler_impl.h index d69ff48ecf..a7f72c92fe 100644 --- a/fastlib/base/compiler_impl.h +++ b/fastlib/base/compiler_impl.h @@ -19,7 +19,7 @@ #define EXTERN_C_START__impl #define EXTERN_C_END__impl #define COMPILER_CAST__impl(cast, type, var) ((type)(var)) -#define IS_CONSTANT_EXPRESSION(x) (__builtin_constant_p(x)) +#define IS_CONSTANT_EXPRESSION__impl(x) (__builtin_constant_p(x)) #endif #ifdef __GNUC__ @@ -34,7 +34,7 @@ #define expect__impl(expr, value) (expr) #define likely__impl(x) (x) #define unlikely__impl(x) (x) -#define IS_CONSTANT_EXPRESSION(x) (0) +#define IS_CONSTANT_EXPRESSION__impl(x) (0) #define COMPILER_NORETURN__IMPL #define COMPILER_PRINTF__IMPL(format_arg, dotdotdot_arg) #define COMPILER_FUNCTIONAL__IMPL diff --git a/fastlib/base/debug.h b/fastlib/base/debug.h index 6381712abf..a5231853a9 100644 --- a/fastlib/base/debug.h +++ b/fastlib/base/debug.h @@ -95,7 +95,7 @@ extern int print_warnings; #define DEBUG_GOT_HERE(min_verbosity) \ VERBOSE_ONLY( \ unlikely(print_got_heres && debug_verbosity >= (min_verbosity)) \ - ? NOTIFY("Got to line " __LINE__ " of " __func__) : NOP) + ? NOTIFY("Got to line %d of %s", __LINE__, __func__) : NOP) /** * Conditionally emit a warning message, which may abort or pause diff --git a/fastlib/data/dataset.cc b/fastlib/data/dataset.cc index 77d54ee99a..e44ff61550 100644 --- a/fastlib/data/dataset.cc +++ b/fastlib/data/dataset.cc @@ -318,7 +318,9 @@ success_t DatasetInfo::ReadMatrix(TextLineReader *reader, Matrix *matrix) const *s = ','; } } - reader->Error("Not enough tokens"); + reader->Error("I am expecting %"LI"d entries per row, " + "but this line has only %"LI"d.", + n_features, i); retval = SUCCESS_FAIL; break; } diff --git a/fastlib/la/matrix.h b/fastlib/la/matrix.h index 93080586cf..7fd32963f5 100644 --- a/fastlib/la/matrix.h +++ b/fastlib/la/matrix.h @@ -52,8 +52,7 @@ class Vector { public: /** - * Creates a completely uninitialized Vector which is only useful for - * transferring ownership to. + * Creates a completely uninitialized Vector which must be initialized. */ Vector() { DEBUG_ONLY(Uninitialize_()); @@ -217,7 +216,7 @@ class Vector { */ void MakeSubvector(index_t start_index, index_t len, Vector* dest) { DEBUG_BOUNDS(start_index, length_); - DEBUG_BOUNDS(start_index + len - 1, length_); + DEBUG_BOUNDS(start_index + len, length_ + 1); dest->Alias(ptr_ + start_index, len); } @@ -367,7 +366,7 @@ class Matrix { CC_ASSIGNMENT_OPERATOR(Matrix); /** - * Non-initializing constructor. + * Creates a matrix that can be initialized. */ Matrix() { DEBUG_ONLY(Uninitialize_()); @@ -575,7 +574,7 @@ class Matrix { void MakeColumnSlice(index_t start_col, index_t n_cols_new, Matrix *dest) const { DEBUG_BOUNDS(start_col, n_cols_); - DEBUG_BOUNDS(start_col + n_cols_new - 1, n_cols_); + DEBUG_BOUNDS(start_col + n_cols_new, n_cols_ + 1); dest->Alias(ptr_ + start_col * n_rows_, n_rows_, n_cols_new); } @@ -618,13 +617,30 @@ class Matrix { dest->Alias(n_rows_ * col + ptr_, n_rows_); } + /** + * Makes an alias of a subvector of particular column. + * + * @param col the column to alias + * @param start_row the first row to put in the subvector + * @param n_rows_new the number of rows of the subvector + * @param dest a pointer to an uninitialized vector, which will be + * initialized as an alias to the particular column's subvector + */ + void MakeColumnSubvector(index_t col, index_t start_row, index_t n_rows_new, + Vector *dest) const { + DEBUG_BOUNDS(col, n_cols_); + DEBUG_BOUNDS(start_row, n_rows_); + DEBUG_BOUNDS(start_row + n_rows_new, n_rows_ + 1); + dest->Alias(n_rows_ * col + start_row + ptr_, n_rows_new); + } + /** * Retrieves a pointer to a contiguous array corresponding to a particular * column. * * @param col the column number * @return an array where the i'th element is the i'th row of that - * particular column + * par ticular column */ double *GetColumnPtr(index_t col) { DEBUG_BOUNDS(col, n_cols_); diff --git a/fastlib/la/uselapack.cc b/fastlib/la/uselapack.cc index 2cb08c0251..5e797b214c 100644 --- a/fastlib/la/uselapack.cc +++ b/fastlib/la/uselapack.cc @@ -436,10 +436,13 @@ success_t la::SVDExpert(Matrix* A_garbage, double *s, double *U, double *VT) { s, U, m, VT, k, &d, -1, iwork, &info); { f77_integer lwork = (f77_integer)d; - double work[lwork]; + // work for DGESDD can be large, we really do need to malloc it + double *work = mem::Alloc(lwork); F77_FUNC(dgesdd)(job, m, n, A_garbage->ptr(), m, s, U, m, VT, k, work, lwork, iwork, &info); + + mem::Free(work); } return SUCCESS_FROM_LAPACK(info); diff --git a/fastlib/la/uselapack.h b/fastlib/la/uselapack.h index b34332f575..4806127a63 100644 --- a/fastlib/la/uselapack.h +++ b/fastlib/la/uselapack.h @@ -833,7 +833,7 @@ namespace la { } /** * Inverts a matrix in place - * (\f$A^{-1}\f$). + * (\f$A \gets A^{-1}\f$). * * @code * Matrix A; @@ -848,7 +848,7 @@ namespace la { success_t Inverse(Matrix *A); /** * Set a matrix to the inverse of another matrix - * (\f$A^{-1}\f$). + * (\f$B \gets A^{-1}\f$). * * @code * Matrix A; @@ -866,7 +866,7 @@ namespace la { success_t InverseOverwrite(const Matrix &A, Matrix *B); /** * Init a matrix to the inverse of another matrix - * (\f$A^{-1}\f$). + * (\f$B \gets A^{-1}\f$). * * @param A an N-by-N matrix to invert * @param B a fresh matrix to be initialized to size N-by-N @@ -1262,7 +1262,7 @@ namespace la { * SUCCESS_FAIL otherwise */ success_t Cholesky(Matrix *A_in_U_out); - + /** * Inits a matrix to the Cholesky factorization (A = U' * U). * diff --git a/fastlib/math/math.h b/fastlib/math/math.h index 3e2e03b2f8..1dd838dbf9 100644 --- a/fastlib/math/math.h +++ b/fastlib/math/math.h @@ -58,6 +58,24 @@ namespace math { inline double ClampNonPositive(double d) { return (d - fabs(d)) / 2; } + + /** + * Clips a number between a particular range. + * + * @param value the number to clip + * @param range_min the first of the range + * @param range_max the last of the range + * @return max(range_min, min(range_max, d)) + */ + inline double ClampRange(double value, double range_min, double range_max) { + if (unlikely(value < range_min)) { + return range_min; + } else if (unlikely(value > range_max)) { + return range_max; + } else { + return value; + } + } }; #include "discrete.h" diff --git a/fastlib/script/buildsys.py b/fastlib/script/buildsys.py index 157b82893d..887e0e71dd 100644 --- a/fastlib/script/buildsys.py +++ b/fastlib/script/buildsys.py @@ -234,7 +234,7 @@ class CompileRule(dep.Rule): mode = params["mode"] my_flags = my_includes + " " + compiler.mode_dictionary[params["mode"]] + " " + self.cflags if not sourceextension in compiler.command_from_ext: - raise Exception("Don't know how to compile files of type [%s]." % sourceextension) + raise Exception("Don't know how to compile files of type '*.%s'." % sourceextension) command_template = compiler.command_from_ext[sourceextension] (source_dirname, source_basename) = os.path.split(source.name) compile_cmd = command_template % (my_flags, sq(source_basename), sq(object.name)) @@ -526,7 +526,8 @@ class Loader: build_file_path = os.path.join(real_path, BUILD_FILE) print "... Reading %s" % (build_file_path) text = util.readfile(build_file_path) - text = text + "\n" + posttext + # remove DOS line feeds and add posttext + text = text.replace("\r", "") + "\n" + posttext exec text in {"register" : register, "Types" : Types, "find" : find, "dep" : dep, "lglob" : lglob, "sourcerule" : sourcerule, "sourcerules" : sourcerules,