Skip to content

Commit 8867613

Browse files
authored
Use the new MinkowskiMetric type from Distances.jl (#206)
1 parent fe9c35e commit 8867613

6 files changed

Lines changed: 58 additions & 51 deletions

File tree

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
name = "NearestNeighbors"
22
uuid = "b8a86587-4115-5ab1-83bc-aa920d37bbce"
3-
version = "0.4.20"
3+
version = "0.4.21"
44

55
[deps]
66
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
77
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
88

99
[compat]
10-
Distances = "0.9, 0.10"
10+
Distances = "0.10.12"
1111
StaticArrays = "0.9, 0.10, 0.11, 0.12, 1.0"
1212
julia = "1.6"
1313

benchmark/Manifest.toml

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is machine-generated - editing it directly is not advised
22

3-
julia_version = "1.10.4"
3+
julia_version = "1.11.1"
44
manifest_format = "2.0"
55
project_hash = "c2d4f1e1a4db771bb121b0dd2aff4834a9af3804"
66

@@ -11,13 +11,15 @@ version = "0.4.5"
1111

1212
[[deps.ArgTools]]
1313
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
14-
version = "1.1.1"
14+
version = "1.1.2"
1515

1616
[[deps.Artifacts]]
1717
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
18+
version = "1.11.0"
1819

1920
[[deps.Base64]]
2021
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
22+
version = "1.11.0"
2123

2224
[[deps.BenchmarkTools]]
2325
deps = ["JSON", "Logging", "Printf", "Profile", "Statistics", "UUIDs"]
@@ -33,12 +35,13 @@ version = "1.1.1+0"
3335
[[deps.Dates]]
3436
deps = ["Printf"]
3537
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
38+
version = "1.11.0"
3639

3740
[[deps.Distances]]
3841
deps = ["LinearAlgebra", "Statistics", "StatsAPI"]
39-
git-tree-sha1 = "66c4c81f259586e8f002eacebc177e1fb06363b0"
42+
git-tree-sha1 = "c7e3a542b999843086e2f29dac96a618c105be1d"
4043
uuid = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
41-
version = "0.10.11"
44+
version = "0.10.12"
4245

4346
[deps.Distances.extensions]
4447
DistancesChainRulesCoreExt = "ChainRulesCore"
@@ -61,10 +64,12 @@ version = "1.6.0"
6164

6265
[[deps.FileWatching]]
6366
uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"
67+
version = "1.11.0"
6468

6569
[[deps.InteractiveUtils]]
6670
deps = ["Markdown"]
6771
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
72+
version = "1.11.0"
6873

6974
[[deps.IrrationalConstants]]
7075
git-tree-sha1 = "630b497eafcc20001bba38a4651b327dcfc491d2"
@@ -73,9 +78,9 @@ version = "0.2.2"
7378

7479
[[deps.JLLWrappers]]
7580
deps = ["Artifacts", "Preferences"]
76-
git-tree-sha1 = "7e5d6779a1e09a36db2a7b6cff50942a0a7d0fca"
81+
git-tree-sha1 = "be3dc50a92e5a386872a493a10050136d4703f9b"
7782
uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
78-
version = "1.5.0"
83+
version = "1.6.1"
7984

8085
[[deps.JSON]]
8186
deps = ["Dates", "Mmap", "Parsers", "Unicode"]
@@ -97,16 +102,17 @@ version = "0.6.4"
97102
[[deps.LibCURL_jll]]
98103
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"]
99104
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"
100-
version = "8.4.0+0"
105+
version = "8.6.0+0"
101106

102107
[[deps.LibGit2]]
103108
deps = ["Base64", "LibGit2_jll", "NetworkOptions", "Printf", "SHA"]
104109
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
110+
version = "1.11.0"
105111

106112
[[deps.LibGit2_jll]]
107113
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll"]
108114
uuid = "e37daf67-58a4-590a-8e99-b0245dd2ffc5"
109-
version = "1.6.4+0"
115+
version = "1.7.2+0"
110116

111117
[[deps.LibSSH2_jll]]
112118
deps = ["Artifacts", "Libdl", "MbedTLS_jll"]
@@ -115,10 +121,12 @@ version = "1.11.0+1"
115121

116122
[[deps.Libdl]]
117123
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
124+
version = "1.11.0"
118125

119126
[[deps.LinearAlgebra]]
120127
deps = ["Libdl", "OpenBLAS_jll", "libblastrampoline_jll"]
121128
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
129+
version = "1.11.0"
122130

123131
[[deps.LogExpFunctions]]
124132
deps = ["DocStringExtensions", "IrrationalConstants", "LinearAlgebra"]
@@ -138,28 +146,31 @@ version = "0.3.28"
138146

139147
[[deps.Logging]]
140148
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
149+
version = "1.11.0"
141150

142151
[[deps.Markdown]]
143152
deps = ["Base64"]
144153
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
154+
version = "1.11.0"
145155

146156
[[deps.MbedTLS_jll]]
147157
deps = ["Artifacts", "Libdl"]
148158
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
149-
version = "2.28.2+1"
159+
version = "2.28.6+0"
150160

151161
[[deps.Mmap]]
152162
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
163+
version = "1.11.0"
153164

154165
[[deps.MozillaCACerts_jll]]
155166
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"
156-
version = "2023.1.10"
167+
version = "2023.12.12"
157168

158169
[[deps.NearestNeighbors]]
159170
deps = ["Distances", "StaticArrays"]
160171
path = ".."
161172
uuid = "b8a86587-4115-5ab1-83bc-aa920d37bbce"
162-
version = "0.4.17"
173+
version = "0.4.21"
163174

164175
[[deps.NetworkOptions]]
165176
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
@@ -168,7 +179,7 @@ version = "1.2.0"
168179
[[deps.OpenBLAS_jll]]
169180
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
170181
uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
171-
version = "0.3.23+4"
182+
version = "0.3.27+1"
172183

173184
[[deps.OpenLibm_jll]]
174185
deps = ["Artifacts", "Libdl"]
@@ -188,9 +199,15 @@ uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
188199
version = "2.8.1"
189200

190201
[[deps.Pkg]]
191-
deps = ["Artifacts", "Dates", "Downloads", "FileWatching", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
202+
deps = ["Artifacts", "Dates", "Downloads", "FileWatching", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "Random", "SHA", "TOML", "Tar", "UUIDs", "p7zip_jll"]
192203
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
193-
version = "1.10.0"
204+
version = "1.11.0"
205+
206+
[deps.Pkg.extensions]
207+
REPLExt = "REPL"
208+
209+
[deps.Pkg.weakdeps]
210+
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
194211

195212
[[deps.PkgBenchmark]]
196213
deps = ["BenchmarkTools", "Dates", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Pkg", "Printf", "TerminalLoggers", "UUIDs"]
@@ -213,40 +230,27 @@ version = "1.4.3"
213230
[[deps.Printf]]
214231
deps = ["Unicode"]
215232
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
233+
version = "1.11.0"
216234

217235
[[deps.Profile]]
218-
deps = ["Printf"]
219236
uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"
237+
version = "1.11.0"
220238

221239
[[deps.ProgressLogging]]
222240
deps = ["Logging", "SHA", "UUIDs"]
223241
git-tree-sha1 = "80d919dee55b9c50e8d9e2da5eeafff3fe58b539"
224242
uuid = "33c8b6b6-d38a-422a-b730-caa89a2f386c"
225243
version = "0.1.4"
226244

227-
[[deps.REPL]]
228-
deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"]
229-
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
230-
231245
[[deps.Random]]
232246
deps = ["SHA"]
233247
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
248+
version = "1.11.0"
234249

235250
[[deps.SHA]]
236251
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
237252
version = "0.7.0"
238253

239-
[[deps.Serialization]]
240-
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
241-
242-
[[deps.Sockets]]
243-
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
244-
245-
[[deps.SparseArrays]]
246-
deps = ["Libdl", "LinearAlgebra", "Random", "Serialization", "SuiteSparse_jll"]
247-
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
248-
version = "1.10.0"
249-
250254
[[deps.SpecialFunctions]]
251255
deps = ["IrrationalConstants", "LogExpFunctions", "OpenLibm_jll", "OpenSpecFun_jll"]
252256
git-tree-sha1 = "2f5d4697f21388cbe1ff299430dd169ef97d7e14"
@@ -267,9 +271,9 @@ version = "1.0.2"
267271

268272
[[deps.StaticArrays]]
269273
deps = ["LinearAlgebra", "PrecompileTools", "Random", "StaticArraysCore"]
270-
git-tree-sha1 = "6e00379a24597be4ae1ee6b2d882e15392040132"
274+
git-tree-sha1 = "777657803913ffc7e8cc20f0fd04b634f871af8f"
271275
uuid = "90137ffa-7385-5640-81b9-e52037218182"
272-
version = "1.9.5"
276+
version = "1.9.8"
273277

274278
[deps.StaticArrays.extensions]
275279
StaticArraysChainRulesCoreExt = "ChainRulesCore"
@@ -285,21 +289,23 @@ uuid = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
285289
version = "1.4.3"
286290

287291
[[deps.Statistics]]
288-
deps = ["LinearAlgebra", "SparseArrays"]
292+
deps = ["LinearAlgebra"]
293+
git-tree-sha1 = "ae3bb1eb3bba077cd276bc5cfc337cc65c3075c0"
289294
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
290-
version = "1.10.0"
295+
version = "1.11.1"
296+
297+
[deps.Statistics.extensions]
298+
SparseArraysExt = ["SparseArrays"]
299+
300+
[deps.Statistics.weakdeps]
301+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
291302

292303
[[deps.StatsAPI]]
293304
deps = ["LinearAlgebra"]
294305
git-tree-sha1 = "1ff449ad350c9c4cbc756624d6f8a8c3ef56d3ed"
295306
uuid = "82ae8749-77ed-4fe6-ae5f-f523153014b0"
296307
version = "1.7.0"
297308

298-
[[deps.SuiteSparse_jll]]
299-
deps = ["Artifacts", "Libdl", "libblastrampoline_jll"]
300-
uuid = "bea87d4a-7f5b-5778-9afe-8cc45184846c"
301-
version = "7.2.1+1"
302-
303309
[[deps.TOML]]
304310
deps = ["Dates"]
305311
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
@@ -319,9 +325,11 @@ version = "0.1.7"
319325
[[deps.UUIDs]]
320326
deps = ["Random", "SHA"]
321327
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
328+
version = "1.11.0"
322329

323330
[[deps.Unicode]]
324331
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
332+
version = "1.11.0"
325333

326334
[[deps.Zlib_jll]]
327335
deps = ["Libdl"]
@@ -331,12 +339,12 @@ version = "1.2.13+1"
331339
[[deps.libblastrampoline_jll]]
332340
deps = ["Artifacts", "Libdl"]
333341
uuid = "8e850b90-86db-534c-a0d3-1478176c7d93"
334-
version = "5.8.0+1"
342+
version = "5.11.0+0"
335343

336344
[[deps.nghttp2_jll]]
337345
deps = ["Artifacts", "Libdl"]
338346
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"
339-
version = "1.52.0+1"
347+
version = "1.59.0+0"
340348

341349
[[deps.p7zip_jll]]
342350
deps = ["Artifacts", "Libdl"]

src/NearestNeighbors.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module NearestNeighbors
22

33
using Distances
4-
import Distances: PreMetric, Metric, result_type, eval_reduce, eval_end, eval_op, eval_start, evaluate, parameters
4+
import Distances: PreMetric, Metric, UnionMinkowskiMetric, result_type, eval_reduce, eval_end, eval_op, eval_start, evaluate, parameters
55

66
using StaticArrays
77
import Base.show
@@ -21,9 +21,9 @@ export Euclidean,
2121

2222
abstract type NNTree{V <: AbstractVector,P <: PreMetric} end
2323

24-
const NonweightedMinowskiMetric = Union{Euclidean,Chebyshev,Cityblock,Minkowski}
25-
const WeightedMinowskiMetric = Union{WeightedEuclidean,WeightedCityblock,WeightedMinkowski}
26-
const MinkowskiMetric = Union{NonweightedMinowskiMetric, WeightedMinowskiMetric}
24+
const NonweightedMinkowskiMetric = Union{Euclidean,Chebyshev,Cityblock,Minkowski}
25+
const WeightedMinkowskiMetric = Union{WeightedEuclidean,WeightedCityblock,WeightedMinkowski}
26+
const MinkowskiMetric = UnionMinkowskiMetric
2727
function check_input(::NNTree{V1}, ::AbstractVector{V2}) where {V1, V2 <: AbstractVector}
2828
if length(V1) != length(V2)
2929
throw(ArgumentError(

src/evaluation.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
@inline eval_pow(::WeightedEuclidean, s) = abs2(s)
44
@inline eval_pow(d::Minkowski, s) = abs(s)^d.p
55

6-
@inline eval_diff(::NonweightedMinowskiMetric, a, b, dim) = a - b
6+
@inline eval_diff(::NonweightedMinkowskiMetric, a, b, dim) = a - b
77
@inline eval_diff(::Chebyshev, ::Any, b, dim) = b
8-
@inline eval_diff(m::WeightedMinowskiMetric, a, b, dim) = m.weights[dim] * (a-b)
8+
@inline eval_diff(m::WeightedMinkowskiMetric, a, b, dim) = m.weights[dim] * (a-b)
99

1010
function evaluate_maybe_end(d::Distances.UnionMetrics, a::AbstractVector,
1111
b::AbstractVector, do_end::Bool)

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using StaticArrays
44
using Test
55
using LinearAlgebra
66

7-
using Distances: Distances, Metric, evaluate, PeriodicEuclidean
7+
using Distances: Distances, Metric, MinkowskiMetric, evaluate, PeriodicEuclidean
88
struct CustomMetric1 <: Metric end
99
Distances.evaluate(::CustomMetric1, a::AbstractVector, b::AbstractVector) = maximum(abs.(a .- b))
1010
function NearestNeighbors.interpolate(::CustomMetric1,

test/test_monkey.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import NearestNeighbors.MinkowskiMetric
21
# This contains a bunch of random tests that should hopefully detect if
32
# some edge case has been missed in the real tests
43

0 commit comments

Comments
 (0)