summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chroma/gpu/pdf.py4
-rw-r--r--chroma/io/root.py4
-rw-r--r--chroma/likelihood.py4
-rw-r--r--chroma/tools.py4
-rw-r--r--setup.py4
-rw-r--r--test/test_propagation.py3
6 files changed, 14 insertions, 9 deletions
diff --git a/chroma/gpu/pdf.py b/chroma/gpu/pdf.py
index 1b6340f..5d27f63 100644
--- a/chroma/gpu/pdf.py
+++ b/chroma/gpu/pdf.py
@@ -2,7 +2,7 @@ import numpy as np
from pycuda import gpuarray as ga
import pycuda.driver as cuda
from chroma.gpu.tools import get_cu_module, cuda_options, GPUFuncs, chunk_iterator
-from chroma.tools import profile_if_possible
+from chroma.tools import profile_if_possible, count_nonzero
class GPUKernelPDF(object):
def __init__(self):
@@ -259,7 +259,7 @@ class GPUPDF(object):
time_only: bool
If True, only the time observable will be used in the PDF.
"""
- self.event_nhit = np.count_nonzero(event_hit)
+ self.event_nhit = count_nonzero(event_hit)
# Define a mapping from an array of len(event_hit) to an array of length event_nhit
self.map_hit_offset_to_channel_id = np.where(event_hit)[0].astype(np.uint32)
diff --git a/chroma/io/root.py b/chroma/io/root.py
index 20c20e2..935299b 100644
--- a/chroma/io/root.py
+++ b/chroma/io/root.py
@@ -2,7 +2,7 @@ import os, os.path
import shutil
import numpy as np
import chroma.event as event
-
+from chroma.tools import count_nonzero
from chroma.rootimport import ROOT
# Check if we have already imported the ROOT class due to a user's
@@ -216,7 +216,7 @@ class RootWriter(object):
self.ev.vertices[i].t0 = vertex.t0
if pyev.channels is not None:
- nhit = np.count_nonzero(pyev.channels.hit)
+ nhit = count_nonzero(pyev.channels.hit)
if nhit > 0:
ROOT.fill_channels(self.ev, nhit, np.arange(len(pyev.channels.t))[pyev.channels.hit].astype(np.int32), pyev.channels.t, pyev.channels.q, pyev.channels.flags, len(pyev.channels.hit))
else:
diff --git a/chroma/likelihood.py b/chroma/likelihood.py
index a29dc6c..50d9593 100644
--- a/chroma/likelihood.py
+++ b/chroma/likelihood.py
@@ -2,7 +2,7 @@ import numpy as np
from math import sqrt
from uncertainties import ufloat, unumpy
from itertools import islice, izip, repeat
-from chroma.tools import profile_if_possible
+from chroma.tools import profile_if_possible, count_nonzero
class Likelihood(object):
"Class to evaluate likelihoods for detector events."
@@ -189,7 +189,7 @@ if __name__ == '__main__':
event = sim.simulate(islice(constant_particle_gun('e-',(0,0,0),(1,0,0),100.0), 1)).next()
- print 'nhit = %i' % np.count_nonzero(event.channels.hit)
+ print 'nhit = %i' % count_nonzero(event.channels.hit)
likelihood = Likelihood(sim, event)
diff --git a/chroma/tools.py b/chroma/tools.py
index 831a356..2a1167e 100644
--- a/chroma/tools.py
+++ b/chroma/tools.py
@@ -4,6 +4,10 @@ import datetime
import sys
import math
+def count_nonzero(array):
+ '''Return the number of nonzero elements in this array'''
+ return (array != 0).sum()
+
def filled_array(value, shape, dtype):
'''Create a numpy array of given `shape` and `dtype` filled with the scalar `value`.'''
a = np.empty(shape=shape, dtype=dtype)
diff --git a/setup.py b/setup.py
index aa53c2f..69eb213 100644
--- a/setup.py
+++ b/setup.py
@@ -42,8 +42,8 @@ setup(
],
setup_requires = ['pyublas'],
- install_requires = ['uncertainties','pyzmq-static','spnav', 'pycuda',
- 'numpy>=1.6','pygame'],
+ install_requires = ['uncertainties','pyzmq-static','spnav', 'pycuda',
+ 'numpy', 'pygame'],
test_suite = 'nose.collector',
)
diff --git a/test/test_propagation.py b/test/test_propagation.py
index 34e64f5..e1b52ae 100644
--- a/test/test_propagation.py
+++ b/test/test_propagation.py
@@ -5,6 +5,7 @@ from chroma.geometry import Solid, Geometry, vacuum
from chroma.make import box
from chroma.sim import Simulation
from chroma.event import Photons
+from chroma.tools import count_nonzero
class TestPropagation(unittest.TestCase):
def testAbort(self):
@@ -51,6 +52,6 @@ class TestPropagation(unittest.TestCase):
max_steps=10).next().photons_end
aborted = (photons_end.flags & (1 << 31)) > 0
print 'aborted photons: %1.1f' % \
- (float(np.count_nonzero(aborted)) / nphotons)
+ (float(count_nonzero(aborted)) / nphotons)
self.assertFalse(aborted.any())