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
8a6c4d3d
Commit
8a6c4d3d
authored
Aug 14, 2009
by
Kurt Smith
Committed by
Mark Florisson
Sep 30, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added .shape .strides and .suboffsets fields to MemoryViewSliceType scope
parent
f6273d89
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
141 additions
and
57 deletions
+141
-57
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+22
-1
tests/run/memoryviewattrs.pyx
tests/run/memoryviewattrs.pyx
+119
-56
No files found.
Cython/Compiler/PyrexTypes.py
View file @
8a6c4d3d
...
...
@@ -385,7 +385,7 @@ class MemoryViewSliceType(PyrexType):
def
attributes_known
(
self
):
if
self
.
scope
is
None
:
import
Symtab
,
MemoryView
import
Symtab
,
MemoryView
,
Options
from
MemoryView
import
axes_to_str
self
.
scope
=
scope
=
Symtab
.
CClassScope
(
...
...
@@ -397,6 +397,27 @@ class MemoryViewSliceType(PyrexType):
scope
.
declare_var
(
'_data'
,
c_char_ptr_type
,
None
,
cname
=
'data'
,
is_cdef
=
1
)
scope
.
declare_var
(
'shape'
,
c_array_type
(
c_py_ssize_t_type
,
Options
.
buffer_max_dims
),
None
,
cname
=
'shape'
,
is_cdef
=
1
)
scope
.
declare_var
(
'strides'
,
c_array_type
(
c_py_ssize_t_type
,
Options
.
buffer_max_dims
),
None
,
cname
=
'strides'
,
is_cdef
=
1
)
scope
.
declare_var
(
'suboffsets'
,
c_array_type
(
c_py_ssize_t_type
,
Options
.
buffer_max_dims
),
None
,
cname
=
'suboffsets'
,
is_cdef
=
1
)
mangle_dtype
=
MemoryView
.
mangle_dtype_name
(
self
.
dtype
)
ndim
=
len
(
self
.
axes
)
...
...
tests/run/memoryviewattrs.pyx
View file @
8a6c4d3d
u'''
>>> test_copy_mismatch()
Traceback (most recent call last):
...
ValueError: memoryview shapes not the same in dimension 0
>>> test_copy_to()
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
>>> test_is_contiguous()
1 1
0 1
1 0
1 0
<BLANKLINE>
0 1
1 0
>>> call()
1000 2000 3000
1000
2000 3000
3000
1 1 1000
>>> two_dee()
1 2 3 4
-4 -4
1 2 3 -4
1 2 3 -4
>>> fort_two_dee()
1 2 3 4
-4 -4
1 2 3 -4
1 3 2 -4
1 2 3 -4
>>> test_nonecheck1()
Traceback (most recent call last):
...
AttributeError: 'NoneType' object has no attribute 'is_c_contig'
>>> test_nonecheck2()
Traceback (most recent call last):
...
AttributeError: 'NoneType' object has no attribute 'is_f_contig'
>>> test_nonecheck3()
Traceback (most recent call last):
...
AttributeError: 'NoneType' object has no attribute 'copy'
>>> test_nonecheck4()
Traceback (most recent call last):
...
AttributeError: 'NoneType' object has no attribute 'copy_fortran'
>>> test_nonecheck5()
Traceback (most recent call last):
...
AttributeError: 'NoneType' object has no attribute '_data'
'''
__test__
=
{}
def
testcase
(
func
):
__test__
[
func
.
__name__
]
=
func
.
__doc__
return
func
# from cython.view cimport memoryview
cimport
cython
from
cython
cimport
array
import
numpy
as
np
cimport
numpy
as
np
@
testcase
def
test_shape_stride_suboffset
():
u'''
>>> test_shape_stride_suboffset()
5 7 11
616 88 8
-1 -1 -1
5 7 11
8 40 280
-1 -1 -1
5 7 11
616 88 8
-1 -1 -1
'''
cdef
unsigned
long
[:,:,:]
larr
=
array
((
5
,
7
,
11
),
sizeof
(
unsigned
long
),
'L'
)
print
larr
.
shape
[
0
],
larr
.
shape
[
1
],
larr
.
shape
[
2
]
print
larr
.
strides
[
0
],
larr
.
strides
[
1
],
larr
.
strides
[
2
]
print
larr
.
suboffsets
[
0
],
larr
.
suboffsets
[
1
],
larr
.
suboffsets
[
2
]
larr
=
array
((
5
,
7
,
11
),
sizeof
(
unsigned
long
),
'L'
,
mode
=
'fortran'
)
print
larr
.
shape
[
0
],
larr
.
shape
[
1
],
larr
.
shape
[
2
]
print
larr
.
strides
[
0
],
larr
.
strides
[
1
],
larr
.
strides
[
2
]
print
larr
.
suboffsets
[
0
],
larr
.
suboffsets
[
1
],
larr
.
suboffsets
[
2
]
cdef
unsigned
long
[:,:,:]
c_contig
=
larr
.
copy
()
print
c_contig
.
shape
[
0
],
c_contig
.
shape
[
1
],
c_contig
.
shape
[
2
]
print
c_contig
.
strides
[
0
],
c_contig
.
strides
[
1
],
c_contig
.
strides
[
2
]
print
c_contig
.
suboffsets
[
0
],
c_contig
.
suboffsets
[
1
],
c_contig
.
suboffsets
[
2
]
@
testcase
def
test_copy_to
():
u'''
>>> test_copy_to()
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
'''
cdef
int
[:,:,:]
from_mvs
,
to_mvs
from_mvs
=
np
.
arange
(
8
,
dtype
=
np
.
int32
).
reshape
(
2
,
2
,
2
)
cdef
int
*
from_dta
=
<
int
*>
from_mvs
.
_data
...
...
@@ -81,38 +65,91 @@ def test_copy_to():
print
to_data
[
i
],
print
@
testcase
@
cython
.
nonecheck
(
True
)
def
test_nonecheck1
():
u'''
>>> test_nonecheck1()
Traceback (most recent call last):
...
AttributeError: 'NoneType' object has no attribute 'is_c_contig'
'''
cdef
int
[:,:,:]
uninitialized
print
uninitialized
.
is_c_contig
()
@
testcase
@
cython
.
nonecheck
(
True
)
def
test_nonecheck2
():
u'''
>>> test_nonecheck2()
Traceback (most recent call last):
...
AttributeError: 'NoneType' object has no attribute 'is_f_contig'
'''
cdef
int
[:,:,:]
uninitialized
print
uninitialized
.
is_f_contig
()
@
testcase
@
cython
.
nonecheck
(
True
)
def
test_nonecheck3
():
u'''
>>> test_nonecheck3()
Traceback (most recent call last):
...
AttributeError: 'NoneType' object has no attribute 'copy'
'''
cdef
int
[:,:,:]
uninitialized
uninitialized
.
copy
()
@
testcase
@
cython
.
nonecheck
(
True
)
def
test_nonecheck4
():
u'''
>>> test_nonecheck4()
Traceback (most recent call last):
...
AttributeError: 'NoneType' object has no attribute 'copy_fortran'
'''
cdef
int
[:,:,:]
uninitialized
uninitialized
.
copy_fortran
()
@
testcase
@
cython
.
nonecheck
(
True
)
def
test_nonecheck5
():
u'''
>>> test_nonecheck5()
Traceback (most recent call last):
...
AttributeError: 'NoneType' object has no attribute '_data'
'''
cdef
int
[:,:,:]
uninitialized
uninitialized
.
_data
@
testcase
def
test_copy_mismatch
():
u'''
>>> test_copy_mismatch()
Traceback (most recent call last):
...
ValueError: memoryview shapes not the same in dimension 0
'''
cdef
int
[:,:,::
1
]
mv1
=
array
((
2
,
2
,
3
),
sizeof
(
int
),
'i'
)
cdef
int
[:,:,::
1
]
mv2
=
array
((
1
,
2
,
3
),
sizeof
(
int
),
'i'
)
mv1
[...]
=
mv2
@
testcase
def
test_is_contiguous
():
u'''
>>> test_is_contiguous()
1 1
0 1
1 0
1 0
<BLANKLINE>
0 1
1 0
'''
cdef
int
[::
1
,
:,
:]
fort_contig
=
array
((
1
,
1
,
1
),
sizeof
(
int
),
'i'
,
mode
=
'fortran'
)
print
fort_contig
.
is_c_contig
()
,
fort_contig
.
is_f_contig
()
fort_contig
=
array
((
200
,
100
,
100
),
sizeof
(
int
),
'i'
,
mode
=
'fortran'
)
...
...
@@ -127,7 +164,16 @@ def test_is_contiguous():
print
strided
.
is_c_contig
(),
strided
.
is_f_contig
()
@
testcase
def
call
():
u'''
>>> call()
1000 2000 3000
1000
2000 3000
3000
1 1 1000
'''
cdef
int
[::
1
]
mv1
,
mv2
,
mv3
cdef
array
arr
=
array
((
3
,),
sizeof
(
int
),
'i'
)
mv1
=
arr
...
...
@@ -156,7 +202,15 @@ def call():
print
(
<
int
*>
mv3
.
_data
)[
0
]
,
(
<
int
*>
mv2
.
_data
)[
0
]
,
(
<
int
*>
mv1
.
_data
)[
0
]
@
testcase
def
two_dee
():
u'''
>>> two_dee()
1 2 3 4
-4 -4
1 2 3 -4
1 2 3 -4
'''
cdef
long
[:,::
1
]
mv1
,
mv2
,
mv3
cdef
array
arr
=
array
((
2
,
2
),
sizeof
(
long
),
'l'
)
...
...
@@ -186,7 +240,16 @@ def two_dee():
print
(
<
long
*>
mv3
.
_data
)[
0
]
,
(
<
long
*>
mv3
.
_data
)[
1
]
,
(
<
long
*>
mv3
.
_data
)[
2
]
,
(
<
long
*>
mv3
.
_data
)[
3
]
@
testcase
def
fort_two_dee
():
u'''
>>> fort_two_dee()
1 2 3 4
-4 -4
1 2 3 -4
1 3 2 -4
1 2 3 -4
'''
cdef
array
arr
=
array
((
2
,
2
),
sizeof
(
long
),
'l'
,
mode
=
'fortran'
)
cdef
long
[::
1
,:]
mv1
,
mv2
,
mv3
...
...
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