30 #include <lal/EllipsoidOverlapTools.h>
48 gsl_permutation *p1 =
p->p1;
49 gsl_vector *tmpV =
p->tmpV;
51 gsl_matrix *A =
p->tmpA;
52 gsl_matrix *B =
p->tmpB;
57 gsl_matrix_memcpy ( A,
p->invQ1);
58 gsl_matrix_memcpy ( B,
p->invQ2);
60 gsl_matrix_scale (B,
x);
61 gsl_matrix_scale (A, (1.0L-
x));
63 gsl_matrix_add (A, B);
65 gsl_linalg_LU_decomp( A, p1, &s1 );
66 gsl_linalg_LU_invert( A, p1, C );
69 gsl_blas_dsymv (CblasUpper, 1.0, C,
p->r_AB, 0.0, tmpV);
72 gsl_blas_ddot (
p->r_AB, tmpV, &result);
74 result *= (
x*(1.0L-
x));
91 const gsl_min_fminimizer_type *T,
108 if ((!(
a && b )) && (
a || b ))
114 if (
a->size1 != n ||
a->size2 != n || b->size1 != n || b->size2 != n )
129 workSpace->
invQ2 = b;
138 XLAL_CALLGSL( workSpace->
s = gsl_min_fminimizer_alloc( T ) );
141 if (!workSpace->
tmpA || !workSpace->
tmpB || !workSpace->
C ||
142 !workSpace->
p1 || !workSpace->
tmpV || !workSpace->
r_AB
165 const gsl_vector *ra,
166 const gsl_vector *rb,
171 INT4 iter = 0, max_iter = 100;
174 gsl_min_fminimizer *s = workSpace->
s;
177 if ( !ra || !rb || !workSpace )
180 if ( ra->size != rb->size || ra->size != workSpace->
n )
188 if ( gsl_vector_isnull( workSpace->
r_AB ))
195 F.params = workSpace;
197 XLAL_CALLGSL( min_status = gsl_min_fminimizer_set (s, &F,
m,
a, b) );
198 if ( min_status != GSL_SUCCESS )
204 XLAL_CALLGSL( min_status = gsl_min_fminimizer_iterate (s) );
205 if (min_status != GSL_SUCCESS )
207 if (min_status == GSL_EBADFUNC)
209 else if (min_status == GSL_EZERODIV)
215 m = gsl_min_fminimizer_x_minimum (s);
216 a = gsl_min_fminimizer_x_lower (s);
217 b = gsl_min_fminimizer_x_upper (s);
220 if (min_status != GSL_CONTINUE && min_status != GSL_SUCCESS )
223 while (min_status == GSL_CONTINUE && iter < max_iter );
227 if ( iter == max_iter && min_status == GSL_CONTINUE )
232 return ( -(s->f_minimum) );
252 if (workSpace->
s)
XLAL_CALLGSL( gsl_min_fminimizer_free( workSpace->
s ));
int XLALPrintWarning(const char *fmt,...)
#define XLAL_CALLGSL(statement)
double REAL8
Double precision real floating-point number (8 bytes).
uint32_t UINT4
Four-byte unsigned integer.
int32_t INT4
Four-byte signed integer.
#define XLAL_ERROR_VOID(...)
Macro to invoke a failure from a XLAL routine returning void.
#define XLAL_ERROR_REAL8(...)
Macro to invoke a failure from a XLAL routine returning a REAL8.
#define XLAL_ERROR_NULL(...)
Macro to invoke a failure from a XLAL routine returning a pointer.
@ XLAL_EBADLEN
Inconsistent or invalid length.
@ XLAL_ENOMEM
Memory allocation error.
@ XLAL_EFPINVAL
IEEE Invalid floating point operation, eg sqrt(-1), 0/0.
@ XLAL_EFAULT
Invalid pointer.
@ XLAL_EFUNC
Internal function call failed bit: "or" this with existing error number.
@ XLAL_EMAXITER
Exceeded maximum number of iterations.
@ XLAL_EINVAL
Invalid argument.
@ XLAL_EFPDIV0
IEEE Division by zero floating point error.