Debian Codegraph @

easel/esl_stats.h

raw symbols SCIP
1 /* Foundation, miscellanea for the statistics modules.
2 */
3 #ifndef eslSTATS_INCLUDED
4 #define eslSTATS_INCLUDED
5 #include <esl_config.h>
6
7 #include "easel.h"
8
9 /*****************************************************************
10 * Splitting IEEE754 double-precision float into two uint32_t
11 *****************************************************************
12 *
13 * Currently we only need these macros for one function,
14 * esl_stats_erfc(). The Sun Microsystems erfc() code that we've
15 * borrowed splits an IEEE754 double into two unsigned 32-bit
16 * integers. It uses arcane trickery to deal with endianness at
17 * runtime, using incantations like these:
18 * n0 = ((*(int*)&one)>>29)^1 0|1 = bigendian | littleendian
19 * hx = *(n0+(int*)&x); get high word
20 * (1-n0+(int*)&z) = 0; set low word
21 *
22 * Not only is this arcane and dubious, static code checking (using
23 * the clang/llvm checker) doesn't like it. I found an improvement
24 * in a library called zenilib by Mitchell Keith Bloch at:
25 * http://www-personal.umich.edu/~bazald/l/api/math__private_8h_source.html
26 *
27 * Here we do the same thing in an ANSI-respecting way using unions,
28 * with endianness detected at compile time.
29 *
30 * The zenilib code also appears to derive from (C) Sun Microsystems
31 * code. The following code is:
32 *
33 * ====================================================
34 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
35 *
36 * Developed at SunPro, a Sun Microsystems, Inc. business.
37 * Permission to use, copy, modify, and distribute this
38 * software is freely granted, provided that this notice
39 * is preserved.
40 * ====================================================
41 */
42
43 #ifdef WORDS_BIGENDIAN
44 typedef union
45 {
46 double val;
47 struct {
48 uint32_t msw;
49 uint32_t lsw;
50 } parts;
51 } esl_double_split_t;
52 #else /* else we're littleendian, such as Intel */
53 typedef union
54 {
55 double val;
56 struct {
57 uint32_t lsw;
58 uint32_t msw;
59 } parts;
60 } esl_double_split_t;
61 #endif /*WORDS_BIGENDIAN*/
62
63 #define ESL_GET_WORDS(ix0, ix1, d) \
64 do { \
65 esl_double_split_t esltmp_ds; \
66 esltmp_ds.val = (d); \
67 (ix0) = esltmp_ds.parts.msw; \
68 (ix1) = esltmp_ds.parts.lsw; \
69 } while (0)
70
71 #define ESL_GET_HIGHWORD(ix0, d) \
72 do { \
73 esl_double_split_t esltmp_ds; \
74 esltmp_ds.val = (d); \
75 (ix0) = esltmp_ds.parts.msw; \
76 } while (0)
77
78 #define ESL_GET_LOWWORD(ix0, d) \
79 do { \
80 esl_double_split_t esltmp_ds; \
81 esltmp_ds.val = (d); \
82 (ix0) = esltmp_ds.parts.lsw; \
83 } while (0)
84
85 #define ESL_SET_WORDS(d, ix0, ix1) \
86 do { \
87 esl_double_split_t esltmp_ds; \
88 esltmp_ds.parts.msw = (ix0); \
89 esltmp_ds.parts.lsw = (ix1); \
90 (d) = esltmp_ds.val; \
91 } while (0)
92
93 #define ESL_SET_HIGHWORD(d, ix0) \
94 do { \
95 esl_double_split_t esltmp_ds; \
96 esltmp_ds.val = (d); \
97 esltmp_ds.parts.msw = (ix0); \
98 (d) = esltmp_ds.val; \
99 } while (0)
100
101 #define ESL_SET_LOWWORD(d, ix1) \
102 do { \
103 esl_double_split_t esltmp_ds; \
104 esltmp_ds.val = (d); \
105 esltmp_ds.parts.lsw = (ix1); \
106 (d) = esltmp_ds.val; \
107 } while (0)
108
109
110 /*****************************************************************
111 * Function declarations
112 *****************************************************************/
113
114 /* 1. Summary statistics calculations */
115 extern int esl_stats_DMean(const double *x, int n, double *opt_mean, double *opt_var);
116 extern int esl_stats_FMean(const float *x, int n, double *opt_mean, double *opt_var);
117 extern int esl_stats_IMean(const int *x, int n, double *opt_mean, double *opt_var);
118
119 /* 2. Special functions */
120 extern int esl_stats_LogGamma(double x, double *ret_answer);
121 extern int esl_stats_Psi (double x, double *ret_answer);
122 extern int esl_stats_Trigamma(double x, double *ret_answer);
123 extern int esl_stats_IncompleteGamma(double a, double x, double *ret_pax, double *ret_qax);
124 extern double esl_stats_erfc(double x);
125
126 /* 3. Standard statistical tests */
127 extern int esl_stats_GTest(int ca, int na, int cb, int nb, double *ret_G, double *ret_P);
128 extern int esl_stats_ChiSquaredTest(int v, double x, double *ret_answer);
129
130 /* 4. Data fitting */
131 extern int esl_stats_LinearRegression(const double *x, const double *y, const double *sigma, int n,
132 double *opt_a, double *opt_b,
133 double *opt_sigma_a, double *opt_sigma_b, double *opt_cov_ab,
134 double *opt_cc, double *opt_Q);
135
136
137 /*****************************************************************
138 * Portability
139 *****************************************************************/
140
141 #ifndef HAVE_ERFC
142 #define erfc(x) esl_stats_erfc(x)
143 #endif
144
145 #endif /*eslSTATS_INCLUDED*/
146