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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
18ba3a48
Commit
18ba3a48
authored
Aug 02, 2008
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Basic numpy testcase working
parent
b7ffe116
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
7 deletions
+46
-7
Cython/Includes/numpy.pxd
Cython/Includes/numpy.pxd
+24
-7
tests/run/tnumpy.pyx
tests/run/tnumpy.pyx
+22
-0
No files found.
Cython/Includes/numpy.pxd
View file @
18ba3a48
...
...
@@ -2,24 +2,40 @@ cdef extern from "Python.h":
ctypedef
int
Py_intptr_t
cdef
extern
from
"numpy/arrayobject.h"
:
ctypedef
void
PyArrayObject
int
PyArray_TYPE
(
PyObject
*
arr
)
ctypedef
Py_intptr_t
npy_intp
ctypedef
struct
PyArray_Descr
:
int
elsize
ctypedef
class
numpy
.
ndarray
[
object
PyArrayObject
]:
cdef
:
char
*
data
int
nd
Py_intptr_t
*
dimensions
Py_intptr_t
*
strides
npy_intp
*
dimensions
npy_intp
*
strides
object
base
# descr not implemented yet here...
int
flags
int
itemsize
object
weakreflist
PyArray_Descr
*
descr
def
__getbuffer__
(
ndarray
self
,
Py_buffer
*
info
,
int
flags
):
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"
)
def
__getbuffer__
(
self
,
Py_buffer
*
info
,
int
flags
):
cdef
int
typenum
=
PyArray_TYPE
(
self
)
info
.
buf
=
<
void
*>
self
.
data
info
.
ndim
=
2
info
.
strides
=
<
Py_ssize_t
*>
self
.
strides
info
.
shape
=
<
Py_ssize_t
*>
self
.
dimensions
info
.
suboffsets
=
NULL
info
.
format
=
"i"
info
.
itemsize
=
self
.
descr
.
elsize
info
.
readonly
=
not
PyArray_ISWRITEABLE
(
self
)
# PS TODO TODO!: Py_ssize_t vs Py_intptr_t
## PyArrayObject *arr = (PyArrayObject*)obj;
## PyArray_Descr *type = (PyArray_Descr*)arr->descr;
...
...
@@ -58,7 +74,8 @@ cdef extern from "numpy/arrayobject.h":
## print "hello" + str(43) + "asdf" + "three"
## pass
cdef
int
PyArray_TYPE
(
ndarray
arr
)
cdef
int
PyArray_ISWRITEABLE
(
ndarray
arr
)
ctypedef
unsigned
int
npy_uint8
ctypedef
unsigned
int
npy_uint16
...
...
tests/run/tnumpy.pyx
0 → 100644
View file @
18ba3a48
# cannot be named "numpy" in order to no clash with the numpy module!
cimport
numpy
try
:
import
numpy
__doc__
=
"""
>>> basic()
[[0 1 2 3 4]
[5 6 7 8 9]]
2 0 9 5
"""
except
:
__doc__
=
""
def
basic
():
cdef
object
[
int
,
2
]
buf
=
numpy
.
arange
(
10
).
reshape
((
2
,
5
))
print
buf
print
buf
[
0
,
2
],
buf
[
0
,
0
],
buf
[
1
,
4
],
buf
[
1
,
0
]
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