Commit e1eb0a1c authored by Stefan Behnel's avatar Stefan Behnel

Tighten "numpy_attributes" test to assert that it's actually using a property...

Tighten "numpy_attributes" test to assert that it's actually using a property call and not an attribute access.
Also add a test for the newly added "ndarray.data" property.
parent 9ac5d811
# mode: run
# tag: numpy
cimport cython
import numpy as np
cimport numpy as cnp
cnp.import_array()
@cython.test_assert_path_exists(
"//ReturnStatNode",
"//ReturnStatNode//IndexNode",
"//ReturnStatNode//IndexNode//SimpleCallNode",
)
@cython.test_fail_if_path_exists(
"//ReturnStatNode//AttributeNode",
)
def access_shape():
"""
>>> access_shape()
10
"""
cdef cnp.ndarray[double, ndim=2, mode='c'] array_in = \
1e10 * np.ones((10, 10))
1e10 * np.ones((10, 10))
return array_in.shape[0]
@cython.test_assert_path_exists(
"//ReturnStatNode",
"//ReturnStatNode//SimpleCallNode",
)
@cython.test_fail_if_path_exists(
"//ReturnStatNode//AttributeNode",
)
def access_size():
"""
>>> access_size()
100
"""
cdef cnp.ndarray[double, ndim=2, mode='c'] array_in = \
1e10 * np.ones((10, 10))
1e10 * np.ones((10, 10))
return array_in.size
@cython.test_assert_path_exists(
"//ReturnStatNode",
"//ReturnStatNode//IndexNode",
"//ReturnStatNode//IndexNode//SimpleCallNode",
)
@cython.test_fail_if_path_exists(
"//ReturnStatNode//AttributeNode",
)
def access_strides():
"""
>>> access_strides()
(80, 8)
"""
cdef cnp.ndarray[double, ndim=2, mode='c'] array_in = \
1e10 * np.ones((10, 10), dtype=np.float64)
1e10 * np.ones((10, 10), dtype=np.float64)
return (array_in.strides[0], array_in.strides[1])
@cython.test_assert_path_exists(
"//ReturnStatNode",
"//ReturnStatNode//PrimaryCmpNode",
"//ReturnStatNode//PrimaryCmpNode//SimpleCallNode",
)
@cython.test_fail_if_path_exists(
"//ReturnStatNode//AttributeNode",
)
def access_data():
"""
>>> access_data()
True
"""
cdef cnp.ndarray[double, ndim=2, mode='c'] array_in = \
1e10 * np.ones((10, 10), dtype=np.float64)
return array_in.data is not NULL
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment