Efficient copying of vertex coords to and from numpy arrays

Hello. @ambi and @varkenvarken Bumping this seemed needed as things have probably evolved but this is the most recent relevant search result for such purely python based solutions. I am trying to accelerate some complete mesh export to strings routine, which up to now was just using bpy.mesh considering how Numpy could help, I found another topic using functions such as :

get_v_index = np.vectorize(lambda l: l.vert.index, otypes=['i4'], cache = True)
faces_verts = get_v_index(looptris)

But here no one ever mention Numpy Vectorize… Is it because it’s a) less practical for some cases, b) less readable for no gain, c) simply not faster , d) you haven’t tried it in your optimization trials ?

e) all of the above :slight_smile:

Seriously though: np.vectorize as documented will not have any speed benefit. It might (depending on your preferences) be considered to be more readable and will give you broadcasting but it looked to me like something that would be a waste of effort.To be honest, I didn’t try to actually use it, might be interesting to compare, but there is even a real change it will be actually slower because this will do a Python function call for every index that is retrieved whereas foreach_get will bypass that.

1 Like