[ismrmrd] 164/281: forcing Fortran-style order in NumPy array (bindings)

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Jan 14 20:01:10 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to annotated tag ismrmrd0.5
in repository ismrmrd.

commit 96742ee39e5e893caf33a6e5593bcd33201d7bd5
Author: Joseph Naegele <joseph.naegele at gmail.com>
Date:   Mon Aug 5 10:55:55 2013 -0400

    forcing Fortran-style order in NumPy array (bindings)
    
    also adding installation of 'FindNumPy.cmake'.
---
 CMakeLists.txt                   |  3 ++-
 bindings/python/ismrmrd_python.i | 37 +++++++++++++++++++++++++++----------
 2 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index e5e7ec0..d0c1158 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -57,7 +57,8 @@ ENDIF(WIN32)
 
 INSTALL(FILES ismrmrd.h ismrmrd_hdf5.h ismrmrd_hdf5_datatypes.h ismrmrd_export.h DESTINATION include)
 INSTALL(FILES schema/ismrmrd.xsd ${XSDS_SOURCES} DESTINATION schema)
-INSTALL(FILES cmake/FindIsmrmrd.cmake cmake/FindFFTW3.cmake cmake/FindXSD.cmake cmake/FindXercesC.cmake DESTINATION cmake)
+INSTALL(FILES cmake/FindIsmrmrd.cmake cmake/FindFFTW3.cmake cmake/FindXSD.cmake
+        cmake/FindXercesC.cmake cmake/FindNumPy.cmake DESTINATION cmake)
 INSTALL(TARGETS ismrmrd DESTINATION lib)
 INSTALL(FILES ${MatlabMFiles} DESTINATION matlab/+ismrmrd)
 
diff --git a/bindings/python/ismrmrd_python.i b/bindings/python/ismrmrd_python.i
index c3cdbd2..95b9cfa 100644
--- a/bindings/python/ismrmrd_python.i
+++ b/bindings/python/ismrmrd_python.i
@@ -102,7 +102,8 @@
     PyObject* getData()
     {
         npy_intp dims[] = { $self->getData().size() };
-        PyObject *array = PyArray_SimpleNew(1, dims, NPY_FLOAT);
+	PyObject *array = PyArray_New(&PyArray_Type, 1, dims, NPY_FLOAT,
+                NULL, NULL, 0, NPY_ARRAY_FARRAY, NULL);
 
         char *raw = PyArray_BYTES(array);
         int data_size = PyArray_ITEMSIZE(array);
@@ -114,19 +115,27 @@
         return array;
     }
 
-    void setData(PyObject *array)
+    void setData(PyObject *in_array)
     {
-        if (!PyArray_Check(array) || !PyArray_ISFLOAT(array)) {
+        if (!PyArray_Check(in_array) || !PyArray_ISFLOAT(in_array)) {
             set_err("Argument to setData is not a numpy float array\n");
             return;
-        } else if (!PyArray_ISBEHAVED_RO(array)) {
+        } else if (!PyArray_ISBEHAVED_RO(in_array)) {
             set_err("Argument to setData must be aligned\n");
             return;
-        } else if (!PyArray_ISONESEGMENT(array)) {
+        } else if (!PyArray_ISONESEGMENT(in_array)) {
             set_err("Data is not one segment\n");
             return;
         }
 
+        PyObject *array = NULL;
+        /* if array is C-style contiguous, make a Fortran-style contiguous copy */
+        if (PyArray_ISCONTIGUOUS(in_array)) {
+            array = PyArray_NewCopy((PyArrayObject*)in_array, NPY_FORTRANORDER);
+        } else {
+            array = in_array;
+        }
+
         int ndim = PyArray_NDIM(array);
         int itemsize = PyArray_ITEMSIZE(array);
         npy_intp nbytes = PyArray_NBYTES(array);
@@ -202,16 +211,24 @@
         return array;
     }
 
-    int appendArray(PyObject *array, const char* varname)
+    int appendArray(PyObject *in_array, const char* varname)
     {
-        if (!PyArray_Check(array)) {
-            set_err("Array arg to appendArray is not a numpy array\n");
+        if (!PyArray_Check(in_array)) {
+            set_err("array arg to appendArray is not a numpy array\n");
             return -1;
-        } else if (!PyArray_ISBEHAVED_RO(array)) {
-            set_err("Array arg to appendArray must be aligned and in machine byte-order\n");
+        } else if (!PyArray_ISBEHAVED_RO(in_array)) {
+            set_err("array arg to appendArray must be aligned and in machine byte-order\n");
             return -1;
         }
 
+        PyObject *array = NULL;
+        /* if in_array is C-style contiguous, make it a Fortran-style contiguous copy */
+        if (PyArray_ISCONTIGUOUS(in_array)) {
+            array = PyArray_NewCopy((PyArrayObject*)in_array, NPY_FORTRANORDER);
+        } else {
+            array = in_array;
+        }
+
         int ndim = PyArray_NDIM(array);
         npy_intp* dims = PyArray_DIMS(array);
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/ismrmrd.git



More information about the debian-science-commits mailing list