From 0d688fbf7d2d5f15cbe4d6406ee51865516da921 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Tue, 23 Sep 2014 11:59:46 +0200 Subject: [PATCH] Added runtime checks to cl_CIC_Density --- python/cosmotool/cl_cic.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/python/cosmotool/cl_cic.py b/python/cosmotool/cl_cic.py index bf16b0a..b53c96b 100644 --- a/python/cosmotool/cl_cic.py +++ b/python/cosmotool/cl_cic.py @@ -227,6 +227,13 @@ def cl_CIC_Density(particles, Ngrid, Lbox, context=None, periodic=True, centered if context is None: context = cl.create_some_context() - cic = CIC_CL(context, ndim=3, centered=centered) + ktype = particles.dtype + if ktype != np.float32 and ktype != np.float64: + raise ValueError("particles may only be float32 or float64") - return cic.run(particles, Ng, L) + if len(particles.shape) != 2 or particles.shape[1] != 3: + raise ValueError("particles may only be a Nx3 array") + + cic = CIC_CL(context, ndim=3, centered=centered, ktype=ktype) + + return cic.run(particles, Ngrid, Lbox)