Skip to content

Commit ace8ec3

Browse files
authored
Solving the signedness problem with integers and releasing version 2.0.0
* Fixes #268; Solving the signedness problem with integers. * Small clean-up. * Switch to use size_t everywhere. * Fixing numpy seed in the example script for easier debugging. * CHANGELOG updated for python3 release. * Mentioning JOSS paper update and v1.2.2 mentioned in the CHANGELOG.
1 parent 6557cf7 commit ace8ec3

16 files changed

Lines changed: 89 additions & 83 deletions

CHANGELOG.rst

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ and this project adheres to
3333
.. Attribution
3434
.. ^^^^^^^^^^^
3535
36-
[v2.0.0] - 2023-02-03
36+
[v2.0.0] - 2023-02-16
3737
~~~~~~~~~~~~~~~~~~~~~
3838

3939
Summary
4040
^^^^^^^
4141

42-
* This major release candidate migrates X-PSI from Python2 (X-PSI v1.2.1 or lower) to Python3 (X-PSI v2.0 and higher), with corresponding updates and improvements to all documentation and tutorials.
42+
* This major release migrates X-PSI from Python2 (X-PSI v1.2.1 or lower) to Python3 (X-PSI v2.0 and higher), with corresponding updates and improvements to all documentation and tutorials.
4343

4444
Fixed
4545
^^^^^
@@ -53,32 +53,36 @@ Added
5353
* Post-processing - adding names of parameters across diagonal in corner plots
5454
* Extra yticks options for plotting functions in the tutorials
5555
* `--noopenmp` install option for Mac Users
56-
* Added option to fix the random seed for the synthetic data generation in Python3 version
56+
* Added option to fix the random seed for the synthetic data generation in Python3 version.
57+
* Added option to plot y-axis in the residuals in a user selected scale (e.g., either log or lin).
5758

5859
Changed
5960
^^^^^^^
6061

61-
* Modified all X-PSI routines to work in Python3
62+
* Modified all X-PSI routines to work in Python3.
6263
* General Documentation (Applications, Team and Acknowledgements, Citation, Future pages) updated for both Python2 and Python3 documentation branches.
63-
* Installation and tutorial pages modified for Python3
64-
* Module generator updated for Python3 and documentation added
65-
* Projection tool updated for Python3 and documentation added
66-
* Github actions modified to work in Python3
67-
* Github actions modified to use mamba with install commands on one line to improve speed
68-
* Updated references in the documentation and tutorial notebooks
69-
* CustomInstrument channel_edges argument now changed to mandatory in tutorial notebooks and examples
70-
* X-PSI Postprocessing now supports up-to-date versions of Nestcheck, Getdist.
64+
* Installation and tutorial pages modified for Python3.
65+
* Module generator updated for Python3 and documentation added.
66+
* Projection tool updated for Python3 and documentation added.
67+
* Github actions modified to work in Python3.
68+
* Github actions modified to use mamba with install commands on one line to improve speed.
69+
* Updated references in the documentation and tutorial notebooks.
70+
* CustomInstrument channel_edges argument now changed to mandatory in tutorial notebooks and examples.
71+
* X-PSI Postprocessing now supports up-to-date versions of NestCheck and GetDist.
72+
* Specified the integer types to be always size_t in Cython files in those integer comparisons that raised warnings for different signedness of integers.
73+
* The JOSS paper has been updated to link to published version.
74+
* A final Python2 release of X-PSI (v1.2.2) was created in the Python2 branch to match the JOSS publication.
7175

7276
Deprecated
7377
^^^^^^^^^^
7478

75-
* The Python2 version of X-PSI (v1.2.1) is now considered deprecated, although documentation and tutorials are still available.
79+
* The Python2 version of X-PSI (v1.2.2) is now considered deprecated, although documentation and tutorials are still available.
7680

7781
Removed
7882
^^^^^^^
7983

