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
Gwenaël Samain
cython
Commits
a171e51a
Commit
a171e51a
authored
Mar 21, 2018
by
gabrieldemarmiesse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed according to the code review.
parent
5e03b2ed
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
74 additions
and
85 deletions
+74
-85
docs/examples/memoryviews/convolve_fused_types.pyx
docs/examples/memoryviews/convolve_fused_types.pyx
+1
-0
docs/examples/memoryviews/convolve_infer_types.pyx
docs/examples/memoryviews/convolve_infer_types.pyx
+0
-0
docs/examples/memoryviews/convolve_memview.pyx
docs/examples/memoryviews/convolve_memview.pyx
+9
-9
docs/examples/memoryviews/convolve_py.py
docs/examples/memoryviews/convolve_py.py
+0
-0
docs/examples/memoryviews/convolve_typed.pyx
docs/examples/memoryviews/convolve_typed.pyx
+12
-15
docs/src/tutorial/numpy.rst
docs/src/tutorial/numpy.rst
+2
-0
docs/src/userguide/numpy_tutorial.rst
docs/src/userguide/numpy_tutorial.rst
+50
-61
No files found.
docs/examples/
userguide
/convolve_fused_types.pyx
→
docs/examples/
memoryviews
/convolve_fused_types.pyx
View file @
a171e51a
# cython: infer_types=True
import
numpy
as
np
cimport
cython
ctypedef
fused
my_type
:
int
...
...
docs/examples/
userguide
/convolve_infer_types.pyx
→
docs/examples/
memoryviews
/convolve_infer_types.pyx
View file @
a171e51a
File moved
docs/examples/
userguide
/convolve_memview.pyx
→
docs/examples/
memoryviews
/convolve_memview.pyx
View file @
a171e51a
...
...
@@ -9,15 +9,15 @@ def naive_convolve(int [:,:] f, int [:,:] g):
# We don't need to check for the type of NumPy array here because
# a check is already performed when calling the function.
cdef
in
t
x
,
y
,
s
,
t
,
v
,
w
,
s_from
,
s_to
,
t_from
,
t_to
cdef
in
t
vmax
=
f
.
shape
[
0
]
cdef
in
t
wmax
=
f
.
shape
[
1
]
cdef
in
t
smax
=
g
.
shape
[
0
]
cdef
in
t
tmax
=
g
.
shape
[
1
]
cdef
in
t
smid
=
smax
//
2
cdef
in
t
tmid
=
tmax
//
2
cdef
in
t
xmax
=
vmax
+
2
*
smid
cdef
in
t
ymax
=
wmax
+
2
*
tmid
cdef
Py_ssize_
t
x
,
y
,
s
,
t
,
v
,
w
,
s_from
,
s_to
,
t_from
,
t_to
cdef
Py_ssize_
t
vmax
=
f
.
shape
[
0
]
cdef
Py_ssize_
t
wmax
=
f
.
shape
[
1
]
cdef
Py_ssize_
t
smax
=
g
.
shape
[
0
]
cdef
Py_ssize_
t
tmax
=
g
.
shape
[
1
]
cdef
Py_ssize_
t
smid
=
smax
//
2
cdef
Py_ssize_
t
tmid
=
tmax
//
2
cdef
Py_ssize_
t
xmax
=
vmax
+
2
*
smid
cdef
Py_ssize_
t
ymax
=
wmax
+
2
*
tmid
h_np
=
np
.
zeros
([
xmax
,
ymax
],
dtype
=
DTYPE
)
cdef
int
[:,:]
h
=
h_np
...
...
docs/examples/
userguide
/convolve_py.py
→
docs/examples/
memoryviews
/convolve_py.py
View file @
a171e51a
File moved
docs/examples/
userguide
/convolve_typed.pyx
→
docs/examples/
memoryviews
/convolve_typed.pyx
View file @
a171e51a
...
...
@@ -13,27 +13,24 @@ def naive_convolve(f, g):
# can only be used at the top indentation level (there are non-trivial
# problems with allowing them in other places, though we'd love to see
# good and thought out proposals for it).
#
# For the indices, the "int" type is used. This corresponds to a C int,
# other C types (like "unsigned int") could have been used instead.
# Purists could use "Py_ssize_t" which is the proper Python type for
# array indices.
cdef
int
x
,
y
,
s
,
t
,
v
,
w
,
s_from
,
s_to
,
t_from
,
t_to
cdef
int
vmax
=
f
.
shape
[
0
]
cdef
int
wmax
=
f
.
shape
[
1
]
cdef
int
smax
=
g
.
shape
[
0
]
cdef
int
tmax
=
g
.
shape
[
1
]
cdef
int
smid
=
smax
//
2
cdef
int
tmid
=
tmax
//
2
cdef
int
xmax
=
vmax
+
2
*
smid
cdef
int
ymax
=
wmax
+
2
*
tmid
# Py_ssize_t is the proper C type for Python array indices.
cdef
Py_ssize_t
x
,
y
,
s
,
t
,
v
,
w
,
s_from
,
s_to
,
t_from
,
t_to
cdef
Py_ssize_t
vmax
=
f
.
shape
[
0
]
cdef
Py_ssize_t
wmax
=
f
.
shape
[
1
]
cdef
Py_ssize_t
smax
=
g
.
shape
[
0
]
cdef
Py_ssize_t
tmax
=
g
.
shape
[
1
]
cdef
Py_ssize_t
smid
=
smax
//
2
cdef
Py_ssize_t
tmid
=
tmax
//
2
cdef
Py_ssize_t
xmax
=
vmax
+
2
*
smid
cdef
Py_ssize_t
ymax
=
wmax
+
2
*
tmid
h
=
np
.
zeros
([
xmax
,
ymax
],
dtype
=
DTYPE
)
# It is very important to type ALL your variables. You do not get any
# warnings if not, only much slower code (they are implicitly typed as
# Python objects).
# For the value variable, we want to use the same data type as is
# stored in the array, so we use
"DTYPE_t" as defined above
.
# stored in the array, so we use
int because it correspond to np.intc
.
# NB! An important side-effect of this is that if "value" overflows its
# datatype size, it will simply wrap around like in C, rather than raise
# an error like in Python.
...
...
docs/src/tutorial/numpy.rst
View file @
a171e51a
.. _working-numpy:
=======================
Working with NumPy
=======================
...
...
docs/src/userguide/numpy_tutorial.rst
View file @
a171e51a
This diff is collapsed.
Click to expand it.
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