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
1d86d5fe
Commit
1d86d5fe
authored
Mar 18, 2018
by
gabrieldemarmiesse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Quite some progress with this tutorial. Only two parts missing.
parent
c00d9ed6
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
145 additions
and
112 deletions
+145
-112
docs/examples/userguide/convolve_fused_types.pyx
docs/examples/userguide/convolve_fused_types.pyx
+1
-1
docs/examples/userguide/convolve_infer_types.pyx
docs/examples/userguide/convolve_infer_types.pyx
+2
-1
docs/examples/userguide/convolve_memview.pyx
docs/examples/userguide/convolve_memview.pyx
+1
-1
docs/examples/userguide/convolve_py.py
docs/examples/userguide/convolve_py.py
+1
-1
docs/examples/userguide/convolve_typed.pyx
docs/examples/userguide/convolve_typed.pyx
+4
-8
docs/src/userguide/convolve_types_html.png
docs/src/userguide/convolve_types_html.png
+0
-0
docs/src/userguide/numpy_tutorial.rst
docs/src/userguide/numpy_tutorial.rst
+136
-100
No files found.
docs/examples/userguide/convolve_fused_types.pyx
View file @
1d86d5fe
...
...
@@ -8,7 +8,7 @@ ctypedef fused my_type:
@
cython
.
boundscheck
(
False
)
@
cython
.
wraparound
(
False
)
cpdef
naive_convolve
_fused_types
(
my_type
[:,:]
f
,
my_type
[:,:]
g
):
cpdef
naive_convolve
(
my_type
[:,:]
f
,
my_type
[:,:]
g
):
if
g
.
shape
[
0
]
%
2
!=
1
or
g
.
shape
[
1
]
%
2
!=
1
:
raise
ValueError
(
"Only odd dimensions on filter supported"
)
...
...
docs/examples/userguide/convolve_infer_types.pyx
View file @
1d86d5fe
# cython: infer_types=True
import
numpy
as
np
cimport
cython
DTYPE
=
np
.
intc
@
cython
.
boundscheck
(
False
)
@
cython
.
wraparound
(
False
)
def
naive_convolve
_infer_types
(
int
[:,::
1
]
f
,
int
[:,::
1
]
g
):
def
naive_convolve
(
int
[:,::
1
]
f
,
int
[:,::
1
]
g
):
if
g
.
shape
[
0
]
%
2
!=
1
or
g
.
shape
[
1
]
%
2
!=
1
:
raise
ValueError
(
"Only odd dimensions on filter supported"
)
...
...
docs/examples/userguide/convolve_memview.pyx
View file @
1d86d5fe
...
...
@@ -2,7 +2,7 @@ import numpy as np
DTYPE
=
np
.
intc
def
naive_convolve
_memview
(
int
[:,:]
f
,
int
[:,:]
g
):
def
naive_convolve
(
int
[:,:]
f
,
int
[:,:]
g
):
if
g
.
shape
[
0
]
%
2
!=
1
or
g
.
shape
[
1
]
%
2
!=
1
:
raise
ValueError
(
"Only odd dimensions on filter supported"
)
...
...
docs/examples/userguide/convolve_py.py
View file @
1d86d5fe
from
__future__
import
division
import
numpy
as
np
def
naive_convolve
_py
(
f
,
g
):
def
naive_convolve
(
f
,
g
):
# f is an image and is indexed by (v, w)
# g is a filter kernel and is indexed by (s, t),
# it needs odd dimensions
...
...
docs/examples/userguide/convolve_typed.pyx
View file @
1d86d5fe
import
numpy
as
np
# "def" can type its arguments but not have a return type. The type of the
# arguments for a "def" function is checked at run-time when entering the
# function.
# We now need to fix a datatype for our arrays. I've used the variable
# DTYPE for this, which is assigned to the usual NumPy runtime
# type info object.
DTYPE
=
np
.
intc
# The arrays f, g and h is typed as "np.ndarray" instances. The only effect
# this has is to a) insert checks that the function arguments really are
# NumPy arrays, and b) make some attribute access like f.shape[0] much
# more efficient. (In this example this doesn't matter though.)
def
naive_convolve_types
(
f
,
g
):
def
naive_convolve
(
f
,
g
):
if
g
.
shape
[
0
]
%
2
!=
1
or
g
.
shape
[
1
]
%
2
!=
1
:
raise
ValueError
(
"Only odd dimensions on filter supported"
)
assert
f
.
dtype
==
DTYPE
and
g
.
dtype
==
DTYPE
...
...
@@ -46,6 +40,8 @@ def naive_convolve_types(f, g):
cdef
int
value
for
x
in
range
(
xmax
):
for
y
in
range
(
ymax
):
# Cython has built-in C functions for min and max
# This makes the following lines very fast.
s_from
=
max
(
smid
-
x
,
-
smid
)
s_to
=
min
((
xmax
-
x
)
-
smid
,
smid
+
1
)
t_from
=
max
(
tmid
-
y
,
-
tmid
)
...
...
docs/src/userguide/convolve_types_html.png
0 → 100644
View file @
1d86d5fe
37.1 KB
docs/src/userguide/numpy_tutorial.rst
View file @
1d86d5fe
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