12 Jun 2012 16:12
having trouble with fused types and ndarray of arbitrary dimensions
Thouis (Ray) Jones <thouis <at> gmail.com>
2012-06-12 14:12:28 GMT
2012-06-12 14:12:28 GMT
I would like to write a function using ndarrarys of fused types. The
only restriction I would like on the input arrays is that they be
broadcastable.
My first attempt was:
ctypedef fused fused1:
np.int32_t
np.int64_t
ctypedef fused fused2:
np.int32_t
np.int64_t
np.float64_t
np.float32_t
def labeled_reduce(np.ndarray[fused1] labels, np.ndarray[fused2]
values, ops)
print "called with", labels.dtype, values.dtype, ops
But that requires that labels and values be 1D.
I ended up writing it like this:
def _labeled_reduce(np.ndarray labels, np.ndarray values, fused1
labelexample, fused2 valueexample, ops=0):
print "called with", labels.dtype, values.dtype, ops
def labeled_reduce(np.ndarray labels, np.ndarray values, ops):
typemap = {np.float32 : 'float32_t',
np.float64 : 'float64_t',
np.int32 : 'int32_t',
(Continue reading)
RSS Feed