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
Boxiang Sun
cython
Commits
c8be949c
Commit
c8be949c
authored
Jul 20, 2011
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix cythonarray test
parent
d58cd33d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
20 deletions
+21
-20
Cython/Compiler/CythonScope.py
Cython/Compiler/CythonScope.py
+12
-17
tests/compile/memview_declaration.pyx
tests/compile/memview_declaration.pyx
+2
-0
tests/run/cythonarray.pyx
tests/run/cythonarray.pyx
+7
-3
No files found.
Cython/Compiler/CythonScope.py
View file @
c8be949c
...
...
@@ -261,44 +261,39 @@ cdef class array:
self.format = format
self.shape = <Py_ssize_t *>malloc(sizeof(Py_ssize_t)*self.ndim)
self.strides = <Py_ssize_t *>malloc(sizeof(Py_ssize_t)*self.ndim)
self.shape = <Py_ssize_t *>
malloc(sizeof(Py_ssize_t)*self.ndim)
self.strides = <Py_ssize_t *>
malloc(sizeof(Py_ssize_t)*self.ndim)
if not self.shape or not self.strides:
raise MemoryError("unable to allocate shape or strides.")
cdef int idx
cdef Py_ssize_t int_
dim, stride
# cdef Py_ssize_t
dim, stride
idx = 0
for dim in shape:
int_dim = <Py_ssize_t>dim
if int_dim <= 0:
if dim <= 0:
raise ValueError("Invalid shape.")
self.shape[idx] = int_dim
self.shape[idx] = dim
idx += 1
assert idx == self.ndim
stride = itemsize
if mode == "fortran":
idx = 0
; stride = itemsize
idx = 0
for dim in shape:
self.strides[idx] = stride
int_dim = <Py_ssize_t>dim
stride = stride * int_dim
stride = stride * dim
idx += 1
assert idx == self.ndim
self.len = stride * self.itemsize
elif mode == "c":
idx = self.ndim-1
; stride = itemsize
idx = self.ndim-1
for dim in shape[::-1]:
self.strides[idx] = stride
int_dim = <Py_ssize_t>dim
stride = stride * int_dim
stride = stride * dim
idx -= 1
assert idx == -1
self.len = stride * self.itemsize
else:
raise ValueError("Invalid mode, expected 'c' or 'fortran', got %s" % mode)
self.len = stride
self.mode = mode
if allocate_buffer:
...
...
tests/compile/memview_declaration.pyx
View file @
c8be949c
# mode: compile
cimport
cython
from
cython.view
cimport
contig
as
foo
,
full
as
bar
#, follow
from
cython
cimport
view
...
...
tests/run/cythonarray.pyx
View file @
c8be949c
...
...
@@ -6,19 +6,23 @@ cimport cython as cy
def
contiguity
():
'''
>>> contiguity()
3 1
12 4
2 3
2
1 2
<BLANKLINE>
4 8
2 3
2
'''
cdef
cy
.
array
cvarray
=
cy
.
array
(
shape
=
(
2
,
3
),
itemsize
=
sizeof
(
int
),
format
=
"i"
,
mode
=
'c'
)
assert
cvarray
.
len
==
2
*
3
*
sizeof
(
int
)
assert
cvarray
.
len
==
2
*
3
*
sizeof
(
int
)
,
(
cvarray
.
len
,
2
*
3
*
sizeof
(
int
))
assert
cvarray
.
itemsize
==
sizeof
(
int
)
print
cvarray
.
strides
[
0
],
cvarray
.
strides
[
1
]
print
cvarray
.
shape
[
0
],
cvarray
.
shape
[
1
]
print
cvarray
.
ndim
print
cdef
cy
.
array
farray
=
cy
.
array
(
shape
=
(
2
,
3
),
itemsize
=
sizeof
(
int
),
format
=
"i"
,
mode
=
'fortran'
)
assert
farray
.
len
==
2
*
3
*
sizeof
(
int
)
assert
farray
.
itemsize
==
sizeof
(
int
)
...
...
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