Batch distance operations

Hi all,

As part of calculating the silhouette coefficient on a set of clusters, we run code to calculate the distance between INDArray vectors:


We currently run this for every point vs every other point in the same and other clusters.
With large amounts of points in each cluster, this can take quite a long time to compute (we are running with a CUDA backend).

We were wondering if the overhead was between CPU and GPU. Would it be possible to batch these distance calculations and run them all at once? I had a look at Transforms.allEuclideanDistances, but the JavaDoc doesn’t have an explanation on the expected input or output.

Any help is greatly appreciated.

Hi all,

I tried using Transforms.allEuclideanDistances(arrayA, arrayB, 1);

But it took 20 seconds to perform a batch calculation this way (1 vs 1000+ vectors), as opposed to 2 seconds to perform the same calculations individually in a for loop. It seems strange that doing them individually is so much faster.

What are your dimensions you’re doing the batch operations on?
Some reproduction code would be helpful.
A quick JMH benchmark indicates that the for loop is slower.