glumpy icon indicating copy to clipboard operation
glumpy copied to clipboard

Compatibility issues (of glu) with numpy v.2.x

Open Stephanowicz opened this issue 6 months ago • 3 comments

Hi there,

I just installed and tried glumpy and stumbled over several compatibility issues with numpy.

I'm using

  • glumpy 1.2.1
  • numpy 2.3.0

on Windows 11 OpenGL shading language version : 4.60 NVIDIA OpenGL ES shading language version : 3.2

I can only speak for this version of numpy, but I think this is starting with numpy 2.0

  1. in /gloo/variable.py
    in class Uniform(Variable):
    in def set_data(self, data):
    line 280:
    self._data[...] = np.array(data,copy=False).ravel()

copy=false rises an error
accroding to numpy (https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword) np.asarray is preferred over np.array and can mostly be used without copy=false.

So I changed this line to
self._data[...] = np.asarray(data).ravel()
and the error disappears
in this file are many other lines with np.array(data,copy=False) - maybe they need to be changed, too?

  1. in /gloo/program.py
    in function def active_uniforms(self):
    in line 453/454:

         name, size, gtype = gl.glGetActiveUniform(self.handle, i)
         name = name.decode()
    

    name.decode rises an error 'numpy.ndarray' object has no attribute 'decode'

    the name returned by gl.glGetActiveUniform is:

    [117 95 118 105 101 119 0 0 0 0 0 0 0 0 0 0 0 0]

    (wich is 'u_view' in ASCII)
    dunno if this GL-version dependant?

    so I made a workaround :

   name = name.tobytes().decode("ascii").strip()  
   name = ''.join(char for char in name if (ord(char) > 32 and ord(char) < 128))  

wich fixed it
(first line is converting to ASCII - second line removes the "0" chars)

Maybe there have been made changes to the decode function?

Cheers,

Stephan

Stephanowicz avatar Jun 12 '25 11:06 Stephanowicz

Thanks for the detailed report and the fix. Maybe the best would be to make a PR such that I can merge your fix.

rougier avatar Jun 14 '25 07:06 rougier

Hi,

well - I think this really needs further investigation - these are just quick fixes that worked for me...
I'm not into the matter, and also quite new to python... :D

e.g 1st - they say it can be used most of the times.... and as I mentioned, in the file are lot more of np.array(data,copy=False)

and 2nd - idk if the returned value for name by gl.glGetActiveUniform is what is expected ? And how did it work before? and my fix for this is what I found by a quick search in the net - maybe not the best, errorproof solution?

I hope some of the other contributers, that are deeper into the matter of gumpy, can take a look and make a PR... (well, if You say 'there is no other to take care of this and the fix is acceptable for the moment', I sure can make a PR)

Cheers, Stephan

Stephanowicz avatar Jun 15 '25 07:06 Stephanowicz

Ok. I'll try to fix it based on your feedback. Thanks again for the initial report.

rougier avatar Jun 15 '25 08:06 rougier