Skip to content

Commit 44d0886

Browse files
committed
Bugfix for int vs longint in aperture module
1 parent dfb6dbd commit 44d0886

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

aperture/aperture.pyx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,16 @@ class RFBucketAperture(Aperture):
223223

224224
@cython.boundscheck(False)
225225
@cython.wraparound(False)
226-
cpdef cytag_lost_rectangular(double[::1] u, unsigned int[::1] alive,
226+
cpdef cytag_lost_rectangular(double[::1] u, int[::1] alive,
227227
double low_lim, double high_lim):
228228
''' Cython function for fast identification and tagging of particles
229229
lost at a rectangular aperture element, i.e. it tags particles with
230230
a spatial coord u (beam.x, beam.y or beam.z) lying outside the
231231
interval (low_lim, high_lim) as lost. Returns whether or not any
232232
lost particles were found. '''
233-
cdef unsigned int n = alive.shape[0]
234-
cdef unsigned int losses = 0
235-
cdef unsigned int i
233+
cdef int n = alive.shape[0]
234+
cdef int losses = 0
235+
cdef int i
236236
for i in xrange(n):
237237
if u[i] < low_lim or u[i] > high_lim:
238238
alive[i] = 0
@@ -242,16 +242,16 @@ cpdef cytag_lost_rectangular(double[::1] u, unsigned int[::1] alive,
242242
@cython.boundscheck(False)
243243
@cython.wraparound(False)
244244
cpdef cytag_lost_circular(
245-
double[::1] u, double[::1] v, unsigned int[::1] alive,
245+
double[::1] u, double[::1] v, int[::1] alive,
246246
double radius_square):
247247
''' Cython function for fast identification and tagging of particles
248248
lost at a circular transverse aperture element of a given radius,
249249
i.e. it tags particles with spatial coords u, v (usually (beam.x,
250250
beam.y)) fulfilling u**2 + v**2 > radius_square as lost. Returns
251251
whether or not any lost particles were found. '''
252-
cdef unsigned int n = alive.shape[0]
253-
cdef unsigned int losses = 0
254-
cdef unsigned int i
252+
cdef int n = alive.shape[0]
253+
cdef int losses = 0
254+
cdef int i
255255
for i in xrange(n):
256256
if (u[i]*u[i] + v[i]*v[i]) > radius_square:
257257
alive[i] = 0

particles/cython_functions.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ def relocate_lost_particles(beam):
3636
cdef double[::1] xp = beam.xp
3737
cdef double[::1] yp = beam.yp
3838
cdef double[::1] dp = beam.dp
39-
cdef unsigned int[::1] id = beam.id
40-
cdef unsigned int[::1] alive = beam.alive
39+
cdef int[::1] id = beam.id
40+
cdef int[::1] alive = beam.alive
4141

4242
# Temporary variables for swapping entries.
4343
cdef double t_x, t_xp, t_y, t_yp, t_z, t_dp
44-
cdef unsigned int t_alive, t_id
44+
cdef int t_alive, t_id
4545

4646
# Find last_alive index.
4747
cdef int n_alive_pri = alive.shape[0]

particles/particles.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ def __init__(self, macroparticlenumber, particlenumber_per_mp, charge,
6868
'''ID of particles in order to keep track of single entries
6969
in the coordinate and momentum arrays.
7070
'''
71-
self.id_all = np.arange(1, self.macroparticlenumber+1, dtype=np.uint)
71+
self.id_all = np.arange(1, self.macroparticlenumber+1, dtype=np.int32)
7272
self.id = self.id_all.view()
7373

7474
'''Alive flag to handle the loss of particles
7575
'''
76-
self.alive_all = np.ones(self.macroparticlenumber, dtype=np.uint)
76+
self.alive_all = np.ones(self.macroparticlenumber, dtype=np.int32)
7777
self.alive = self.alive_all.view()
7878

7979
self.update(coords_n_momenta_dict)

0 commit comments

Comments
 (0)