@@ -46,15 +46,15 @@ __eltype(::Base.EltypeUnknown, a) = _eltype(typeof(first(a)))
46
46
# Generic column-wise evaluation
47
47
48
48
"""
49
- colwise!(r::AbstractArray, metric::PreMetric , a, b)
49
+ colwise!(metric::PreMetric, r::AbstractArray , a, b)
50
50
51
51
Compute distances between corresponding elements of the iterable collections
52
52
`a` and `b` according to distance `metric`, and store the result in `r`.
53
53
54
54
`a` and `b` must have the same number of elements, `r` must be an array of length
55
55
`length(a) == length(b)`.
56
56
"""
57
- function colwise! (r :: AbstractArray , metric :: PreMetric , a, b)
57
+ function colwise! (metric :: PreMetric , r :: AbstractArray , a, b)
58
58
require_one_based_indexing (r)
59
59
n = length (a)
60
60
length (b) == n || throw (DimensionMismatch (" iterators have different lengths" ))
@@ -65,7 +65,7 @@ function colwise!(r::AbstractArray, metric::PreMetric, a, b)
65
65
r
66
66
end
67
67
68
- function colwise! (r :: AbstractArray , metric :: PreMetric , a:: AbstractVector , b:: AbstractMatrix )
68
+ function colwise! (metric :: PreMetric , r :: AbstractArray , a:: AbstractVector , b:: AbstractMatrix )
69
69
require_one_based_indexing (r)
70
70
n = size (b, 2 )
71
71
length (r) == n || throw (DimensionMismatch (" Incorrect size of r." ))
@@ -75,7 +75,7 @@ function colwise!(r::AbstractArray, metric::PreMetric, a::AbstractVector, b::Abs
75
75
r
76
76
end
77
77
78
- function colwise! (r :: AbstractArray , metric :: PreMetric , a:: AbstractMatrix , b:: AbstractVector )
78
+ function colwise! (metric :: PreMetric , r :: AbstractArray , a:: AbstractMatrix , b:: AbstractVector )
79
79
require_one_based_indexing (r)
80
80
n = size (a, 2 )
81
81
length (r) == n || throw (DimensionMismatch (" Incorrect size of r." ))
@@ -86,11 +86,11 @@ function colwise!(r::AbstractArray, metric::PreMetric, a::AbstractMatrix, b::Abs
86
86
end
87
87
88
88
"""
89
- colwise!(r::AbstractArray, metric::PreMetric ,
89
+ colwise!(metric::PreMetric, r::AbstractArray ,
90
90
a::AbstractMatrix, b::AbstractMatrix)
91
- colwise!(r::AbstractArray, metric::PreMetric ,
91
+ colwise!(metric::PreMetric, r::AbstractArray ,
92
92
a::AbstractVector, b::AbstractMatrix)
93
- colwise!(r::AbstractArray, metric::PreMetric ,
93
+ colwise!(metric::PreMetric, r::AbstractArray ,
94
94
a::AbstractMatrix, b::AbstractVector)
95
95
96
96
Compute distances between each corresponding columns of `a` and `b` according
@@ -105,7 +105,7 @@ vector. `r` must be an array of length `maximum(size(a, 2), size(b, 2))`.
105
105
If both `a` and `b` are vectors, the generic, iterator-based method of
106
106
`colwise` applies.
107
107
"""
108
- function colwise! (r :: AbstractArray , metric :: PreMetric , a:: AbstractMatrix , b:: AbstractMatrix )
108
+ function colwise! (metric :: PreMetric , r :: AbstractArray , a:: AbstractMatrix , b:: AbstractMatrix )
109
109
require_one_based_indexing (r, a, b)
110
110
n = get_common_ncols (a, b)
111
111
length (r) == n || throw (DimensionMismatch (" Incorrect size of r." ))
@@ -126,7 +126,7 @@ Compute distances between corresponding elements of the iterable collections
126
126
function colwise (metric:: PreMetric , a, b)
127
127
n = get_common_length (a, b)
128
128
r = Vector {result_type(metric, a, b)} (undef, n)
129
- colwise! (r, metric , a, b)
129
+ colwise! (metric, r , a, b)
130
130
end
131
131
132
132
"""
@@ -148,25 +148,25 @@ vector.
148
148
function colwise (metric:: PreMetric , a:: AbstractMatrix , b:: AbstractMatrix )
149
149
n = get_common_ncols (a, b)
150
150
r = Vector {result_type(metric, a, b)} (undef, n)
151
- colwise! (r, metric , a, b)
151
+ colwise! (metric, r , a, b)
152
152
end
153
153
154
154
function colwise (metric:: PreMetric , a:: AbstractVector , b:: AbstractMatrix )
155
155
n = size (b, 2 )
156
156
r = Vector {result_type(metric, a, b)} (undef, n)
157
- colwise! (r, metric , a, b)
157
+ colwise! (metric, r , a, b)
158
158
end
159
159
160
160
function colwise (metric:: PreMetric , a:: AbstractMatrix , b:: AbstractVector )
161
161
n = size (a, 2 )
162
162
r = Vector {result_type(metric, a, b)} (undef, n)
163
- colwise! (r, metric , a, b)
163
+ colwise! (metric, r , a, b)
164
164
end
165
165
166
166
167
167
# Generic pairwise evaluation
168
168
169
- function _pairwise! (r :: AbstractMatrix , metric :: PreMetric , a, b= a)
169
+ function _pairwise! (metric :: PreMetric , r :: AbstractMatrix , a, b= a)
170
170
require_one_based_indexing (r)
171
171
na = length (a)
172
172
nb = length (b)
@@ -177,7 +177,7 @@ function _pairwise!(r::AbstractMatrix, metric::PreMetric, a, b=a)
177
177
r
178
178
end
179
179
180
- function _pairwise! (r :: AbstractMatrix , metric :: PreMetric ,
180
+ function _pairwise! (metric :: PreMetric , r :: AbstractMatrix ,
181
181
a:: AbstractMatrix , b:: AbstractMatrix = a)
182
182
require_one_based_indexing (r, a, b)
183
183
na = size (a, 2 )
@@ -192,7 +192,7 @@ function _pairwise!(r::AbstractMatrix, metric::PreMetric,
192
192
r
193
193
end
194
194
195
- function _pairwise! (r :: AbstractMatrix , metric :: SemiMetric , a)
195
+ function _pairwise! (metric :: SemiMetric , r :: AbstractMatrix , a)
196
196
require_one_based_indexing (r)
197
197
n = length (a)
198
198
size (r) == (n, n) || throw (DimensionMismatch (" Incorrect size of r." ))
@@ -208,7 +208,7 @@ function _pairwise!(r::AbstractMatrix, metric::SemiMetric, a)
208
208
r
209
209
end
210
210
211
- function _pairwise! (r :: AbstractMatrix , metric :: SemiMetric , a:: AbstractMatrix )
211
+ function _pairwise! (metric :: SemiMetric , r :: AbstractMatrix , a:: AbstractMatrix )
212
212
require_one_based_indexing (r)
213
213
n = size (a, 2 )
214
214
size (r) == (n, n) || throw (DimensionMismatch (" Incorrect size of r." ))
@@ -237,7 +237,7 @@ function deprecated_dims(dims::Union{Nothing,Integer})
237
237
end
238
238
239
239
"""
240
- pairwise!(r::AbstractMatrix, metric::PreMetric ,
240
+ pairwise!(metric::PreMetric, r::AbstractMatrix ,
241
241
a::AbstractMatrix, b::AbstractMatrix=a; dims)
242
242
243
243
Compute distances between each pair of rows (if `dims=1`) or columns (if `dims=2`)
@@ -247,7 +247,7 @@ If a single matrix `a` is provided, compute distances between its rows or column
247
247
`a` and `b` must have the same numbers of columns if `dims=1`, or of rows if `dims=2`.
248
248
`r` must be a matrix with size `size(a, dims) × size(b, dims)`.
249
249
"""
250
- function pairwise! (r :: AbstractMatrix , metric :: PreMetric ,
250
+ function pairwise! (metric :: PreMetric , r :: AbstractMatrix ,
251
251
a:: AbstractMatrix , b:: AbstractMatrix ;
252
252
dims:: Union{Nothing,Integer} = nothing )
253
253
dims = deprecated_dims (dims)
@@ -266,13 +266,13 @@ function pairwise!(r::AbstractMatrix, metric::PreMetric,
266
266
size (r) == (na, nb) ||
267
267
throw (DimensionMismatch (" Incorrect size of r (got $(size (r)) , expected $((na, nb)) )." ))
268
268
if dims == 1
269
- _pairwise! (r, metric , permutedims (a), permutedims (b))
269
+ _pairwise! (metric, r , permutedims (a), permutedims (b))
270
270
else
271
- _pairwise! (r, metric , a, b)
271
+ _pairwise! (metric, r , a, b)
272
272
end
273
273
end
274
274
275
- function pairwise! (r :: AbstractMatrix , metric :: PreMetric , a:: AbstractMatrix ;
275
+ function pairwise! (metric :: PreMetric , r :: AbstractMatrix , a:: AbstractMatrix ;
276
276
dims:: Union{Nothing,Integer} = nothing )
277
277
dims = deprecated_dims (dims)
278
278
dims in (1 , 2 ) || throw (ArgumentError (" dims should be 1 or 2 (got $dims )" ))
@@ -284,23 +284,23 @@ function pairwise!(r::AbstractMatrix, metric::PreMetric, a::AbstractMatrix;
284
284
size (r) == (n, n) ||
285
285
throw (DimensionMismatch (" Incorrect size of r (got $(size (r)) , expected $((n, n)) )." ))
286
286
if dims == 1
287
- _pairwise! (r, metric , permutedims (a))
287
+ _pairwise! (metric, r , permutedims (a))
288
288
else
289
- _pairwise! (r, metric , a)
289
+ _pairwise! (metric, r , a)
290
290
end
291
291
end
292
292
293
293
"""
294
- pairwise!(r::AbstractMatrix, metric::PreMetric , a, b=a)
294
+ pairwise!(metric::PreMetric, r::AbstractMatrix , a, b=a)
295
295
296
296
Compute distances between each element of collection `a` and each element of
297
297
collection `b` according to distance `metric`, and store the result in `r`.
298
298
If a single iterable `a` is provided, compute distances between its elements.
299
299
300
300
`r` must be a matrix with size `length(a) × length(b)`.
301
301
"""
302
- pairwise! (r :: AbstractMatrix , metric :: PreMetric , a, b) = _pairwise! (r, metric , a, b)
303
- pairwise! (r :: AbstractMatrix , metric :: PreMetric , a) = _pairwise! (r, metric , a)
302
+ pairwise! (metric :: PreMetric , r :: AbstractMatrix , a, b) = _pairwise! (metric, r , a, b)
303
+ pairwise! (metric :: PreMetric , r :: AbstractMatrix , a) = _pairwise! (metric, r , a)
304
304
305
305
"""
306
306
pairwise(metric::PreMetric, a::AbstractMatrix, b::AbstractMatrix=a; dims)
@@ -318,7 +318,7 @@ function pairwise(metric::PreMetric, a::AbstractMatrix, b::AbstractMatrix;
318
318
m = size (a, dims)
319
319
n = size (b, dims)
320
320
r = Matrix {result_type(metric, a, b)} (undef, m, n)
321
- pairwise! (r, metric , a, b, dims= dims)
321
+ pairwise! (metric, r , a, b, dims= dims)
322
322
end
323
323
324
324
function pairwise (metric:: PreMetric , a:: AbstractMatrix ;
@@ -327,7 +327,7 @@ function pairwise(metric::PreMetric, a::AbstractMatrix;
327
327
dims in (1 , 2 ) || throw (ArgumentError (" dims should be 1 or 2 (got $dims )" ))
328
328
n = size (a, dims)
329
329
r = Matrix {result_type(metric, a, a)} (undef, n, n)
330
- pairwise! (r, metric , a, dims= dims)
330
+ pairwise! (metric, r , a, dims= dims)
331
331
end
332
332
333
333
"""
@@ -341,11 +341,11 @@ function pairwise(metric::PreMetric, a, b)
341
341
m = length (a)
342
342
n = length (b)
343
343
r = Matrix {result_type(metric, a, b)} (undef, m, n)
344
- _pairwise! (r, metric , a, b)
344
+ _pairwise! (metric, r , a, b)
345
345
end
346
346
347
347
function pairwise (metric:: PreMetric , a)
348
348
n = length (a)
349
349
r = Matrix {result_type(metric, a, a)} (undef, n, n)
350
- _pairwise! (r, metric , a)
350
+ _pairwise! (metric, r , a)
351
351
end
0 commit comments