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
f7ca8b0d
Commit
f7ca8b0d
authored
Aug 16, 2008
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
numpy.pxd: Added type_t typedefs corresponding to predefined dtypes
parent
ed4b0e7b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
20 deletions
+78
-20
Cython/Compiler/Buffer.py
Cython/Compiler/Buffer.py
+2
-1
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+1
-0
Cython/Includes/numpy.pxd
Cython/Includes/numpy.pxd
+52
-18
tests/run/tnumpy.pyx
tests/run/tnumpy.pyx
+23
-1
No files found.
Cython/Compiler/Buffer.py
View file @
f7ca8b0d
...
@@ -478,7 +478,8 @@ def get_ts_check_item(dtype, writer):
...
@@ -478,7 +478,8 @@ def get_ts_check_item(dtype, writer):
elif
dtype
.
is_float
:
elif
dtype
.
is_float
:
types
=
[(
'f'
,
'float'
),
(
'd'
,
'double'
),
(
'g'
,
'long double'
)]
types
=
[(
'f'
,
'float'
),
(
'd'
,
'double'
),
(
'g'
,
'long double'
)]
else
:
else
:
assert
False
assert
dtype
.
is_error
return
name
if
dtype
.
signed
==
0
:
if
dtype
.
signed
==
0
:
code
+=
""
.
join
([
"
\
n
case '%s': ok = (sizeof(%s) == sizeof(%s) && (%s)-1 > 0); break;"
%
code
+=
""
.
join
([
"
\
n
case '%s': ok = (sizeof(%s) == sizeof(%s) && (%s)-1 > 0); break;"
%
(
char
.
upper
(),
ctype
,
against
,
ctype
)
for
char
,
against
in
types
])
(
char
.
upper
(),
ctype
,
against
,
ctype
)
for
char
,
against
in
types
])
...
...
Cython/Compiler/Nodes.py
View file @
f7ca8b0d
...
@@ -601,6 +601,7 @@ class CBufferAccessTypeNode(CBaseTypeNode):
...
@@ -601,6 +601,7 @@ class CBufferAccessTypeNode(CBaseTypeNode):
def
analyse
(
self
,
env
):
def
analyse
(
self
,
env
):
base_type
=
self
.
base_type_node
.
analyse
(
env
)
base_type
=
self
.
base_type_node
.
analyse
(
env
)
if
base_type
.
is_error
:
return
base_type
import
Buffer
import
Buffer
options
=
Buffer
.
analyse_buffer_options
(
options
=
Buffer
.
analyse_buffer_options
(
...
...
Cython/Includes/numpy.pxd
View file @
f7ca8b0d
...
@@ -82,6 +82,22 @@ cdef extern from "numpy/arrayobject.h":
...
@@ -82,6 +82,22 @@ cdef extern from "numpy/arrayobject.h":
cdef
npy_intp
PyArray_DIMS
(
ndarray
arr
)
cdef
npy_intp
PyArray_DIMS
(
ndarray
arr
)
cdef
Py_ssize_t
PyArray_ITEMSIZE
(
ndarray
arr
)
cdef
Py_ssize_t
PyArray_ITEMSIZE
(
ndarray
arr
)
ctypedef
signed
int
npy_byte
ctypedef
signed
int
npy_short
ctypedef
signed
int
npy_int
ctypedef
signed
int
npy_long
ctypedef
signed
int
npy_longlong
ctypedef
unsigned
int
npy_ubyte
ctypedef
unsigned
int
npy_ushort
ctypedef
unsigned
int
npy_uint
ctypedef
unsigned
int
npy_ulong
ctypedef
unsigned
int
npy_ulonglong
ctypedef
float
npy_float
ctypedef
float
npy_double
ctypedef
float
npy_longdouble
ctypedef
signed
int
npy_int8
ctypedef
signed
int
npy_int8
ctypedef
signed
int
npy_int16
ctypedef
signed
int
npy_int16
ctypedef
signed
int
npy_int32
ctypedef
signed
int
npy_int32
...
@@ -102,22 +118,40 @@ cdef extern from "numpy/arrayobject.h":
...
@@ -102,22 +118,40 @@ cdef extern from "numpy/arrayobject.h":
ctypedef
float
npy_float96
ctypedef
float
npy_float96
ctypedef
float
npy_float128
ctypedef
float
npy_float128
# Typedefs that matches the runtime dtype objects in
# the numpy module.
# The ones that are commented out needs an IFDEF function
# in Cython to enable them only on the right systems.
ctypedef
npy_int8
int8_t
ctypedef
npy_int16
int16_t
ctypedef
npy_int32
int32_t
ctypedef
npy_int64
int64_t
#ctypedef npy_int96 int96_t
#ctypedef npy_int128 int128_t
ctypedef
npy_uint8
uint8_t
ctypedef
npy_uint16
uint16_t
ctypedef
npy_uint32
uint32_t
ctypedef
npy_uint64
uint64_t
#ctypedef npy_uint96 uint96_t
#ctypedef npy_uint128 uint128_t
ctypedef
npy_float32
float32_t
ctypedef
npy_float64
float64_t
#ctypedef npy_float80 float80_t
#ctypedef npy_float128 float128_t
# The int types are mapped a bit surprising --
# numpy.int corresponds to 'l' and numpy.long to 'q'
ctypedef
npy_long
int_t
ctypedef
npy_longlong
long_t
ctypedef
npy_ulong
uint_t
ctypedef
npy_ulonglong
ulong_t
ctypedef
npy_double
float_t
ctypedef
npy_double
double_t
ctypedef
npy_longdouble
longdouble_t
ctypedef
npy_int8
int8_t
ctypedef
npy_int16
int16_t
ctypedef
npy_int32
int32_t
ctypedef
npy_int64
int64_t
ctypedef
npy_int96
int96_t
ctypedef
npy_int128
int128_t
ctypedef
npy_uint8
uint8_t
ctypedef
npy_uint16
uint16_t
ctypedef
npy_uint32
uint32_t
ctypedef
npy_uint64
uint64_t
ctypedef
npy_uint96
uint96_t
ctypedef
npy_uint128
uint128_t
ctypedef
npy_float32
float32_t
ctypedef
npy_float64
float64_t
ctypedef
npy_float80
float80_t
ctypedef
npy_float128
float128_t
tests/run/tnumpy.pyx
View file @
f7ca8b0d
...
@@ -92,6 +92,15 @@ try:
...
@@ -92,6 +92,15 @@ try:
>>> test_dtype('g', inc1_longdouble)
>>> test_dtype('g', inc1_longdouble)
>>> test_dtype('O', inc1_object)
>>> test_dtype('O', inc1_object)
>>> test_dtype(np.int, inc1_int_t)
>>> test_dtype(np.long, inc1_long_t)
>>> test_dtype(np.float, inc1_float_t)
>>> test_dtype(np.double, inc1_double_t)
>>> test_dtype(np.longdouble, inc1_longdouble_t)
>>> test_dtype(np.int32, inc1_int32_t)
>>> test_dtype(np.float64, inc1_float64_t)
Unsupported types:
Unsupported types:
>>> test_dtype(np.complex, inc1_byte)
>>> test_dtype(np.complex, inc1_byte)
Traceback (most recent call last):
Traceback (most recent call last):
...
@@ -103,7 +112,6 @@ try:
...
@@ -103,7 +112,6 @@ try:
Traceback (most recent call last):
Traceback (most recent call last):
...
...
ValueError: only objects, int and float dtypes supported for ndarray buffer access so far (dtype is 20)
ValueError: only objects, int and float dtypes supported for ndarray buffer access so far (dtype is 20)
"""
"""
except
:
except
:
...
@@ -154,10 +162,24 @@ def inc1_float(np.ndarray[float] arr): arr[1] += 1
...
@@ -154,10 +162,24 @@ def inc1_float(np.ndarray[float] arr): arr[1] += 1
def
inc1_double
(
np
.
ndarray
[
double
]
arr
):
arr
[
1
]
+=
1
def
inc1_double
(
np
.
ndarray
[
double
]
arr
):
arr
[
1
]
+=
1
def
inc1_longdouble
(
np
.
ndarray
[
long
double
]
arr
):
arr
[
1
]
+=
1
def
inc1_longdouble
(
np
.
ndarray
[
long
double
]
arr
):
arr
[
1
]
+=
1
def
inc1_object
(
np
.
ndarray
[
object
]
arr
):
def
inc1_object
(
np
.
ndarray
[
object
]
arr
):
o
=
arr
[
1
]
o
=
arr
[
1
]
o
+=
1
o
+=
1
arr
[
1
]
=
o
# unfortunately, += segfaults for objects
arr
[
1
]
=
o
# unfortunately, += segfaults for objects
def
inc1_int_t
(
np
.
ndarray
[
np
.
int_t
]
arr
):
arr
[
1
]
+=
1
def
inc1_long_t
(
np
.
ndarray
[
np
.
long_t
]
arr
):
arr
[
1
]
+=
1
def
inc1_float_t
(
np
.
ndarray
[
np
.
float_t
]
arr
):
arr
[
1
]
+=
1
def
inc1_double_t
(
np
.
ndarray
[
np
.
double_t
]
arr
):
arr
[
1
]
+=
1
def
inc1_longdouble_t
(
np
.
ndarray
[
np
.
longdouble_t
]
arr
):
arr
[
1
]
+=
1
# The tests below only work on platforms that has the given types
def
inc1_int32_t
(
np
.
ndarray
[
np
.
int32_t
]
arr
):
arr
[
1
]
+=
1
def
inc1_float64_t
(
np
.
ndarray
[
np
.
float64_t
]
arr
):
arr
[
1
]
+=
1
def
test_dtype
(
dtype
,
inc1
):
def
test_dtype
(
dtype
,
inc1
):
a
=
np
.
array
([
0
,
10
],
dtype
=
dtype
)
a
=
np
.
array
([
0
,
10
],
dtype
=
dtype
)
inc1
(
a
)
inc1
(
a
)
...
...
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