[cig-commits] r13629 - cs/cigma/trunk/src

luis at geodynamics.org luis at geodynamics.org
Tue Dec 9 18:16:29 PST 2008


Author: luis
Date: 2008-12-09 18:16:29 -0800 (Tue, 09 Dec 2008)
New Revision: 13629

Modified:
   cs/cigma/trunk/src/numpy_util.cpp
Log:
Fixes in numpy_util.cpp for Mac OS X

Current code fails when trying to use pointers to npy_intp
as int pointers:

  error: invalid conversion from 'npy_intp*' to 'int*'

assuming that the cast will work, we simply apply an (int*) cast
where necessary.

Modified: cs/cigma/trunk/src/numpy_util.cpp
===================================================================
--- cs/cigma/trunk/src/numpy_util.cpp	2008-12-10 02:16:28 UTC (rev 13628)
+++ cs/cigma/trunk/src/numpy_util.cpp	2008-12-10 02:16:29 UTC (rev 13629)
@@ -104,7 +104,10 @@
 // Create a one-dimensional numeric array of length n and type t
 numeric::array makeArray(intp n, PyArray_TYPES t=PyArray_DOUBLE)
 {
-    object obj(handle<>(PyArray_FromDims(1, &n, t)));
+    // XXX: how safe is it to cast intp* to int*?
+    // See ndarrayobject.h and pyport.h for the typedefs
+    // intp -> npy_intp -> Py_intptr_t -> intptr_t
+    object obj(handle<>(PyArray_FromDims(1, (int*)&n, t)));
     return extract<numeric::array>(obj);
 }
 
@@ -112,14 +115,16 @@
 numeric::array makeArray(intp m, intp n, PyArray_TYPES t=PyArray_DOUBLE)
 {
     intp dims[2] = {m,n};
-    object obj(handle<>(PyArray_FromDims(2, dims, t)));
+    // XXX: intp* cast into int*
+    object obj(handle<>(PyArray_FromDims(2, (int*)dims, t)));
     return extract<numeric::array>(obj);
 }
 
 // Create a numeric array with dimensions dimens and type t
 numeric::array makeArray(std::vector<intp> dimens, PyArray_TYPES t=PyArray_DOUBLE)
 {
-    object obj(handle<>(PyArray_FromDims(dimens.size(), &dimens[0], t)));
+    // XXX: intp* cast into int*
+    object obj(handle<>(PyArray_FromDims(dimens.size(), (int*)&dimens[0], t)));
     return extract<numeric::array>(obj);
 }
 
@@ -215,7 +220,8 @@
         PyErr_SetString(PyExc_ValueError, "expected a PyArrayObject");
         throw_error_already_set();
     }
-    int* dims_ptr = PyArray_DIMS(arr.ptr());
+    // XXX: intp* cast into int*
+    int* dims_ptr = (int*)PyArray_DIMS(arr.ptr());
     int the_rank = rank(arr);
     for (int i = 0; i < the_rank; i++)
     {



More information about the CIG-COMMITS mailing list