Commit 531011f7 authored by Vivien Raymond's avatar Vivien Raymond
Browse files

Merge branch 'master' into cbc_bayesian_devel

Original: 249ea469073001da59bb43a2803207e09564dd52
parents e7517bb4 b5572eac
......@@ -636,7 +636,9 @@ EXCLUDE_PATTERNS = */include/lal/* \
# wildcard * is used, a substring. Examples: ANamespace, AClass,
# AClass::ANamespace, ANamespace::*Test
EXCLUDE_SYMBOLS =
EXCLUDE_SYMBOLS = UNUSED \
NRCSID \
RCSID
# The EXAMPLE_PATH tag can be used to specify one or more files or
# directories that contain example code fragments that are included (see
......
......@@ -636,7 +636,9 @@ EXCLUDE_PATTERNS = */include/lal/* \
# wildcard * is used, a substring. Examples: ANamespace, AClass,
# AClass::ANamespace, ANamespace::*Test
EXCLUDE_SYMBOLS =
EXCLUDE_SYMBOLS = UNUSED \
NRCSID \
RCSID
# The EXAMPLE_PATH tag can be used to specify one or more files or
# directories that contain example code fragments that are included (see
......
# lalsuite_build.m4 - top level build macros
#
# serial 16
# serial 17
AC_DEFUN([LALSUITE_USE_LIBTOOL],
[## $0: Generate a libtool script for use in configure tests
......@@ -129,6 +129,18 @@ AC_DEFUN([LALSUITE_ENABLE_NIGHTLY],
AC_SUBST(NIGHTLY_VERSION)
])
AC_DEFUN([LALSUITE_ENABLE_DEBUG],
[AC_ARG_ENABLE(
[debug],
AC_HELP_STRING([--enable-debug],[include standard LAL debugging code [default=yes]]),
[ case "${enableval}" in
yes) ;;
no) AC_DEFINE(LAL_NDEBUG, 1, Suppress debugging code) ;;
*) AC_MSG_ERROR(bad value for ${enableval} for --enable-debug) ;;
esac
], )
])
AC_DEFUN([LALSUITE_ENABLE_ALL_LAL],
[AC_ARG_ENABLE(
[all_lal],
......
......@@ -147,7 +147,7 @@ LALSUITE_WITH_CUDA
LALSUITE_ENABLE_BOINC
LALSUITE_ENABLE_GCC_FLAGS
LAL_ENABLE_DEBUG
LALSUITE_ENABLE_DEBUG
LAL_ENABLE_MACROS
LAL_ENABLE_PTHREAD_LOCK
LALSUITE_ENABLE_NIGHTLY
......
# lal.m4 - lal specific macros
#
# serial 8
# serial 9
AC_DEFUN([LAL_WITH_EXTRA_CPPFLAGS],
[AC_ARG_WITH(
......@@ -81,18 +81,6 @@ AC_DEFUN([LAL_ENABLE_INTELFFT],
], [ intelfft=false ] )
])
AC_DEFUN([LAL_ENABLE_DEBUG],
[AC_ARG_ENABLE(
[debug],
AC_HELP_STRING([--enable-debug],[include standard LAL debugging code [default=yes]]),
[ case "${enableval}" in
yes) ;;
no) AC_DEFINE(LAL_NDEBUG, 1, Suppress debugging code) ;;
*) AC_MSG_ERROR(bad value for ${enableval} for --enable-debug) ;;
esac
], )
])
AC_DEFUN([LAL_ENABLE_MACROS],
[AC_ARG_ENABLE(
[macros],
......
......@@ -25,8 +25,6 @@
* \brief Creation/destruction/manipulation API for 'StringVector' type objects,
* which are just LAL 'vectors' of CHAR * pointers.
*
* $Id$
*
*/
#ifndef _STRINGVECTOR_H /* Double-include protection. */
......@@ -44,7 +42,6 @@ extern "C" {
#include <lal/LALRCSID.h>
/*---------- DEFINES ----------*/
NRCSID( STRINGVECTORH, "$Id$" );
/*----- Error-codes -----*/
/*---------- exported types ----------*/
......@@ -57,7 +54,7 @@ void XLALDestroyStringVector ( LALStringVector *vect );
int XLALSortStringVector (LALStringVector *strings);
LALStringVector *XLALParseCSV2StringVector ( const CHAR *CSVlist );
INT4 XLALFindStringInVector ( const char *needle, const LALStringVector *haystack );
#ifdef __cplusplus
}
......
......@@ -24,8 +24,6 @@
* \ingroup factories
* \brief Creation/destruction/manipulation functions for 'LALStringVector' type objects.
*
* Revision: $Id$
*
*/
/*---------- INCLUDES ----------*/
......@@ -45,8 +43,6 @@ static CHAR *deblank_string ( const CHAR *start, UINT4 len );
const LALStringVector empty_LALStringVector;
/*---------- Global variables ----------*/
NRCSID( STRINGVECTORC, "$Id$");
/*---------- internal prototypes ----------*/
......@@ -63,29 +59,36 @@ XLALAppendString2Vector (LALStringVector *vect, /**< input string-vector to app
const CHAR *string /**< string to append */
)
{
const CHAR *fn = "XLALAppendString2Vector()";
const CHAR *fn = __func__;
UINT4 oldlen;
LALStringVector *ret;
if ( !string ) {
XLALPrintError ("\n%s: NULL string passed to append\n\n", fn );
XLALPrintError ("\n%s: NULL 'string' passed to append\n\n", fn );
XLAL_ERROR_NULL ( fn, XLAL_EINVAL );
}
if ( ! vect )
ret = XLALCreateStringVector ( string, NULL ); /* special case: NULL string-vector to append to */
{ /* special case: NULL string-vector to append to */
if ( (ret = XLALCreateStringVector ( string, NULL )) == NULL) {
XLALPrintError ("%s: XLALCreateStringVector() failed!\n", fn );
XLAL_ERROR_NULL ( fn, XLAL_EFUNC );
}
}
else
{
ret = vect;
oldlen = ret->length;
if ( (ret->data = LALRealloc ( ret->data, (oldlen + 1)*sizeof( *ret->data ) )) == NULL ) {
if ( (ret->data = XLALRealloc ( ret->data, (oldlen + 1)*sizeof( *ret->data ) )) == NULL ) {
XLALPrintError ("%s: XLALRealloc(%d) failed!\n", fn, oldlen + 1 );
XLAL_ERROR_NULL ( fn, XLAL_ENOMEM );
}
ret->length ++;
if ( (ret->data[oldlen] = LALCalloc(1, strlen(string) + 1 )) == NULL ) {
if ( (ret->data[oldlen] = XLALCalloc(1, strlen(string) + 1 )) == NULL ) {
XLALPrintError ("%s: XLALCalloc(%d) failed!\n", fn, strlen(string) + 1 );
XLAL_ERROR_NULL ( fn, XLAL_ENOMEM );
}
......@@ -107,28 +110,31 @@ XLALAppendString2Vector (LALStringVector *vect, /**< input string-vector to app
LALStringVector *
XLALCreateStringVector ( const CHAR *str1, ... )
{
const CHAR *fn = "XLALCreateStringVector()";
const CHAR *fn = __func__;
LALStringVector *ret;
const CHAR *next;
va_list ap;
if ( !str1 ) {
XLALPrintError ("%s: invalid NULL input string 'str1'\n", fn );
XLAL_ERROR_NULL (fn, XLAL_EINVAL );
}
size_t len;
/* set up return vector of strings, and handle first argument */
if ( (ret = LALCalloc ( 1, sizeof(*ret) )) == NULL ) {
XLAL_ERROR_NULL ( fn, XLAL_ENOMEM );
}
if ( (ret->data = LALCalloc ( 1, sizeof(ret->data[0]) )) == NULL) {
LALFree ( ret );
XLAL_ERROR_NULL ( fn, XLAL_ENOMEM );
}
if ( (ret->data[0] = LALCalloc ( strlen(str1)+1, sizeof(CHAR) )) == NULL ) {
LALFree ( ret->data );
LALFree ( ret );
XLAL_ERROR_NULL ( fn, XLAL_ENOMEM );
}
len = sizeof(*ret);
if ( (ret = XLALCalloc ( 1, len )) == NULL )
goto failed;
len = sizeof(ret->data[0]);
if ( (ret->data = XLALCalloc ( 1, len )) == NULL)
goto failed;
len = strlen(str1)+1;
if ( (ret->data[0] = XLALCalloc ( len, sizeof(CHAR) )) == NULL )
goto failed;
strcpy ( ret->data[0], str1 );
ret->length ++;
......@@ -138,9 +144,13 @@ XLALCreateStringVector ( const CHAR *str1, ... )
while ( (next = va_arg(ap, const CHAR *)) != NULL )
{
ret->length ++;
if ( (ret->data = LALRealloc ( ret->data, ret->length * sizeof(ret->data[0]))) == NULL )
len = ret->length * sizeof(ret->data[0]);
if ( (ret->data = XLALRealloc ( ret->data, len)) == NULL )
goto failed;
if ( (ret->data[ret->length-1] = LALCalloc( strlen(next)+1, sizeof(CHAR) )) == NULL )
len = strlen(next)+1;
if ( (ret->data[ret->length-1] = XLALCalloc( len, sizeof(CHAR) )) == NULL )
goto failed;
strcpy ( ret->data[ret->length-1], next );
......@@ -153,6 +163,7 @@ XLALCreateStringVector ( const CHAR *str1, ... )
failed:
va_end(ap);
XLALPrintError ("%s: failed to allocate '%d' bytes\n", fn, len );
XLALDestroyStringVector ( ret );
XLAL_ERROR_NULL ( fn, XLAL_ENOMEM );
......@@ -173,13 +184,13 @@ XLALDestroyStringVector ( LALStringVector *vect )
for ( i=0; i < vect->length; i++ )
{
if ( vect->data[i] )
LALFree ( vect->data[i] );
XLALFree ( vect->data[i] );
}
LALFree ( vect->data );
XLALFree ( vect->data );
}
LALFree ( vect );
XLALFree ( vect );
return;
......@@ -200,8 +211,10 @@ static int StringCompare (const void *p1, const void *p2)
int
XLALSortStringVector (LALStringVector *strings)
{
const CHAR *fn = "XLALSortStringVector()";
const CHAR *fn = __func__;
if ( !strings || strings->length == 0 ) {
XLALPrintError ("%s: invalid empty or zero-length input 'strings'\n", fn );
XLAL_ERROR ( fn, XLAL_EINVAL );
}
......@@ -219,7 +232,7 @@ XLALSortStringVector (LALStringVector *strings)
LALStringVector *
XLALParseCSV2StringVector ( const CHAR *CSVlist )
{
const CHAR *fn = "XLALParseCSV2StringVector";
const CHAR *fn = __func__;
UINT4 counter;
const CHAR *start, *tmp;
CHAR **data = NULL;
......@@ -228,18 +241,20 @@ XLALParseCSV2StringVector ( const CHAR *CSVlist )
if ( !CSVlist )
return NULL;
size_t len;
/* prepare return string-vector */
if ( ( ret = LALCalloc ( 1, sizeof( *ret )) ) == NULL )
XLAL_ERROR_NULL ( fn, XLAL_ENOMEM );
len = sizeof( *ret );
if ( ( ret = XLALCalloc ( 1, len ) ) == NULL )
goto failed;
start = CSVlist;
counter = 0;
do
{
UINT4 len;
/* extend string-array */
if ( ( data = LALRealloc ( data, (counter+1) * sizeof(CHAR*) )) == NULL )
len = (counter+1) * sizeof(CHAR*);
if ( ( data = XLALRealloc ( data, len )) == NULL )
goto failed;
/* determine string-length of next value */
......@@ -249,9 +264,10 @@ XLALParseCSV2StringVector ( const CHAR *CSVlist )
len = strlen ( start );
/* allocate space for that value in string-array */
if ( (data[counter] = deblank_string ( start, len ) ) == NULL )
goto failed;
if ( (data[counter] = deblank_string ( start, len ) ) == NULL ) {
XLALDestroyStringVector ( ret );
XLAL_ERROR_NULL ( fn, XLAL_EFUNC );
}
counter ++;
} while ( tmp && (start = tmp + 1) );
......@@ -263,6 +279,7 @@ XLALParseCSV2StringVector ( const CHAR *CSVlist )
return ( ret );
failed:
XLALPrintError ("%s: failed to allocate %d bytes\n", fn, len );
XLALDestroyStringVector ( ret );
XLAL_ERROR_NULL ( fn, XLAL_ENOMEM );
......@@ -275,13 +292,17 @@ XLALParseCSV2StringVector ( const CHAR *CSVlist )
CHAR *
deblank_string ( const CHAR *start, UINT4 len )
{
const char *fn = __func__;
const CHAR *blank_chars = " \t\n";
const CHAR *pos0, *pos1;
UINT4 newlen;
CHAR *ret;
if ( !start || !len )
return NULL;
if ( !start || !len ) {
XLALPrintError ("%s: invalid NULL input 'start' or len=0\n", fn );
XLAL_ERROR_NULL ( fn, XLAL_EINVAL );
}
/* clip from beginning */
pos0 = start;
......@@ -294,11 +315,15 @@ deblank_string ( const CHAR *start, UINT4 len )
pos1 --;
newlen = pos1 - pos0 + 1;
if ( !newlen )
return NULL;
if ( !newlen ) {
XLALPrintError ("%s: something went wrong here .. probably a coding mistake.\n", fn );
XLAL_ERROR_NULL ( fn, XLAL_EFAILED );
}
if ( (ret = LALCalloc(1, newlen + 1)) == NULL )
return NULL;
if ( (ret = XLALCalloc(1, newlen + 1)) == NULL ) {
XLALPrintError ("%s: failed to XLALCalloc(1, %d )\n", fn, newlen + 1 );
XLAL_ERROR_NULL ( fn, XLAL_ENOMEM );
}
strncpy ( ret, pos0, newlen );
ret[ newlen ] = 0;
......@@ -307,3 +332,30 @@ deblank_string ( const CHAR *start, UINT4 len )
} /* deblank_string() */
/** Search for string 'needle' in string-vector 'haystack', return index to
* first matching vector element if found, -1 outherwise.
*
* Note: function allows haystack=NULL input, in which case -1 (=not found) will be returned.
*
*/
INT4
XLALFindStringInVector ( const char *needle, const LALStringVector *haystack )
{
const char *fn = __func__;
if ( !needle ) {
XLALPrintError ("%s: invalid NULL input 'needle'!\n", fn );
XLAL_ERROR ( fn, XLAL_EINVAL );
}
if ( !haystack || (haystack->length == 0) ) // no vector to search => not found
return -1;
UINT4 i;
for ( i=0; i < haystack->length; i ++ )
if ( !strcmp ( needle, haystack->data[i] ) ) // found it!
return i;
return -1; // didn't find matching entry
} /* XLALFindStringInVector() */
......@@ -34,165 +34,132 @@
#include <lal/Random.h>
#include <lal/GSLSupport.h>
#ifdef __cplusplus
#if defined(__cplusplus)
extern "C" {
#elif 0
} /* so that editors will match preceding brace */
#endif
NRCSID(FLATLATTICETILINGH, "$Id$");
NRCSID(FLATLATTICETILINGH, "$Id$");
/**
* Flat lattice tiling bound
*/
typedef BOOLEAN (*FlatLatticeTilingBoundFunc)(
void *data, /**< Arbitrary data describing parameter space */
INT4 dimension, /**< Dimension on which bound applies */
gsl_vector *point, /**< Point on which to find bounds */
REAL8 *lower, /**< Lower bound on point in dimension */
REAL8 *upper /**< Upper bound on point in dimension */
);
typedef void (*FlatLatticeTilingBoundFree)(
void *data /**< Arbitrary data describing parameter space */
);
typedef struct tagFlatLatticeTilingBound {
/**
* Flat lattice tiling bound
*/
typedef BOOLEAN (*FlatLatticeTilingBoundFunc)(
void *data, /**< Arbitrary data describing parameter space */
INT4 dimension, /**< Dimension on which bound applies */
gsl_vector *point, /**< Point on which to find bounds */
REAL8 *lower, /**< Lower bound on point in dimension */
REAL8 *upper /**< Upper bound on point in dimension */
);
typedef void (*FlatLatticeTilingBoundFree)(
void *data /**< Arbitrary data describing parameter space */
);
typedef struct tagFlatLatticeTilingBound FlatLatticeTilingBound;
/**
* Flat lattice tiling subspace
*/
typedef struct tagFlatLatticeTilingSubspace FlatLatticeTilingSubspace;
/**
* Flat tiling lattice generator
*/
typedef int (*FlatTilingLatticeGenerator)(
INT4 dimensions, /**< Number of dimensions */
gsl_matrix** generator, /**< Generator matrix */
REAL8* norm_thickness /**< Normalised thickness */
);
/**
* Flat lattice tiling state/input structure
*/
typedef struct tagFlatLatticeTiling {
/* Dimension of the parameter space */
INT4 dimensions;
/* Parameter space bounds */
INT4 num_bounds;
FlatLatticeTilingBound **bounds;
gsl_vector_int *bound_map;
gsl_vector *bound_point;
/* Metric of the parameter space in normalised coordinates */
gsl_matrix *metric;
/* Normalised to real parameter coordinates scaling and offset */
gsl_vector *real_scale;
gsl_vector *real_offset;
/* Number of bound dimensions */
INT4 dimensions;
/* Maximum metric mismatch between the templates */
REAL8 max_mismatch;
/* Dimensions which are bound */
UINT8 is_bound;
/* Flat tiling lattice generator */
FlatTilingLatticeGenerator generator;
/* Parameter space bound function */
FlatLatticeTilingBoundFunc func;
/* Cache of generated tiling subspaces */
INT4 num_subspaces;
FlatLatticeTilingSubspace **subspaces;
/* Arbitrary data describing parameter space */
void *data;
/* Scaling of the padding of bounds (for testing) */
REAL8 scale_padding;
/* Cleanup function */
FlatLatticeTilingBoundFree free;
/* Current dimensions which are tiled (non-flat) */
UINT8 curr_is_tiled;
} FlatLatticeTilingBound;
/* Current tiling subspace */
FlatLatticeTilingSubspace *curr_subspace;
/* Current lattice point */
gsl_vector *curr_point;
/* Bounds on current point */
gsl_vector *curr_lower;
gsl_vector *curr_upper;
/* Current template */
gsl_vector *current;
/* Total number of points generated so far */
UINT4 count;
/* State of the tiling */
int state;
} FlatLatticeTiling;
/**
* Core functions
*/
FlatLatticeTiling* XLALCreateFlatLatticeTiling(INT4);
void XLALFreeFlatLatticeTiling(FlatLatticeTiling*);
int XLALAddFlatLatticeTilingBound(FlatLatticeTiling*, UINT8, FlatLatticeTilingBoundFunc, void*, FlatLatticeTilingBoundFree);
int XLALSetFlatLatticeTilingMetric(FlatLatticeTiling*, gsl_matrix*, REAL8, gsl_vector*);
int XLALSetFlatTilingLattice(FlatLatticeTiling*, FlatTilingLatticeGenerator);
int XLALNextFlatLatticePoint(FlatLatticeTiling*);
UINT4 XLALTotalFlatLatticePointCount(FlatLatticeTiling*);
int XLALRandomPointInFlatLatticeParamSpace(FlatLatticeTiling*, RandomParams*, gsl_vector*, gsl_vector*, REAL8*);
/**
* Support functions
*/
gsl_matrix* XLALMetricEllipsePrincipalAxes(gsl_matrix*, REAL8);
gsl_vector* XLALMetricEllipseBoundingBox(gsl_matrix*, REAL8);
int XLALOrthonormaliseWRTMetric(gsl_matrix*, gsl_matrix*);
gsl_matrix* XLALSquareLowerTriangularLatticeGenerator(gsl_matrix*);
int XLALNormaliseLatticeGenerator(gsl_matrix*, REAL8, REAL8);
/**
* Specific lattices and parameter spaces
*/
int XLALSetFlatTilingCubicLattice(FlatLatticeTiling*);
int XLALSetFlatTilingAnstarLattice(FlatLatticeTiling*);
int XLALAddFlatLatticeTilingConstantBound(FlatLatticeTiling*, INT4, REAL8, REAL8);
/**
* Flat lattice tiling subspace
*/
typedef struct tagFlatLatticeTilingSubspace {
/* Total number of tiled (non-flat) dimensions */
INT4 dimensions;
/* Dimensions which are tiled (non-flat) */
UINT8 is_tiled;
/* Padding of bounds along each dimension */
gsl_vector *padding;
/* Increment vectors of the lattice tiling generator */
gsl_matrix *increment;
} FlatLatticeTilingSubspace;
/**
* Flat tiling lattice generator
*/
typedef int (*FlatTilingLatticeGenerator)(
INT4 dimensions, /**< Number of dimensions */
gsl_matrix** generator, /**< Generator matrix */
REAL8* norm_thickness /**< Normalised thickness */
);
/**
* State of the flat lattice tiling algorithm
*/
typedef enum tagFlatLatticeTilingState {
FLT_S_NotInitialised,
FLT_S_NotStarted,
FLT_S_InProgress,
FLT_S_Finished
} FlatLatticeTilingState;
typedef struct tagFlatLatticeTiling {
/* Dimension of the parameter space */
INT4 dimensions;
/* Parameter space bounds */
INT4 num_bounds;
FlatLatticeTilingBound **bounds;
gsl_vector_int *bound_map;