Update clustering code generation
Add unit tests for sample_from_scores & friends