80-
* Removed requirement of FFMPEG for Animations in tutorials
81-
* Suppressed printf() statements from c code in tutorial notebooks
84+
* Removed requirement of FFMPEG for Animations in tutorials.
85+
* Suppressed printf() statements from c code in tutorial notebooks.
8286

8387
Attribution
8488
^^^^^^^^^^^

examples/examples_fast/Modules/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import xpsi
77
from xpsi.global_imports import gravradius
88

9+
np.random.seed(xpsi._rank+10)
10+
911
import time
1012

1113
from CustomInstrument import CustomInstrument

xpsi/cellmesh/integrator.pyx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,16 +207,16 @@ def integrate(size_t numThreads,
207207
cos_deflection = np.zeros((deflection.shape[0],
208208
deflection.shape[1]),
209209
dtype = np.double)
210-
for i in range(deflection.shape[0]):
211-
for j in range(deflection.shape[1]):
210+
for i in range(<size_t>deflection.shape[0]):
211+
for j in range(<size_t>deflection.shape[1]):
212212
cos_deflection[i,j] = cos(deflection[i, N_R - j - 1])
213213

214214
cos_alpha_alt = np.zeros((cos_alpha.shape[0],
215215
cos_alpha.shape[1]),
216216
dtype = np.double)
217217

218-
for i in range(cos_alpha.shape[0]):
219-
for j in range(cos_alpha.shape[1]):
218+
for i in range(<size_t>cos_alpha.shape[0]):
219+
for j in range(<size_t>cos_alpha.shape[1]):
220220
cos_alpha_alt[i,j] = cos_alpha[i, N_R - j - 1]
221221

222222
if image_order_limit is not None:
@@ -274,12 +274,12 @@ def integrate(size_t numThreads,
274274
j = 0
275275
# use this to decide whether or not to compute parallel:
276276
# does the local vicinity of the parallel contain radiating material?
277-
while j < cellArea.shape[1]:
277+
while j < <size_t>cellArea.shape[1]:
278278
if CELL_RADIATES[i,j] == 1:
279279
break
280280
j = j + 1
281281

282-
if j == cellArea.shape[1]:
282+
if j == <size_t>cellArea.shape[1]:
283283
continue
284284

285285
gsl_interp_accel_reset(accel_alpha[T])
@@ -561,7 +561,7 @@ def integrate(size_t numThreads,
561561
gsl_interp_init(interp_GEOM[T], phase_ptr, GEOM_ptr, N_L)
562562

563563
j = 0
564-
while j < cellArea.shape[1] and terminate[T] == 0:
564+
while j < <size_t>cellArea.shape[1] and terminate[T] == 0:
565565
if CELL_RADIATES[i,j] == 1:
566566
phi_shift = phi[i,j]
567567
for k in range(N_P):

xpsi/cellmesh/integrator_for_azimuthal_invariance.pyx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,16 @@ def integrate(size_t numThreads,
212212
cos_deflection = np.zeros((deflection.shape[0],
213213
deflection.shape[1]),
214214
dtype = np.double)
215-
for i in range(deflection.shape[0]):
216-
for j in range(deflection.shape[1]):
215+
for i in range(<size_t>deflection.shape[0]):
216+
for j in range(<size_t>deflection.shape[1]):
217217
cos_deflection[i,j] = cos(deflection[i, N_R - j - 1])
218218

219219
cos_alpha_alt = np.zeros((cos_alpha.shape[0],
220220
cos_alpha.shape[1]),
221221
dtype = np.double)
222222

223-
for i in range(cos_alpha.shape[0]):
224-
for j in range(cos_alpha.shape[1]):
223+
for i in range(<size_t>cos_alpha.shape[0]):
224+
for j in range(<size_t>cos_alpha.shape[1]):
225225
cos_alpha_alt[i,j] = cos_alpha[i, N_R - j - 1]
226226

227227
if image_order_limit is not None:
@@ -279,13 +279,13 @@ def integrate(size_t numThreads,
279279
j = 0
280280
# use this to decide whether or not to compute parallel:
281281
# Does the local vicinity of the parallel contain radiating material?
282-
while j < cellArea.shape[1]:
282+
while j < <size_t>cellArea.shape[1]:
283283
if CELL_RADIATES[i,j] == 1:
284284
J = j
285285
break
286286
j = j + 1
287287

288-
if j == cellArea.shape[1]:
288+
if j == <size_t>cellArea.shape[1]:
289289
continue
290290

291291
gsl_interp_accel_reset(accel_alpha[T])
@@ -557,7 +557,7 @@ def integrate(size_t numThreads,
557557
gsl_interp_init(interp_PROFILE[T], phase_ptr, profile_ptr, N_L)
558558

559559
j = 0
560-
while j < cellArea.shape[1] and terminate[T] == 0:
560+
while j < <size_t>cellArea.shape[1] and terminate[T] == 0:
561561
if CELL_RADIATES[i,j] == 1:
562562
phi_shift = phi[i,j]
563563
for k in range(N_P):

xpsi/cellmesh/integrator_for_time_invariance.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,16 @@ def integrate(size_t numThreads,
164164
cos_deflection = np.zeros((deflection.shape[0],
165165
deflection.shape[1]),
166166
dtype = np.double)
167-
for i in range(deflection.shape[0]):
168-
for j in range(deflection.shape[1]):
167+
for i in range(<size_t>deflection.shape[0]):
168+
for j in range(<size_t>deflection.shape[1]):
169169
cos_deflection[i,j] = cos(deflection[i, N_R - j - 1])
170170

171171
cos_alpha_alt = np.zeros((cos_alpha.shape[0],
172172
cos_alpha.shape[1]),
173173
dtype = np.double)
174174

175-
for i in range(cos_alpha.shape[0]):
176-
for j in range(cos_alpha.shape[1]):
175+
for i in range(<size_t>cos_alpha.shape[0]):
176+
for j in range(<size_t>cos_alpha.shape[1]):
177177
cos_alpha_alt[i,j] = cos_alpha[i, N_R - j - 1]
178178

179179
if image_order_limit is not None:

xpsi/likelihoods/_poisson_likelihood_given_background.pyx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def poisson_likelihood_given_background(double exposure_time,
104104
raise TypeError('An iterable is required to specify component-by-'
105105
'component positivity.')
106106
else:
107-
if len(allow_negative) != num_components:
107+
if <size_t>len(allow_negative) != num_components:
108108
raise ValueError('Number of allow_negative declarations does '
109109
'not match the number of components..')
110110

@@ -130,7 +130,7 @@ def poisson_likelihood_given_background(double exposure_time,
130130
cdef gsl_interp *inter_ptr = NULL
131131
cdef accel *acc_ptr = NULL
132132

133-
for i in range(STAR.shape[0]):
133+
for i in range(<size_t>STAR.shape[0]):
134134
for p in range(num_components):
135135
signal = components[p]
136136
signal_phase_set = component_phases[p]
@@ -144,7 +144,7 @@ def poisson_likelihood_given_background(double exposure_time,
144144
gsl_interp_init(interp_ptr, phases_ptr, signal_ptr,
145145
signal_phase_set.shape[0])
146146

147-
for j in range(phases.shape[0] - 1):
147+
for j in range(<size_t>phases.shape[0] - 1):
148148
a = phases[j] + phase_shift
149149
b = phases[j+1] + phase_shift
150150

@@ -180,7 +180,7 @@ def poisson_likelihood_given_background(double exposure_time,
180180
if _val > 0.0 or _allow_negative[p] == 1:
181181
STAR[i,j] += _val
182182

183-
for j in range(phases.shape[0] - 1): # interpolant safety procedure
183+
for j in range(<size_t>phases.shape[0] - 1): # interpolant safety procedure
184184
if STAR[i,j] < 0.0:
185185
STAR[i,j] = 0.0
186186

@@ -195,8 +195,8 @@ def poisson_likelihood_given_background(double exposure_time,
195195
double LOGLIKE = 0.0, EXPEC = 0.0
196196
double n = <double>(phases.shape[0] - 1)
197197

198-
for i in range(STAR.shape[0]):
199-
for j in range(STAR.shape[1]):
198+
for i in range(<size_t>STAR.shape[0]):
199+
for j in range(<size_t>STAR.shape[1]):
200200
EXPEC = (STAR[i,j] + background[i,j]/n) * exposure_time
201201
LOGLIKE -= EXPEC
202202
LOGLIKE += counts[i,j] * log(EXPEC)

xpsi/likelihoods/default_background_marginalisation.pyx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ def precomputation(int[:,::1] data):
5656
size_t i, j
5757
double[::1] precomp = np.zeros(data.shape[0], dtype = np.double)
5858

59-
for i in range(data.shape[0]):
60-
for j in range(data.shape[1]):
59+
for i in range(<size_t>data.shape[0]):
60+
for j in range(<size_t>data.shape[1]):
6161
precomp[i] += gsl_sf_lnfact(<unsigned int>(data[i,j]))
6262

6363
precomp[i] *= -1.0
@@ -79,7 +79,7 @@ ctypedef struct args:
7979

8080
cdef double marginal_integrand(double B, void *params) nogil:
8181

82-
cdef int j
82+
cdef size_t j
8383
cdef double c, x = 0.0
8484
cdef args *a = <args*> params
8585

@@ -99,7 +99,7 @@ cdef double marginal_integrand(double B, void *params) nogil:
9999

100100
cdef double delta(double B, void *params) nogil:
101101

102-
cdef int j
102+
cdef size_t j
103103
cdef double x = 0.0, y = 0.0
104104
cdef args *a = <args*> params
105105

@@ -304,7 +304,7 @@ def eval_marginal_likelihood(double exposure_time,
304304
raise TypeError('An iterable is required to specify component-by-'
305305
'component positivity.')
306306
else:
307-
if len(allow_negative) != num_components:
307+
if <size_t> len(allow_negative) != num_components:
308308
raise ValueError('Number of allow_negative declarations does '
309309
'not match the number of components..')
310310

@@ -325,7 +325,7 @@ def eval_marginal_likelihood(double exposure_time,
325325
cdef gsl_interp *inter_ptr = NULL
326326
cdef accel *acc_ptr = NULL
327327

328-
for i in range(STAR.shape[0]):
328+
for i in range(<size_t> STAR.shape[0]):
329329
for p in range(num_components):
330330
pulse = components[p]
331331
pulse_phase_set = component_phases[p]
@@ -339,7 +339,7 @@ def eval_marginal_likelihood(double exposure_time,
339339
gsl_interp_init(interp_ptr, phases_ptr, pulse_ptr,
340340
pulse_phase_set.shape[0])
341341

342-
for j in range(phases.shape[0] - 1):
342+
for j in range(<size_t> (phases.shape[0] - 1)):
343343
pa = phases[j] + phase_shift
344344
pb = phases[j+1] + phase_shift
345345

@@ -375,13 +375,13 @@ def eval_marginal_likelihood(double exposure_time,
375375
if _val > 0.0 or _allow_negative[p] == 1:
376376
STAR[i,j] += _val
377377

378-
for j in range(phases.shape[0] - 1): # interpolant safety procedure
378+
for j in range(<size_t> (phases.shape[0] - 1)): # interpolant safety procedure
379379
if STAR[i,j] < 0.0:
380380
STAR[i,j] = 0.0
381381

382382
av_DATA = 0.0; av_STAR = 0.0
383383

384-
for j in range(phases.shape[0] - 1):
384+
for j in range(<size_t> (phases.shape[0] - 1)):
385385
STAR[i,j] *= n
386386
if background is not None:
387387
STAR[i,j] += _background[i,j]

xpsi/pixelmesh/RK_IP2S_tracer.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ cdef int RK(_RAY *const RAY,
160160
if status == GSL_SUCCESS:
161161
RAY.NUMSTEPS += 1
162162

163-
if RAY.NUMSTEPS >= RAY.MAXSTEPS:
163+
if <size_t> RAY.NUMSTEPS >= RAY.MAXSTEPS:
164164
printf("\n\nSteps exceeded... %d", RAY.NUMSTEPS)
165165
printf("\nx: %.8e; y: %.8e", X_IP, Y_IP)
166166
printf("\ny[]: %.8e, %.8e, %.8e, %.8e, %.8e, %.8e",
@@ -296,7 +296,7 @@ cdef int RK(_RAY *const RAY,
296296
RAY.NUM_SINGULARITY_STEPS += 1
297297
#printf("\nSingularity steps: %d", RAY.NUM_SINGULARITY_STEPS)
298298

299-
if RAY.NUM_SINGULARITY_STEPS == RAY.MAXSTEPS:
299+
if <size_t>RAY.NUM_SINGULARITY_STEPS == RAY.MAXSTEPS:
300300
RAY.EVOLVE = 0
301301
break
302302

xpsi/pixelmesh/integrator.pyx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,8 @@ def integrate(size_t numThreads,
365365

366366
if cache_intensities == 1:
367367
for search in range(N_CP):
368-
if k == cache_phase_indices[search]:
369-
if cache_counter_E < N_CE and p == cache_energy_indices[cache_counter_E]:
368+
if k == <size_t> cache_phase_indices[search]:
369+
if cache_counter_E < N_CE and p == <size_t> cache_energy_indices[cache_counter_E]:
370370
if single_precision_cache == 0:
371371
IMAGE_DUB[cache_phase_indices[search], cache_counter_E, INDEX + 1] = I_E / energies[p]
372372
else:
@@ -397,17 +397,17 @@ def integrate(size_t numThreads,
397397

398398
if cache_intensities == 1:
399399
for search in range(N_CP):
400-
if k == cache_phase_indices[search]:
401-
if cache_counter_E < N_CE and p == cache_energy_indices[cache_counter_E]:
400+
if k == <size_t> cache_phase_indices[search]:
401+
if cache_counter_E < N_CE and p == <size_t> cache_energy_indices[cache_counter_E]:
402402
if single_precision_cache == 0:
403403
IMAGE_DUB[cache_phase_indices[search], cache_counter_E, 0] = I_E / energies[p]
404404
else:
405405
IMAGE[cache_phase_indices[search], cache_counter_E, 0] = I_E / energies[p]
406406

407407
if cache_intensities == 1:
408408
for search in range(N_CP):
409-
if k == cache_phase_indices[search]:
410-
if cache_counter_E < N_CE and p == cache_energy_indices[cache_counter_E]:
409+
if k == <size_t> cache_phase_indices[search]:
410+
if cache_counter_E < N_CE and p == <size_t> cache_energy_indices[cache_counter_E]:
411411
cache_counter_E = cache_counter_E + 1
412412

413413
integrated_flux[k,p] *= SEMI_MINOR * SEMI_MAJOR

xpsi/surface_radiation_field/__init__.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,9 @@ def effective_gravity(double[::1] cos_colatitude,
452452
cdef double[::1] gravity = np.zeros(cos_colatitude.shape[0],
453453
dtype=np.double)
454454

455-
cdef size_t i
455+
cdef unsigned int i
456456

457-
for i in range(gravity.shape[0]):
457+
for i in range(<size_t>gravity.shape[0]):
458458
gravity[i] = effectiveGravity(cos_colatitude[i],
459459
R_eq[i],
460460
zeta[i],

0 commit comments

Comments
 (0)