pub fn euclidean_grad<T>(x: &Array1<T>, y: &Array1<T>) -> (T, Vec<T>)where
T: Float,Expand description
Computes the Euclidean distance and its gradient between two vectors.
The function calculates the Euclidean distance between two input vectors x and y
and returns both the distance and the gradient. The gradient indicates how much each
element in the input vectors contributes to the distance.
§Parameters
x: AnArray1<T>representing the first vector.y: AnArray1<T>representing the second vector.
§Type Parameter
T: A generic type that must implement theFloattrait. This ensures that the elements in vectorsxandycan be used for arithmetic operations involving floating-point numbers.
§Returns
A tuple containing:
- The Euclidean distance between the two input vectors, of type
T. - An
Array1<T>representing the gradient. Each element in this array corresponds to the contribution of each element in the input vectors towards the Euclidean distance.
§Panics
- If the input arrays do not have the same length, the function will panic with an appropriate error message.