1 /** D bindings for GSL.
2     Authors:    Chibisi Chima-Okereke
3     Copyright:  Copyright (c) 2016, Chibisi Chima-Okereke. All rights reserved.
4     License:    Boost License 1.0
5 */
6 
7 module gsl.histogram;
8 import core.stdc.stdio : FILE;
9 
10 extern (C):
11 
12 //gsl_histogram
13 struct gsl_histogram
14 {
15     size_t n;
16     double* range;
17     double* bin;
18 }
19 
20 struct gsl_histogram_pdf
21 {
22     size_t n;
23     double* range;
24     double* sum;
25 }
26 
27 gsl_histogram* gsl_histogram_alloc (size_t n);
28 gsl_histogram* gsl_histogram_calloc (size_t n);
29 gsl_histogram* gsl_histogram_calloc_uniform (const size_t n, const double xmin, const double xmax);
30 void gsl_histogram_free (gsl_histogram* h);
31 int gsl_histogram_increment (gsl_histogram* h, double x);
32 int gsl_histogram_accumulate (gsl_histogram* h, double x, double weight);
33 int gsl_histogram_find (const(gsl_histogram)* h, const double x, size_t* i);
34 double gsl_histogram_get (const(gsl_histogram)* h, size_t i);
35 int gsl_histogram_get_range (const(gsl_histogram)* h, size_t i, double* lower, double* upper);
36 double gsl_histogram_max (const(gsl_histogram)* h);
37 double gsl_histogram_min (const(gsl_histogram)* h);
38 size_t gsl_histogram_bins (const(gsl_histogram)* h);
39 void gsl_histogram_reset (gsl_histogram* h);
40 gsl_histogram* gsl_histogram_calloc_range (size_t n, double* range);
41 int gsl_histogram_set_ranges (gsl_histogram* h, const(double)* range, size_t size);
42 int gsl_histogram_set_ranges_uniform (gsl_histogram* h, double xmin, double xmax);
43 int gsl_histogram_memcpy (gsl_histogram* dest, const(gsl_histogram)* source);
44 gsl_histogram* gsl_histogram_clone (const(gsl_histogram)* source);
45 double gsl_histogram_max_val (const(gsl_histogram)* h);
46 size_t gsl_histogram_max_bin (const(gsl_histogram)* h);
47 double gsl_histogram_min_val (const(gsl_histogram)* h);
48 size_t gsl_histogram_min_bin (const(gsl_histogram)* h);
49 int gsl_histogram_equal_bins_p (const(gsl_histogram)* h1, const(gsl_histogram)* h2);
50 int gsl_histogram_add (gsl_histogram* h1, const(gsl_histogram)* h2);
51 int gsl_histogram_sub (gsl_histogram* h1, const(gsl_histogram)* h2);
52 int gsl_histogram_mul (gsl_histogram* h1, const(gsl_histogram)* h2);
53 int gsl_histogram_div (gsl_histogram* h1, const(gsl_histogram)* h2);
54 int gsl_histogram_scale (gsl_histogram* h, double scale);
55 int gsl_histogram_shift (gsl_histogram* h, double shift);
56 double gsl_histogram_sigma (const(gsl_histogram)* h);
57 double gsl_histogram_mean (const(gsl_histogram)* h);
58 double gsl_histogram_sum (const(gsl_histogram)* h);
59 int gsl_histogram_fwrite (FILE* stream, const(gsl_histogram)* h);
60 int gsl_histogram_fread (FILE* stream, gsl_histogram* h);
61 int gsl_histogram_fprintf (FILE* stream, const(gsl_histogram)* h, const(char)* range_format, const(char)* bin_format);
62 int gsl_histogram_fscanf (FILE* stream, gsl_histogram* h);
63 gsl_histogram_pdf* gsl_histogram_pdf_alloc (const size_t n);
64 int gsl_histogram_pdf_init (gsl_histogram_pdf* p, const(gsl_histogram)* h);
65 void gsl_histogram_pdf_free (gsl_histogram_pdf* p);
66 double gsl_histogram_pdf_sample (const(gsl_histogram_pdf)* p, double r);
67 
68 
69 //gsl_histogram2d
70 struct gsl_histogram2d
71 {
72     size_t nx;
73     size_t ny;
74     double* xrange;
75     double* yrange;
76     double* bin;
77 }
78 
79 struct gsl_histogram2d_pdf
80 {
81     size_t nx;
82     size_t ny;
83     double* xrange;
84     double* yrange;
85     double* sum;
86 }
87 
88 gsl_histogram2d* gsl_histogram2d_alloc (const size_t nx, const size_t ny);
89 gsl_histogram2d* gsl_histogram2d_calloc (const size_t nx, const size_t ny);
90 gsl_histogram2d* gsl_histogram2d_calloc_uniform (const size_t nx, const size_t ny, const double xmin, const double xmax, const double ymin, const double ymax);
91 void gsl_histogram2d_free (gsl_histogram2d* h);
92 int gsl_histogram2d_increment (gsl_histogram2d* h, double x, double y);
93 int gsl_histogram2d_accumulate (gsl_histogram2d* h, double x, double y, double weight);
94 int gsl_histogram2d_find (const(gsl_histogram2d)* h, const double x, const double y, size_t* i, size_t* j);
95 double gsl_histogram2d_get (const(gsl_histogram2d)* h, const size_t i, const size_t j);
96 int gsl_histogram2d_get_xrange (const(gsl_histogram2d)* h, const size_t i, double* xlower, double* xupper);
97 int gsl_histogram2d_get_yrange (const(gsl_histogram2d)* h, const size_t j, double* ylower, double* yupper);
98 double gsl_histogram2d_xmax (const(gsl_histogram2d)* h);
99 double gsl_histogram2d_xmin (const(gsl_histogram2d)* h);
100 size_t gsl_histogram2d_nx (const(gsl_histogram2d)* h);
101 double gsl_histogram2d_ymax (const(gsl_histogram2d)* h);
102 double gsl_histogram2d_ymin (const(gsl_histogram2d)* h);
103 size_t gsl_histogram2d_ny (const(gsl_histogram2d)* h);
104 void gsl_histogram2d_reset (gsl_histogram2d* h);
105 gsl_histogram2d* gsl_histogram2d_calloc_range (size_t nx, size_t ny, double* xrange, double* yrange);
106 int gsl_histogram2d_set_ranges_uniform (gsl_histogram2d* h, double xmin, double xmax, double ymin, double ymax);
107 int gsl_histogram2d_set_ranges (gsl_histogram2d* h, const(double)* xrange, size_t xsize, const(double)* yrange, size_t ysize);
108 int gsl_histogram2d_memcpy (gsl_histogram2d* dest, const(gsl_histogram2d)* source);
109 gsl_histogram2d* gsl_histogram2d_clone (const(gsl_histogram2d)* source);
110 double gsl_histogram2d_max_val (const(gsl_histogram2d)* h);
111 void gsl_histogram2d_max_bin (const(gsl_histogram2d)* h, size_t* i, size_t* j);
112 double gsl_histogram2d_min_val (const(gsl_histogram2d)* h);
113 void gsl_histogram2d_min_bin (const(gsl_histogram2d)* h, size_t* i, size_t* j);
114 double gsl_histogram2d_xmean (const(gsl_histogram2d)* h);
115 double gsl_histogram2d_ymean (const(gsl_histogram2d)* h);
116 double gsl_histogram2d_xsigma (const(gsl_histogram2d)* h);
117 double gsl_histogram2d_ysigma (const(gsl_histogram2d)* h);
118 double gsl_histogram2d_cov (const(gsl_histogram2d)* h);
119 double gsl_histogram2d_sum (const(gsl_histogram2d)* h);
120 int gsl_histogram2d_equal_bins_p (const(gsl_histogram2d)* h1, const(gsl_histogram2d)* h2);
121 int gsl_histogram2d_add (gsl_histogram2d* h1, const(gsl_histogram2d)* h2);
122 int gsl_histogram2d_sub (gsl_histogram2d* h1, const(gsl_histogram2d)* h2);
123 int gsl_histogram2d_mul (gsl_histogram2d* h1, const(gsl_histogram2d)* h2);
124 int gsl_histogram2d_div (gsl_histogram2d* h1, const(gsl_histogram2d)* h2);
125 int gsl_histogram2d_scale (gsl_histogram2d* h, double scale);
126 int gsl_histogram2d_shift (gsl_histogram2d* h, double shift);
127 int gsl_histogram2d_fwrite (FILE* stream, const(gsl_histogram2d)* h);
128 int gsl_histogram2d_fread (FILE* stream, gsl_histogram2d* h);
129 int gsl_histogram2d_fprintf (FILE* stream, const(gsl_histogram2d)* h, const(char)* range_format, const(char)* bin_format);
130 int gsl_histogram2d_fscanf (FILE* stream, gsl_histogram2d* h);
131 gsl_histogram2d_pdf* gsl_histogram2d_pdf_alloc (const size_t nx, const size_t ny);
132 int gsl_histogram2d_pdf_init (gsl_histogram2d_pdf* p, const(gsl_histogram2d)* h);
133 void gsl_histogram2d_pdf_free (gsl_histogram2d_pdf* p);
134 int gsl_histogram2d_pdf_sample (const(gsl_histogram2d_pdf)* p, double r1, double r2, double* x, double* y);