Steve132
Steve132 t1_j28og0o wrote
Reply to comment by RingoCatKeeper in [P]Run CLIP on your iPhone to Search Photos offline. by RingoCatKeeper
There's an O(n) algorithm for top k partitioning that could be much much faster than .sort() when you have thousands of elements.
QuickSelect. In C++ its available as std::nth_element
in swift I couldn't find it directly but you can implement it in a few lines using .partition as a subroutine
Steve132 t1_j28oxex wrote
Reply to comment by londons_explorer in [P]Run CLIP on your iPhone to Search Photos offline. by RingoCatKeeper
One thing you aren't taking into account is that the computation of the similarity scores is O(n) but the sorting he's doing is n log n which for 1m might dominate especially since it's not necessarily hardware optimized