本文介绍了OpenGL说"from_param接收到非连续数组".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

安装优胜美地后,我必须升级numpy,PyOpenGL等.

After installing Yosemite, I had to upgrade numpy, PyOpenGL, etc.

现在,一个以前可以正常工作的程序为我提供了以下堆栈跟踪:

Now, a previously-working program is giving me the following stack trace:

file "latebind.pyx", line 44, in OpenGL_accelerate.latebind.Curry.__call__ (src/latebind.c:1201)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/OpenGL/GL/VERSION/GL_1_5.py", line 89, in glBufferData
    return baseOperation( target, size, data, usage )
  File "latebind.pyx", line 32, in OpenGL_accelerate.latebind.LateBind.__call__ (src/latebind.c:989)
  File "wrapper.pyx", line 314, in OpenGL_accelerate.wrapper.Wrapper.__call__ (src/wrapper.c:6505)
  File "wrapper.pyx", line 311, in OpenGL_accelerate.wrapper.Wrapper.__call__ (src/wrapper.c:6439)
ctypes.ArgumentError: ("argument 3: <class 'OpenGL.error.CopyError'>: from_param received a non-contiguous array! []", (GL_ARRAY_BUFFER, 0, array([],
      dtype=[('time', '<f8'), ('data', [('cluster_index', '<i4'), ('delta_diag_out', '<f8')])]), GL_STREAM_DRAW))

看起来PyOpenGL希望我的数组是连续的.在PyOpenGL中查看numpy_formathandler.pyx中的源代码:

It looks like PyOpenGL wants my array to be contiguous. Looking at the source in numpy_formathandler.pyx in PyOpenGL:

if not PyArray_ISCARRAY( instance ):
            raise CopyError(
                """from_param received a non-contiguous array! %s"""%(
                    working,
                )
            )

PyArray_ISCARRAY(arr)如果arr的数据区域为C样式连续且PyArray_ISBEHAVED(arr)为true,则评估为true.据此,"PyArray_ISBEHAVED(arr)如果arr的数据区域是对齐且可写的,并且根据其描述符以机器字节顺序进行计算,则为true."

And PyArray_ISCARRAY(arr) "Evaluates true if the data area of arr is C-style contiguous, and PyArray_ISBEHAVED (arr) is true." Whereby "PyArray_ISBEHAVED(arr)Evalutes true if the data area of arr is aligned and writeable and in machine byte-order according to its descriptor."

但是,推送到OpenGL的数组的flags属性是:

However, the flags attribute of the array that was pushed to OpenGL is:

  C_CONTIGUOUS : True
  F_CONTIGUOUS : True
  OWNDATA : False
  WRITEABLE : True
  ALIGNED : False
  UPDATEIFCOPY : False

也许我需要对齐数组?但是,将numpy.requirerequirements={'ALIGNED': True}结合使用似乎无效.

Perhaps I need to align the array? But using numpy.require with requirements={'ALIGNED': True} doesn't seem to work.

我查看了numpy 1.9中的更改,这些更改指示:

I looked at the changes in numpy 1.9, which indicate:

NPY_RELAXED_STRIDES_CHECKING = 1 python setup.py安装

NPY_RELAXED_STRIDES_CHECKING=1 python setup.py install

您可以检查 通过运行以下命令是否有效NPY_RELAXED_STRIDES_CHECKING:

You can check whether NPY_RELAXED_STRIDES_CHECKING is in effect by running:

np.ones((10,1),order ="C").flags.f_contiguous

np.ones((10, 1), order="C").flags.f_contiguous

如果是,则为True 宽松的步幅检查已启用,否则为False.典型的 到目前为止,我们所看到的问题是与C相邻的C代码 数组,并假设可以通过查看来访问itemsize PyArray_STRIDES(arr)数组中的最后一个元素.放松的时候 迈进了一步,这是不正确的(事实上,从来没有 在某些情况下为真).而是使用PyArray_ITEMSIZE(arr).

This will be True if relaxed strides checking is enabled, and False otherwise. The typical problem we’ve seen so far is C code that works with C-contiguous arrays, and assumes that the itemsize can be accessed by looking at the last element in the PyArray_STRIDES(arr) array. When relaxed strides are in effect, this is not true (and in fact, it never was true in some corner cases). Instead, use PyArray_ITEMSIZE(arr).

但是,np.ones((10, 1), order="C").flags.f_contiguous在我的系统上为False.所以我很沮丧.什么变化导致opengl认为我发送的数组不连续且未对齐?有没有办法用力对齐数组?

However, np.ones((10, 1), order="C").flags.f_contiguous is False on my system. So I'm stumped. What changed that is causing opengl to think that the arrays I'm sending it are not contiguous and aligned? Is there a way to align an array by force?

推荐答案

这可能与numpy 1.9中的此错误有关,该错误未分配给任何人: https://github.com/numpy/numpy/issues/5224

This is probably related to this bug in numpy 1.9 to which no one is assigned: https://github.com/numpy/numpy/issues/5224

这篇关于OpenGL说"from_param接收到非连续数组".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 01:31
查看更多