Evaluate a distance spec for many targets (batch)
Arguments
- spec
Distance spec (see
is_distance()).- X
Numeric matrix \(n x p\).
- X0
Numeric matrix \(m x p\) (targets as rows).
- ctx
Optional context; if
NULLandspec$setupexists, it will be called asspec$setup(X)to create a context.
Examples
x_mat <- matrix(rnorm(12), 4, 3)
x0_mat <- matrix(rnorm(6), 2, 3)
distance_eval_batch(distance_l2(), x_mat, x0_mat)
#> [,1] [,2]
#> [1,] 1.808042 1.291032
#> [2,] 1.795455 1.221198
#> [3,] 1.977835 2.050604
#> [4,] 4.127344 3.380991