Commit e1bfcf52 authored by Stefan Behnel's avatar Stefan Behnel

Repair NumPy conditional expressions in Pythran: needs to use operator[] instead of operator().

parent 99309aed
......@@ -4226,7 +4226,7 @@ class BufferIndexNode(_IndexingBaseNode):
if is_pythran_expr(self.base.type):
res = self.result()
code.putln("__Pyx_call_destructor(%s);" % res)
code.putln("new (&%s) decltype(%s){%s(%s)};" % (
code.putln("new (&%s) decltype(%s){%s[%s]};" % (
res,
res,
self.base.pythran_result(),
......
......@@ -76,7 +76,7 @@ def pythran_indexing_type(type_, indices):
raise ValueError("unsupported indexing type %s!" % idx.type)
indexing = ",".join(index_code(idx) for idx in indices)
return type_remove_ref("decltype(std::declval<%s>()(%s))" % (pythran_type(type_), indexing))
return type_remove_ref("decltype(std::declval<%s>()[%s])" % (pythran_type(type_), indexing))
def pythran_indexing_code(indices):
......
......@@ -32,3 +32,25 @@ def diffuse_numpy(cnp.ndarray[double, ndim=2] u, int N):
u[1:-1, 2:] - 2 * u[1:-1, 1:-1] + u[1:-1, 0:-2])
u[:, :] = temp[:, :]
temp[:, :] = 0.0
def calculate_tax(cnp.ndarray[double, ndim=1] d):
"""
>>> mu, sigma = 10.64, .35
>>> np.random.seed(1234)
>>> d = np.random.lognormal(mu, sigma, 10000)
>>> avg = calculate_tax(d)
>>> 0.243 < avg < 0.244 or avg # 0.24342652180085891
"""
tax_seg1 = d[(d > 256303)] * 0.45 - 16164.53
tax_seg2 = d[(d > 54057) & (d <= 256303)] * 0.42 - 8475.44
seg3 = d[(d > 13769) & (d <= 54057)] - 13769
seg4 = d[(d > 8820) & (d <= 13769)] - 8820
prog_seg3 = seg3 * 0.0000022376 + 0.2397
prog_seg4 = seg4 * 0.0000100727 + 0.14
return (
np.sum(tax_seg1) +
np.sum(tax_seg2) +
np.sum(seg3 * prog_seg3 + 939.57) +
np.sum(seg4 * prog_seg4)
) / np.sum(d)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment