Attribute Statistic node
Status: The implementation is ready and the speed is definitely usable. However currently all outputs are calculated even when the some of the sockets are not connected. For most operations this does not really matter because they're cheap, but finding median is relatively expensive, so it would be good to calculate it only when the socket is connected. Also in certain cases, the materialization of the attributes could then be removed.
Description
Current UI:
Initial UI (for reference):
Design
The possible data_types:
- Float (float)
- Vector (float3)
Conversion to the data_type happens before calculating the statistic and is handled by create_implicit_conversions.
A few notes:
- all statistics are element-wise for Vectors
- product was not added because the it would very easily overflow
- it was decided to not add the + operator etc, to Color4f (see: https://developer.blender.org/D10269#inline-82590), so I've also removed support for the color data type in this patch too.
Benchmarks
Node evaluation time breakdown for a float attribute:
Node evaluation time breakdown for a vector attribute:
Note about the full sort: Sorting the entire span is only slightly slower that std::nth_element in a single thread, but sorting seems to scale better with amount of threads than std::nth_element. For certain spans e.g. the UVMap span, std::nth_element is terribly slow when executing multithreaded, and just sorting the entire array is much faster. Not sure what the cause could be, it looks like some kind of "soft deadlock" is happening, where the threads are competing for the same data during the median calculation.
File used for the benchmarks:




