-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adaptive Polygons mk3 #3798
Adaptive Polygons mk3 #3798
Conversation
arr[:,0] /= lens | ||
arr[:,1] /= lens | ||
arr[:,2] /= lens | ||
return arr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest
- Change this to something like
result = np.zeros(arr.shape)
norms = np.linalg.norm(arr, axis=1, keepdims=True)
nonzero = (norms > 0)[:,0]
result[nonzero] = arr[nonzero] / norms[nonzero][:,0][np.newaxis].T
this 1) uses vectorization more effectively (at least, theoretically it should), 2) takes care of division by zero.
- Move it to
sverchok.utils.math
, because I think I saw similar functions in other modules, at least next time there will be "standard" function to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
I did some performance tests
and this was 10% faster:
def np_normalized_v3(vecs):
result = np.zeros(vecs.shape)
norms = np.linalg.norm(vecs, axis=1)
nonzero = (norms > 0)
result[nonzero] = vecs[nonzero] / norms[nonzero][:,np.newaxis]
return result
And this like 2.5x faster. Does the normalisation in-place (good for me in this case)
def np_normalize_v3(vecs):
norms = np.linalg.norm(vecs, axis=1)
nonzero = (norms > 0)
vecs[nonzero] = vecs[nonzero] / norms[nonzero][:,np.newaxis]
I added both to sverchok.utils.math
Could anyone give me a hint of why the CI is failing? i found an error in the bl_idname of trim_and_tesselate (@portnov) but maybe I should leave it like was to avoid layout breaks because does not seem the cause |
8e565cf
to
dfda417
Compare
@vicdoval did you re-save json files, or just replaced Mk2 with Mk3? |
The error message is still confusing... |
Thanks @portnov. You were right the key was in the examples, they broke with the socket renaming. |
Also if you are interesting in adding new stuff in the node it could be useful to make the node dealing with UW mappings. |
@Durman Do you have the building example Blend with adaptive polygon? I am curious about the building and the logic. |
This file I used in this some sort of a tutorial. |
Numpy implementation for the Adaptive polygons node.
In this scenario:
Before 0.793 seconds. Now 0.058 seconds (13X)
I left the previous implementation because is faster when the donor has less than 12 vertices for quad transform and 50 for tris transform. (approx.)
The default is a Auto mode that switches implementation depending on the donor vert count.
Also added a Donor Matching property that can be Repeat Last, Cycle or By Index (controlled by input)