cosineDistance

fun <T : DType, V> Tensor<T, V>.cosineDistance(other: Tensor<T, V>, dim: Int = -1, eps: Double = 1.0E-8): Tensor<T, V>(source)

Calculates the cosine distance between two tensors along a given dimension. Cosine distance is defined as 1 - cosine similarity. Formula: 1 - (A dot B) / (||A|| * ||B||)

Return

A tensor containing the cosine distance.

Parameters

other

The other tensor to calculate the distance to.

dim

The dimension along which to calculate the cosine distance. Default is -1 (last dimension).

eps

A small value to avoid division by zero. Default is 1e-8.