1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
/* Copyright (c) 2019, Anthony Latorre <tlatorre at uchicago>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef MISC_H
#define MISC_H
#include <stdlib.h> /* for size_t */
/* Macro to compute the size of a static C array.
*
* See https://stackoverflow.com/questions/1598773. */
#define LEN(x) ((sizeof(x)/sizeof(0[x]))/((size_t)(!(sizeof(x) % sizeof(0[x])))))
#define LN_MAX 100
#define LNFACT_MAX 100
/* Number of points to create a lookup table for the fast_acos() function. */
#define N_ACOS 10000
double trapz(const double *y, double dx, size_t n);
int intersect_sphere(double *pos, double *dir, double R, double *l);
void get_path_length(double *pos1, double *pos2, double R, double *l1, double *l2);
double ln(unsigned int n);
double lnfact(unsigned int n);
double kahan_sum(double *x, size_t n);
double interp1d(double x, double *xp, double *yp, size_t n);
double interp2d(double x, double y, double *xp, double *yp, double *zp, size_t n1, size_t n2);
int isclose(double a, double b, double rel_tol, double abs_tol);
int allclose(double *a, double *b, size_t n, double rel_tol, double abs_tol);
double logsumexp(double *a, size_t n);
double log_norm(double x, double mu, double sigma);
double norm(double x, double mu, double sigma);
double norm_cdf(double x, double mu, double sigma);
double mean(const double *x, size_t n);
double std(const double *x, size_t n);
double gamma_pdf(double x, double k, double theta);
size_t ipow(size_t base, size_t exp);
void product(size_t n, size_t r, size_t *result);
void unique_vertices(int *id, size_t n, size_t npeaks, size_t *result, size_t *nvertices);
void combinations_with_replacement(size_t n, size_t r, size_t *result, size_t *len);
size_t argmax(double *a, size_t n);
size_t argmin(double *a, size_t n);
void get_dir(double *dir, double theta, double phi);
double fast_acos(double x);
#endif
|