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
fd7e2651
Commit
fd7e2651
authored
Nov 10, 2008
by
David Cournapeau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
numpy.pxd support also when Py_ssize_t and npy_intp do not have the same size.
parent
e527ed66
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
6 deletions
+23
-6
Cython/Includes/numpy.pxd
Cython/Includes/numpy.pxd
+23
-6
No files found.
Cython/Includes/numpy.pxd
View file @
fd7e2651
...
...
@@ -52,8 +52,11 @@ cdef extern from "numpy/arrayobject.h":
# requirements, and does not yet fullfill the PEP.
# In particular strided access is always provided regardless
# of flags
cdef
int
copy_shape
if
sizeof
(
npy_intp
)
!=
sizeof
(
Py_ssize_t
):
raise
RuntimeError
(
"Py_intptr_t and Py_ssize_t differs in size, numpy.pxd does not support this"
)
copy_shape
=
1
else
:
copy_shape
=
0
if
((
flags
&
pybuf
.
PyBUF_C_CONTIGUOUS
==
pybuf
.
PyBUF_C_CONTIGUOUS
)
and
not
PyArray_CHKFLAGS
(
self
,
NPY_C_CONTIGUOUS
)):
...
...
@@ -65,8 +68,15 @@ cdef extern from "numpy/arrayobject.h":
info
.
buf
=
PyArray_DATA
(
self
)
info
.
ndim
=
PyArray_NDIM
(
self
)
info
.
strides
=
<
Py_ssize_t
*>
PyArray_STRIDES
(
self
)
info
.
shape
=
<
Py_ssize_t
*>
PyArray_DIMS
(
self
)
if
copy_shape
:
info
.
strides
=
<
Py_ssize_t
*>
stdlib
.
malloc
(
sizeof
(
Py_ssize_t
)
*
info
.
ndim
)
info
.
shape
=
<
Py_ssize_t
*>
stdlib
.
malloc
(
sizeof
(
Py_ssize_t
)
*
info
.
ndim
)
for
i
in
range
(
info
.
ndim
):
info
.
strides
[
i
]
=
PyArray_STRIDES
(
self
)[
i
]
info
.
shape
[
i
]
=
PyArray_DIMS
(
self
)[
i
]
else
:
info
.
strides
=
<
Py_ssize_t
*>
PyArray_STRIDES
(
self
)
info
.
shape
=
<
Py_ssize_t
*>
PyArray_DIMS
(
self
)
info
.
suboffsets
=
NULL
info
.
itemsize
=
PyArray_ITEMSIZE
(
self
)
info
.
readonly
=
not
PyArray_ISWRITEABLE
(
self
)
...
...
@@ -86,9 +96,14 @@ cdef extern from "numpy/arrayobject.h":
# (this would look much prettier if we could use utility
# functions).
if
not
hasfields
and
not
copy_shape
:
# do not call releasebuffer
info
.
obj
=
None
else
:
# need to call releasebuffer
info
.
obj
=
self
if
not
hasfields
:
info
.
obj
=
None
# do not call releasebuffer
t
=
descr
.
type_num
if
t
==
NPY_BYTE
:
f
=
"b"
elif
t
==
NPY_UBYTE
:
f
=
"B"
...
...
@@ -112,7 +127,6 @@ cdef extern from "numpy/arrayobject.h":
info
.
format
=
f
return
else
:
info
.
obj
=
self
# need to call releasebuffer
info
.
format
=
<
char
*>
stdlib
.
malloc
(
255
)
# static size
f
=
info
.
format
stack
=
[
iter
(
descr
.
fields
.
iteritems
())]
...
...
@@ -170,6 +184,9 @@ cdef extern from "numpy/arrayobject.h":
# This can not be called unless format needs to be freed (as
# obj is set to NULL in those case)
stdlib
.
free
(
info
.
format
)
if
sizeof
(
npy_intp
)
!=
sizeof
(
Py_ssize_t
):
stdlib
.
free
(
info
.
shape
)
stdlib
.
free
(
info
.
strides
)
cdef
void
*
PyArray_DATA
(
ndarray
arr
)
...
...
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