Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
e1bfcf52
Commit
e1bfcf52
authored
Sep 11, 2017
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Repair NumPy conditional expressions in Pythran: needs to use operator[] instead of operator().
parent
99309aed
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
2 deletions
+24
-2
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+1
-1
Cython/Compiler/Pythran.py
Cython/Compiler/Pythran.py
+1
-1
tests/run/numpy_pythran.pyx
tests/run/numpy_pythran.pyx
+22
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
e1bfcf52
...
@@ -4226,7 +4226,7 @@ class BufferIndexNode(_IndexingBaseNode):
...
@@ -4226,7 +4226,7 @@ class BufferIndexNode(_IndexingBaseNode):
if
is_pythran_expr
(
self
.
base
.
type
):
if
is_pythran_expr
(
self
.
base
.
type
):
res
=
self
.
result
()
res
=
self
.
result
()
code
.
putln
(
"__Pyx_call_destructor(%s);"
%
res
)
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
,
res
,
res
,
self
.
base
.
pythran_result
(),
self
.
base
.
pythran_result
(),
...
...
Cython/Compiler/Pythran.py
View file @
e1bfcf52
...
@@ -76,7 +76,7 @@ def pythran_indexing_type(type_, indices):
...
@@ -76,7 +76,7 @@ def pythran_indexing_type(type_, indices):
raise
ValueError
(
"unsupported indexing type %s!"
%
idx
.
type
)
raise
ValueError
(
"unsupported indexing type %s!"
%
idx
.
type
)
indexing
=
","
.
join
(
index_code
(
idx
)
for
idx
in
indices
)
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
):
def
pythran_indexing_code
(
indices
):
...
...
tests/run/numpy_pythran.pyx
View file @
e1bfcf52
...
@@ -32,3 +32,25 @@ def diffuse_numpy(cnp.ndarray[double, ndim=2] u, int N):
...
@@ -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
[
1
:
-
1
,
2
:]
-
2
*
u
[
1
:
-
1
,
1
:
-
1
]
+
u
[
1
:
-
1
,
0
:
-
2
])
u
[:,
:]
=
temp
[:,
:]
u
[:,
:]
=
temp
[:,
:]
temp
[:,
:]
=
0.0
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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment