forked from maxjhandsome/jittor
check c stype in core
This commit is contained in:
parent
3f452fe966
commit
2db484a3df
|
@ -113,6 +113,12 @@ class TestArray(unittest.TestCase):
|
|||
""")
|
||||
assert (b.data==[2,8,18]).all()
|
||||
|
||||
def test_not_c_style(self):
|
||||
a = np.array([1,2,3])
|
||||
b = a[::-1]
|
||||
x = jt.array(b)
|
||||
x = x + b
|
||||
assert (x.data == [6,4,2]).all()
|
||||
|
||||
|
||||
|
||||
|
|
2
setup.py
2
setup.py
|
@ -21,7 +21,7 @@ with open(os.path.join(path, "README.md"), "r", encoding='utf8') as fh:
|
|||
|
||||
setuptools.setup(
|
||||
name='jittor',
|
||||
version='1.1.5.0',
|
||||
version='1.1.5.1',
|
||||
# scripts=[],
|
||||
author="Jittor Group",
|
||||
author_email="ran.donglang@gmail.com",
|
||||
|
|
|
@ -15,6 +15,7 @@ PyObject* (*PyArray_New)(PyTypeObject *, int, npy_intp const *, int, npy_intp co
|
|||
PyObject* (*PyArray_FromAny)(PyObject *, PyArrayDescr_Proxy *, int, int, int, PyObject *);
|
||||
unsigned int (*PyArray_GetNDArrayCFeatureVersion)();
|
||||
int (*PyArray_SetBaseObject)(PyObject *arr, PyObject *obj);
|
||||
PyObject* (*PyArray_NewCopy)(PyObject *, int);
|
||||
|
||||
tmp_data_t tmp_data;
|
||||
|
||||
|
@ -30,6 +31,7 @@ void numpy_init() {
|
|||
fill(PyArray_New, 93);
|
||||
fill(PyArray_GetNDArrayCFeatureVersion, 211);
|
||||
fill(PyArray_SetBaseObject, 282);
|
||||
fill(PyArray_NewCopy, 85);
|
||||
|
||||
ASSERT(PyArray_GetNDArrayCFeatureVersion()>=7);
|
||||
}
|
||||
|
|
|
@ -97,6 +97,8 @@ extern PyObject* (*PyArray_New)(PyTypeObject *, int, npy_intp const *, int, npy_
|
|||
extern PyObject* (*PyArray_FromAny)(PyObject *, PyArrayDescr_Proxy *, int, int, int, PyObject *);
|
||||
extern unsigned int (*PyArray_GetNDArrayCFeatureVersion)();
|
||||
extern int (*PyArray_SetBaseObject)(PyObject *arr, PyObject *obj);
|
||||
extern PyObject* (*PyArray_NewCopy)(PyObject *, int);
|
||||
#define PyArray_Copy(obj) PyArray_NewCopy(obj, 0)
|
||||
|
||||
#define NPY_ARRAY_ALIGNED 0x0100
|
||||
#define NPY_ARRAY_WRITEABLE 0x0400
|
||||
|
|
|
@ -293,8 +293,13 @@ DEF_IS(ArrayArgs, T) from_py_object(PyObject* obj) {
|
|||
auto ptr = GET_RAW_PTR(VarHolder, obj);
|
||||
return move(fetch_sync({ptr}).at(0));
|
||||
}
|
||||
if (Py_TYPE(obj) != PyArray_Type) {
|
||||
PyObjHolder holder(PyArray_FROM_O(obj));
|
||||
// PyArray_Type
|
||||
auto arr = (PyArray_Proxy*)obj;
|
||||
if (Py_TYPE(obj) != PyArray_Type || !is_c_style(arr)) {
|
||||
PyObjHolder holder(
|
||||
Py_TYPE(obj) != PyArray_Type ?
|
||||
PyArray_FROM_O(obj) :
|
||||
PyArray_Copy(obj));
|
||||
auto arr = (PyArray_Proxy*)holder.obj;
|
||||
int64 size = PyArray_Size(arr);
|
||||
T args;
|
||||
|
@ -305,9 +310,6 @@ DEF_IS(ArrayArgs, T) from_py_object(PyObject* obj) {
|
|||
memcpy((void*)args.buffer.get(), (void*)arr->data, size);
|
||||
return args;
|
||||
}
|
||||
// PyArray_Type
|
||||
auto arr = (PyArray_Proxy*)obj;
|
||||
CHECK(is_c_style(arr));
|
||||
T args;
|
||||
args.ptr = arr->data;
|
||||
if (arr->dimensions)
|
||||
|
|
Loading…
Reference in New Issue