Skip to content

ndarray to buffer converter fun #14

@jeromeetienne

Description

@jeromeetienne

Long/complex explanation sorry: It explains why converting why generating protocol commands with vec3 always leads to exception.


This is the ndarray to buffer converter. It is used to convert vec3/vec4 to buffer, which is required to generate GSP commands from any visual.

@register("ndarray", "Buffer")
def ndarray_to_Buffer(obj):
# WARN: Do we need to keep track of obj/Buffer such as not create
# several buffers pointing at the same underlying object?
# In the current implementation, Buffer is created each time
# this convertes is called such that if the obj has been
# mofidied, it shoudl be ok
Z = glm.ndarray.tracked(obj)
return Z._tracker.gsp_buffer

As it is a converter, the obj in there is a numpy.ndarray. It uses glm.ndarray.tracked(obj) which is supposed to be API compatible with np.ndarray (@rougier correct me if im wrong).

It then goes into the __new__ of https://github.com/vispy/GSP/blob/master/gsp/glm/ndarray/tracked.py.

def __new__(cls, *args, **kwargs):
obj = np.ndarray.__new__(cls, *args, **kwargs)
if cls.__tracker_class__ is not None:
obj._tracker = cls.__tracker_class__(obj)
return obj

And here notice how it call np.ndarray.__new__(cls, *args, **kwargs) which is relatively equivalent to np.ndarray(obj) with the obj from the converter.

Unfortunatly np.ndarray(other_ndarray) is not a valid API. here is the doc https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html which shows that the first argument is a shape . It interprets the other_ndarray as a definition of shape and lead to this error message

Exception has occurred: ValueError
maximum supported dimension for an ndarray is currently 64, found 200000

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions