mtazzari / galario

Gpu Accelerated Library for Analysing Radio Interferometer Observations
https://mtazzari.github.io/galario/
GNU Lesser General Public License v3.0
31 stars 15 forks source link

ValueError: ndarray is not C-contiguous #121

Closed mtazzari closed 6 years ago

mtazzari commented 6 years ago

I get this error by calling one of galario functions:

Traceback (most recent call last):
  File "quickstart_twhya.py", line 169, in <module>
    chi2 = g_double.chi2Profile(np.ones(nxy), Rmin, dR, nxy, dxy, u, v, Re, Im, w)
  File "libcommon.pyx", line 629, in libcommon.chi2Profile
  File "stringsource", line 646, in View.MemoryView.memoryview_cwrapper
  File "stringsource", line 347, in View.MemoryView.memoryview.__cinit__
fredRos commented 6 years ago

Unfortunately the error message doesn't say which input array is not contiguous but that's a cython limitation. We require all array inputs to be contiguous because the underlying C/C++ implementation is agnostic of numpy tricks. The solution is easy. Call

u = numpy.ascontiguousarray(u)
v = numpy.ascontiguousarray(v)
...

on all your inputs. You can check manually if an array is contiguous with u.flags. Often you will call galario repeatedly in a fit. To avoid making copies again and again, we ask the user to do the conversion if necessary. In fact, ascontiguousarray(u) doesn't copy u if u is already contiguous.