Try to debug error

This commit is contained in:
Guilhem Lavaux 2014-06-13 17:38:49 +02:00
parent 00f4f0a00a
commit 60a477a4c0
2 changed files with 45 additions and 42 deletions

View File

@ -6,6 +6,7 @@ from libc.math cimport sin, cos, abs, floor, sqrt
import numpy as np
cimport numpy as npx
cimport cython
from copy cimport *
ctypedef npx.float64_t DTYPE_t
DTYPE=np.float64
@ -560,11 +561,11 @@ cdef DTYPE_t cube_integral_trilin(DTYPE_t u[3], DTYPE_t u0[3], int r[1], DTYPE_t
alpha_max = tmp_a
j = i
if (u0[i] < 0 or u0[i] > 1):
err[0] = 1
with gil:
print("Bouh! u0[%d] = %lg" % (i, u0[i]))
return 0
# if (u0[i] < 0 or u0[i] > 1):
# err[0] = 1
# with gil:
# print("Bouh! u0[%d] = %lg" % (i, u0[i]))
# return 0
I = compute_projection(vertex_value, u, u0, alpha_max)
@ -595,10 +596,6 @@ cdef DTYPE_t integrator1(DTYPE_t[:,:,:] density,
cdef int i
for i in xrange(3):
# if u[i] < 0:
# a[i][0] = iu0[i]-1
# a[i][1] = iu0[i]
# else:
a[i][0] = iu0[i]
a[i][1] = iu0[i]+1
@ -658,17 +655,19 @@ cdef DTYPE_t C_line_of_sight_projection(DTYPE_t[:,:,:] density,
u0[i] = a_u[i]*min_distance
ifu0[i] = half_N+u0[i]+shifter[i]
if (ifu0[i] <= 0 or ifu0[i] >= N):
with gil:
print "BLABLA"
return 0
iu0[i] = int(floor(ifu0[i]))
u0[i] = ifu0[i]-iu0[i]
u_delta[i] = 1 if iu0[i] > 0 else -1
if (not ((iu0[i]>= 0) and (iu0[i] < N))):
out_err[0] = 1
return 0
# if (not ((iu0[i]>= 0) and (iu0[i] < N))):
# out_err[0] = 1
# return 0
if (not (u0[i]>=0 and u0[i]<=1)):
out_err[0] = 1
return 0
# if (not (u0[i]>=0 and u0[i]<=1)):
# out_err[0] = 1
# return 0
completed = 0
if ((iu0[0] >= N) or (iu0[0] <= 0) or
@ -682,11 +681,11 @@ cdef DTYPE_t C_line_of_sight_projection(DTYPE_t[:,:,:] density,
err[0] = 0
I0 += integrator(density, u, u0, u_delta, iu0, jumper, err)
if err[0] == 1:
with gil:
print("Bah! error!")
out_err[0] = 1
return 0
# if err[0] == 1:
# with gil:
# print("Bah! error!")
# out_err[0] = 1
# return 0
if u[jumper[0]] < 0:
iu0[jumper[0]] -= 1
@ -703,7 +702,7 @@ cdef DTYPE_t C_line_of_sight_projection(DTYPE_t[:,:,:] density,
else:
dist2 = 0
for i in range(3):
delta = iu0[i]+u0[i]-half_N
delta = iu0[i]+u0[i]-half_N-shifter[i]
dist2 += delta*delta
if (dist2 > max_distance2):
@ -731,8 +730,8 @@ def line_of_sight_projection(DTYPE_t[:,:,:] density not None,
u,
min_distance,
max_distance, shifter, integrator_id, out_err)
if out_err[0] == 1:
raise RuntimeError("Error occured during integration")
# if out_err[0] == 1:
# raise RuntimeError("Error occured during integration")
return v
cdef double _spherical_projloop(double theta, double phi, DTYPE_t[:,:,:] density,
@ -747,24 +746,6 @@ cdef double _spherical_projloop(double theta, double phi, DTYPE_t[:,:,:] density
return C_line_of_sight_projection(density, u0, min_distance, max_distance, shifter, integrator_id, out_err)
ctypedef fused sum_type:
cython.int
cython.float
npx.uint64_t
npx.uint32_t
@cython.boundscheck(False)
cdef sum_type _mysum(sum_type[:] jobs) nogil:
cdef sum_type s
cdef npx.uint64_t N
cdef int i
s = 0
N = jobs.shape[0]
for i in xrange(N):
s += jobs[i]
return s
@cython.boundscheck(False)
def spherical_projection(int Nside,
@ -808,7 +789,7 @@ def spherical_projection(int Nside,
if omp_get_thread_num() == 0 and progress != 0 and (i%booster) == 0:
with gil:
p.update(_mysum(job_done))
out_err[0] = 0
# out_err[0] = 0
outm[i] = _spherical_projloop(theta[i], phi[i], density_view, min_distance, max_distance, shifter, integrator_id, out_err)
job_done[omp_get_thread_num()] = i

22
python/copy.pxd Normal file
View File

@ -0,0 +1,22 @@
cimport cython
cimport numpy as npx
ctypedef fused sum_type:
cython.int
cython.float
npx.uint64_t
npx.uint32_t
@cython.boundscheck(False)
cdef inline sum_type _mysum(sum_type[:] jobs) nogil:
cdef sum_type s
cdef npx.uint64_t N
cdef int i
s = 0
N = jobs.shape[0]
for i in xrange(N):
s += jobs[i]
return s