| 1 | /* dht/dht.c |
| 2 | * |
| 3 | * Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | /* Author: G. Jungman |
| 21 | */ |
| 22 | #include "gsl__config.h"cxx . . $ `<file>/external/gsl/gsl__config.h`/ |
| 23 | #include <stdlib.h> |
| 24 | #include "gsl_errno.h"cxx . . $ `<file>/external/gsl/gsl_errno.h`/ |
| 25 | #include "gsl_math.h"cxx . . $ `<file>/external/gsl/gsl_math.h`/ |
| 26 | #include "gsl_sf_bessel.h"cxx . . $ `<file>/external/gsl/gsl_sf_bessel.h`/ |
| 27 | #include "gsl_dht.h"cxx . . $ `<file>/external/gsl/gsl_dht.h`/ |
| 28 | |
| 29 | |
| 30 | gsl_dhtcxx . . $ gsl_dht# * |
| 31 | gsl_dht_alloccxx . . $ gsl_dht_alloc(2d18754896a1ac00). (size_t size) |
| 32 | { |
| 33 | gsl_dhtcxx . . $ gsl_dht# * t; |
| 34 | |
| 35 | if(size == 0) { |
| 36 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`!("size == 0", GSL_EDOM, 0); |
| 37 | } |
| 38 | |
| 39 | t = (gsl_dhtcxx . . $ gsl_dht# *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(gsl_dhtcxx . . $ gsl_dht#)); |
| 40 | |
| 41 | if(t == 0) { |
| 42 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`!("out of memory", GSL_ENOMEM, 0); |
| 43 | } |
| 44 | |
| 45 | t->sizecxx . . $ gsl_dht_struct#size. = size; |
| 46 | |
| 47 | t->xmaxcxx . . $ gsl_dht_struct#xmax. = -1.0; /* Make it clear that this needs to be calculated. */ |
| 48 | t->nucxx . . $ gsl_dht_struct#nu. = -1.0; |
| 49 | |
| 50 | t->jcxx . . $ gsl_dht_struct#j. = (double *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).((size+2)*sizeof(double)); |
| 51 | |
| 52 | if(t->jcxx . . $ gsl_dht_struct#j. == 0) { |
| 53 | freecxx . . $ free(5d22bdacc48458e8).(t); |
| 54 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`!("could not allocate memory for j", GSL_ENOMEM, 0); |
| 55 | } |
| 56 | |
| 57 | t->Jjjcxx . . $ gsl_dht_struct#Jjj. = (double *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(size*(size+1)/2 * sizeof(double)); |
| 58 | |
| 59 | if(t->Jjjcxx . . $ gsl_dht_struct#Jjj. == 0) { |
| 60 | freecxx . . $ free(5d22bdacc48458e8).(t->jcxx . . $ gsl_dht_struct#j.); |
| 61 | freecxx . . $ free(5d22bdacc48458e8).(t); |
| 62 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`!("could not allocate memory for Jjj", GSL_ENOMEM, 0); |
| 63 | } |
| 64 | |
| 65 | t->J2cxx . . $ gsl_dht_struct#J2. = (double *)malloccxx . . $ malloc(bfcfa4d6b7f7ef64).((size+1)*sizeof(double)); |
| 66 | |
| 67 | if(t->J2cxx . . $ gsl_dht_struct#J2. == 0) { |
| 68 | freecxx . . $ free(5d22bdacc48458e8).(t->Jjjcxx . . $ gsl_dht_struct#Jjj.); |
| 69 | freecxx . . $ free(5d22bdacc48458e8).(t->jcxx . . $ gsl_dht_struct#j.); |
| 70 | freecxx . . $ free(5d22bdacc48458e8).(t); |
| 71 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`!("could not allocate memory for J2", GSL_ENOMEM, 0); |
| 72 | } |
| 73 | |
| 74 | return t; |
| 75 | } |
| 76 | |
| 77 | /* Handle internal calculation of Bessel zeros. */ |
| 78 | static int |
| 79 | dht_bessel_zeroscxx . . $ dht_bessel_zeros(f121d8b9bcd2dc6c).(gsl_dhtcxx . . $ gsl_dht# * t) |
| 80 | { |
| 81 | unsigned int s; |
| 82 | gsl_sf_resultcxx . . $ gsl_sf_result# z; |
| 83 | int stat_z = 0; |
| 84 | t->jcxx . . $ gsl_dht_struct#j.[0] = 0.0; |
| 85 | for(s=1; s < t->sizecxx . . $ gsl_dht_struct#size. + 2; s++) { |
| 86 | stat_z += gsl_sf_bessel_zero_Jnu_ecxx . . $ gsl_sf_bessel_zero_Jnu_e(20a82b5be633c070).(t->nucxx . . $ gsl_dht_struct#nu., s, &z); |
| 87 | t->jcxx . . $ gsl_dht_struct#j.[s] = z.valcxx . . $ gsl_sf_result_struct#val.; |
| 88 | } |
| 89 | if(stat_z != 0) { |
| 90 | GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`!("could not compute bessel zeroes", GSL_EFAILED); |
| 91 | } |
| 92 | else { |
| 93 | return GSL_SUCCESScxx . . $ GSL_SUCCESS.; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | gsl_dhtcxx . . $ gsl_dht# * |
| 98 | gsl_dht_newcxx . . $ gsl_dht_new(ff24530878e6e22d). (size_t size, double nu, double xmax) |
| 99 | { |
| 100 | int status; |
| 101 | |
| 102 | gsl_dhtcxx . . $ gsl_dht# * dht = gsl_dht_alloccxx . . $ gsl_dht_alloc(2d18754896a1ac00). (size); |
| 103 | |
| 104 | if (dht == 0) |
| 105 | return 0; |
| 106 | |
| 107 | status = gsl_dht_initcxx . . $ gsl_dht_init(cf3bdeaddba68f39).(dht, nu, xmax); |
| 108 | |
| 109 | if (status) |
| 110 | return 0; |
| 111 | |
| 112 | return dht; |
| 113 | } |
| 114 | |
| 115 | int |
| 116 | gsl_dht_initcxx . . $ gsl_dht_init(cf3bdeaddba68f39).(gsl_dhtcxx . . $ gsl_dht# * t, double nu, double xmax) |
| 117 | { |
| 118 | if(xmax <= 0.0) { |
| 119 | GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("xmax is not positive", GSL_EDOM); |
| 120 | } else if(nu < 0.0) { |
| 121 | GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`! ("nu is negative", GSL_EDOM); |
| 122 | } |
| 123 | else { |
| 124 | size_t n, m; |
| 125 | int stat_bz = GSL_SUCCESScxx . . $ GSL_SUCCESS.; |
| 126 | int stat_J = 0; |
| 127 | double jN; |
| 128 | |
| 129 | if(nu != t->nucxx . . $ gsl_dht_struct#nu.) { |
| 130 | /* Recalculate Bessel zeros if necessary. */ |
| 131 | t->nucxx . . $ gsl_dht_struct#nu. = nu; |
| 132 | stat_bz = dht_bessel_zeroscxx . . $ dht_bessel_zeros(f121d8b9bcd2dc6c).(t); |
| 133 | } |
| 134 | |
| 135 | jN = t->jcxx . . $ gsl_dht_struct#j.[t->sizecxx . . $ gsl_dht_struct#size.+1]; |
| 136 | |
| 137 | t->xmaxcxx . . $ gsl_dht_struct#xmax. = xmax; |
| 138 | t->kmaxcxx . . $ gsl_dht_struct#kmax. = jN / xmax; |
| 139 | |
| 140 | t->J2cxx . . $ gsl_dht_struct#J2.[0] = 0.0; |
| 141 | for(m=1; m<t->sizecxx . . $ gsl_dht_struct#size.+1; m++) { |
| 142 | gsl_sf_resultcxx . . $ gsl_sf_result# J; |
| 143 | stat_J += gsl_sf_bessel_Jnu_ecxx . . $ gsl_sf_bessel_Jnu_e(38fedf92a6b14b51).(nu + 1.0, t->jcxx . . $ gsl_dht_struct#j.[m], &J); |
| 144 | t->J2cxx . . $ gsl_dht_struct#J2.[m] = J.valcxx . . $ gsl_sf_result_struct#val. * J.valcxx . . $ gsl_sf_result_struct#val.; |
| 145 | } |
| 146 | |
| 147 | /* J_nu(j[n] j[m] / j[N]) = Jjj[n(n-1)/2 + m - 1], 1 <= n,m <= size |
| 148 | */ |
| 149 | for(n=1; n<t->sizecxx . . $ gsl_dht_struct#size.+1; n++) { |
| 150 | for(m=1; m<=n; m++) { |
| 151 | double arg = t->jcxx . . $ gsl_dht_struct#j.[n] * t->jcxx . . $ gsl_dht_struct#j.[m] / jN; |
| 152 | gsl_sf_resultcxx . . $ gsl_sf_result# J; |
| 153 | stat_J += gsl_sf_bessel_Jnu_ecxx . . $ gsl_sf_bessel_Jnu_e(38fedf92a6b14b51).(nu, arg, &J); |
| 154 | t->Jjjcxx . . $ gsl_dht_struct#Jjj.[n*(n-1)/2 + m - 1] = J.valcxx . . $ gsl_sf_result_struct#val.; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | if(stat_J != 0) { |
| 159 | GSL_ERRORcxx . . $ `external/gsl/gsl_errno.h:104:9`!("error computing bessel function", GSL_EFAILED); |
| 160 | } |
| 161 | else { |
| 162 | return stat_bz; |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | |
| 168 | double gsl_dht_x_samplecxx . . $ gsl_dht_x_sample(93805cc2749c5242).(const gsl_dhtcxx . . $ gsl_dht# * t, int n) |
| 169 | { |
| 170 | return t->jcxx . . $ gsl_dht_struct#j.[n+1]/t->jcxx . . $ gsl_dht_struct#j.[t->sizecxx . . $ gsl_dht_struct#size.+1] * t->xmaxcxx . . $ gsl_dht_struct#xmax.; |
| 171 | } |
| 172 | |
| 173 | |
| 174 | double gsl_dht_k_samplecxx . . $ gsl_dht_k_sample(93805cc2749c5242).(const gsl_dhtcxx . . $ gsl_dht# * t, int n) |
| 175 | { |
| 176 | return t->jcxx . . $ gsl_dht_struct#j.[n+1] / t->xmaxcxx . . $ gsl_dht_struct#xmax.; |
| 177 | } |
| 178 | |
| 179 | |
| 180 | void gsl_dht_freecxx . . $ gsl_dht_free(f1118a3655c07c47).(gsl_dhtcxx . . $ gsl_dht# * t) |
| 181 | { |
| 182 | freecxx . . $ free(5d22bdacc48458e8).(t->J2cxx . . $ gsl_dht_struct#J2.); |
| 183 | freecxx . . $ free(5d22bdacc48458e8).(t->Jjjcxx . . $ gsl_dht_struct#Jjj.); |
| 184 | freecxx . . $ free(5d22bdacc48458e8).(t->jcxx . . $ gsl_dht_struct#j.); |
| 185 | freecxx . . $ free(5d22bdacc48458e8).(t); |
| 186 | } |
| 187 | |
| 188 | |
| 189 | int |
| 190 | gsl_dht_applycxx . . $ gsl_dht_apply(9ed2368c09b995c5).(const gsl_dhtcxx . . $ gsl_dht# * t, double * f_in, double * f_out) |
| 191 | { |
| 192 | const double jN = t->jcxx . . $ gsl_dht_struct#j.[t->sizecxx . . $ gsl_dht_struct#size. + 1]; |
| 193 | const double r = t->xmaxcxx . . $ gsl_dht_struct#xmax. / jN; |
| 194 | size_t m; |
| 195 | size_t i; |
| 196 | |
| 197 | for(m=0; m<t->sizecxx . . $ gsl_dht_struct#size.; m++) { |
| 198 | double sum = 0.0; |
| 199 | double Y; |
| 200 | for(i=0; i<t->sizecxx . . $ gsl_dht_struct#size.; i++) { |
| 201 | /* Need to find max and min so that we |
| 202 | * address the symmetric Jjj matrix properly. |
| 203 | * FIXME: we can presumably optimize this |
| 204 | * by just running over the elements of Jjj |
| 205 | * in a deterministic manner. |
| 206 | */ |
| 207 | size_t m_local; |
| 208 | size_t n_local; |
| 209 | if(i < m) { |
| 210 | m_local = i; |
| 211 | n_local = m; |
| 212 | } |
| 213 | else { |
| 214 | m_local = m; |
| 215 | n_local = i; |
| 216 | } |
| 217 | Y = t->Jjjcxx . . $ gsl_dht_struct#Jjj.[n_local*(n_local+1)/2 + m_local] / t->J2cxx . . $ gsl_dht_struct#J2.[i+1]; |
| 218 | sum += Y * f_in[i]; |
| 219 | } |
| 220 | f_out[m] = sum * 2.0 * r*r; |
| 221 | } |
| 222 | |
| 223 | return GSL_SUCCESScxx . . $ GSL_SUCCESS.; |
| 224 | } |
| 225 |