@@ -60,6 +60,36 @@ function test_metricity(dist, x, y, z)
60
60
end
61
61
end
62
62
63
+ function test_batch (dist, _x, _y, args= (); Tins= (Float32, Float64), Touts= Tins)
64
+ _xs = hcat (_x, _x)
65
+ _ys = hcat (_y, _y)
66
+
67
+ for (Tin, Tout) in zip (Tins, Touts)
68
+ x, y = Tin .(_x), Tin .(_y)
69
+ xs, ys = Tin .(_xs), Tin .(_ys)
70
+
71
+ # Instantiate using `args` if not already instantiated.
72
+ d = if dist isa PreMetric
73
+ dist
74
+ else
75
+ dist (map (a -> Tin .(a), args)... )
76
+ end
77
+
78
+ # Ensure that `result_type` preserves the type.
79
+ @test result_type (d, xs, ys) === Tout
80
+
81
+ # Ensure that `pairwise` preserves the type,
82
+ # e.g. if someone decides to implement their own.
83
+ colpairs = pairwise (d, xs, ys; dims= 2 )
84
+ @test eltype (colpairs) === Tout
85
+ @test all (colpairs .== d (x, y))
86
+
87
+ cols = colwise (d, xs, ys)
88
+ @test eltype (cols) === Tout
89
+ @test all (cols .== d (x, y))
90
+ end
91
+ end
92
+
63
93
@testset " PreMetric, SemiMetric, Metric on $T " for T in (Float64, F64)
64
94
Random. seed! (123 )
65
95
n = 100
424
454
end # testset
425
455
426
456
@testset " haversine" begin
457
+ let x = [1. ,- 15.625 ], y = [- 179. ,15.625 ]
458
+ # Type used in default constructor should work for both `Float32` and `Float64`.
459
+ test_batch (Haversine (), x, y)
460
+
461
+ # `Float32` should be promoted to `Float64`.
462
+ test_batch (Haversine {Float32} (), x, y)
463
+
464
+ # `Haversine(T(radius))` should result in `T` when inputs also has eltype `T`.
465
+ test_batch (Haversine, x, y, (6_371_000 , ))
466
+ end
467
+
427
468
for T in (Float64, F64)
428
469
@test haversine ([- 180. ,0. ], [180. ,0. ], 1. ) ≈ 0 atol= 1e-10
429
470
@test haversine ([0. ,- 90. ], [0. ,90. ], 1. ) ≈ π atol= 1e-10
0 commit comments