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
c7d6af72
Commit
c7d6af72
authored
Aug 16, 2008
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Buffers: ndim option must now be given as keyword argument
parent
f7ca8b0d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
18 deletions
+19
-18
Cython/Compiler/Buffer.py
Cython/Compiler/Buffer.py
+2
-1
tests/compile/c_directives.pyx
tests/compile/c_directives.pyx
+4
-4
tests/run/bufaccess.pyx
tests/run/bufaccess.pyx
+13
-13
No files found.
Cython/Compiler/Buffer.py
View file @
c7d6af72
...
...
@@ -115,6 +115,7 @@ class IntroduceBufferAuxiliaryVars(CythonTransform):
#
buffer_options
=
(
"dtype"
,
"ndim"
,
"mode"
)
# ordered!
buffer_defaults
=
{
"ndim"
:
1
,
"mode"
:
"full"
}
buffer_positional_options_count
=
1
# anything beyond this needs keyword argument
ERR_BUF_OPTION_UNKNOWN
=
'"%s" is not a buffer option'
ERR_BUF_TOO_MANY
=
'Too many buffer options'
...
...
@@ -140,7 +141,7 @@ def analyse_buffer_options(globalpos, env, posargs, dictargs, defaults=None, nee
posargs
,
dictargs
=
Interpreter
.
interpret_compiletime_options
(
posargs
,
dictargs
,
type_env
=
env
)
if
len
(
posargs
)
>
len
(
buffer_options
)
:
if
len
(
posargs
)
>
buffer_positional_options_count
:
raise
CompileError
(
posargs
[
-
1
][
1
],
ERR_BUF_TOO_MANY
)
options
=
{}
...
...
tests/compile/c_directives.pyx
View file @
c7d6af72
...
...
@@ -7,21 +7,21 @@ print 3
cimport
python_dict
as
asadf
,
python_exc
,
cython
as
cy
def
e
(
object
[
int
,
2
]
buf
):
def
e
(
object
[
int
,
ndim
=
2
]
buf
):
print
buf
[
3
,
2
]
# no bc
@
cy
.
boundscheck
(
False
)
def
f
(
object
[
int
,
2
]
buf
):
def
f
(
object
[
int
,
ndim
=
2
]
buf
):
print
buf
[
3
,
2
]
# no bc
@
cy
.
boundscheck
(
True
)
def
g
(
object
[
int
,
2
]
buf
):
def
g
(
object
[
int
,
ndim
=
2
]
buf
):
# The below line should have no meaning
# boundscheck = False
# even if the above line doesn't follow indentation.
print
buf
[
3
,
2
]
# bc
def
h
(
object
[
int
,
2
]
buf
):
def
h
(
object
[
int
,
ndim
=
2
]
buf
):
print
buf
[
3
,
2
]
# no bc
with
cy
.
boundscheck
(
True
):
print
buf
[
3
,
2
]
# bc
...
...
tests/run/bufaccess.pyx
View file @
c7d6af72
...
...
@@ -41,13 +41,13 @@ def nousage():
"""
The challenge here is just compilation.
"""
cdef
object
[
int
,
2
]
buf
cdef
object
[
int
,
ndim
=
2
]
buf
def
printbuf
():
"""
Just compilation.
"""
cdef
object
[
int
,
2
]
buf
cdef
object
[
int
,
ndim
=
2
]
buf
print
buf
@
testcase
...
...
@@ -334,7 +334,7 @@ def explicitly_release_buffer():
# Getting items and index bounds checking
#
@
testcase
def
get_int_2d
(
object
[
int
,
2
]
buf
,
int
i
,
int
j
):
def
get_int_2d
(
object
[
int
,
ndim
=
2
]
buf
,
int
i
,
int
j
):
"""
>>> get_int_2d(C, 1, 1)
acquired C
...
...
@@ -368,7 +368,7 @@ def get_int_2d(object[int, 2] buf, int i, int j):
return
buf
[
i
,
j
]
@
testcase
def
get_int_2d_uintindex
(
object
[
int
,
2
]
buf
,
unsigned
int
i
,
unsigned
int
j
):
def
get_int_2d_uintindex
(
object
[
int
,
ndim
=
2
]
buf
,
unsigned
int
i
,
unsigned
int
j
):
"""
Unsigned indexing:
>>> get_int_2d_uintindex(C, 0, 0)
...
...
@@ -385,7 +385,7 @@ def get_int_2d_uintindex(object[int, 2] buf, unsigned int i, unsigned int j):
return
buf
[
i
,
j
]
@
testcase
def
set_int_2d
(
object
[
int
,
2
]
buf
,
int
i
,
int
j
,
int
value
):
def
set_int_2d
(
object
[
int
,
ndim
=
2
]
buf
,
int
i
,
int
j
,
int
value
):
"""
Uses get_int_2d to read back the value afterwards. For pure
unit test, one should support reading in MockBuffer instead.
...
...
@@ -470,7 +470,7 @@ def fmtst2(object[int] buf):
"""
@
testcase
def
ndim1
(
object
[
int
,
2
]
buf
):
def
ndim1
(
object
[
int
,
ndim
=
2
]
buf
):
"""
>>> ndim1(IntMockBuffer("A", range(3)))
Traceback (most recent call last):
...
...
@@ -492,7 +492,7 @@ def readonly(obj):
>>> [str(x) for x in R.recieved_flags] # Works in both py2 and py3
['FORMAT', 'INDIRECT', 'ND', 'STRIDES']
"""
cdef
object
[
unsigned
short
int
,
3
]
buf
=
obj
cdef
object
[
unsigned
short
int
,
ndim
=
3
]
buf
=
obj
print
buf
[
2
,
2
,
1
]
@
testcase
...
...
@@ -505,11 +505,11 @@ def writable(obj):
>>> [str(x) for x in R.recieved_flags] # Py2/3
['FORMAT', 'INDIRECT', 'ND', 'STRIDES', 'WRITABLE']
"""
cdef
object
[
unsigned
short
int
,
3
]
buf
=
obj
cdef
object
[
unsigned
short
int
,
ndim
=
3
]
buf
=
obj
buf
[
2
,
2
,
1
]
=
23
@
testcase
def
strided
(
object
[
int
,
1
,
'strided'
]
buf
):
def
strided
(
object
[
int
,
ndim
=
1
,
mode
=
'strided'
]
buf
):
"""
>>> A = IntMockBuffer("A", range(4))
>>> strided(A)
...
...
@@ -648,7 +648,7 @@ def printbuf_int_2d(o, shape):
released A
"""
# should make shape builtin
cdef
object
[
int
,
2
]
buf
cdef
object
[
int
,
ndim
=
2
]
buf
buf
=
o
cdef
int
i
,
j
for
i
in
range
(
shape
[
0
]):
...
...
@@ -1076,10 +1076,10 @@ def typedbuffer1(obj):
...
TypeError: Cannot convert int to bufaccess.IntMockBuffer
"""
cdef
IntMockBuffer
[
int
,
1
]
buf
=
obj
cdef
IntMockBuffer
[
int
,
ndim
=
1
]
buf
=
obj
@
testcase
def
typedbuffer2
(
IntMockBuffer
[
int
,
1
]
obj
):
def
typedbuffer2
(
IntMockBuffer
[
int
,
ndim
=
1
]
obj
):
"""
>>> typedbuffer2(IntMockBuffer("A", range(10)))
acquired A
...
...
@@ -1096,7 +1096,7 @@ def typedbuffer2(IntMockBuffer[int, 1] obj):
# Test __cythonbufferdefaults__
#
@
testcase
def
bufdefaults1
(
IntStridedMockBuffer
[
int
,
1
]
buf
):
def
bufdefaults1
(
IntStridedMockBuffer
[
int
,
ndim
=
1
]
buf
):
"""
For IntStridedMockBuffer, mode should be
"strided" by defaults which should show
...
...
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