Skip to content

Commit

Permalink
remove deprecation of not giving dims
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Oct 2, 2019
1 parent 7f3a28c commit e1e893b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,18 @@ Note that either of `X` and `Y` can be just a single vector -- then the `colwise

#### Computing pairwise distances

Let `X` and `Y` respectively have `m` and `n` columns. Then the `pairwise` function with the `dims=2` argument computes distances between each pair of columns in `X` and `Y`:
Let `X` and `Y` respectively have `m` and `n` columns. Then the `pairwise` function argument computes distances between each pair of columns in `X` and `Y`:

```julia
R = pairwise(dist, X, Y, dims=2)
R = pairwise(dist, X, Y)
```

In the output, `R` is a matrix of size `(m, n)`, such that `R[i,j]` is the distance between `X[:,i]` and `Y[:,j]`. Computing distances for all pairs using `pairwise` function is often remarkably faster than evaluting for each pair individually.

If you just want to just compute distances between columns of a matrix `X`, you can write

```julia
R = pairwise(dist, X, dims=2)
R = pairwise(dist, X)
```

This statement will result in an `m-by-m` matrix, where `R[i,j]` is the distance between `X[:,i]` and `X[:,j]`.
Expand All @@ -105,12 +105,12 @@ matrices with observations stored in rows are also supported via the argument `d

#### Computing column-wise and pairwise distances inplace

If the vector/matrix to store the results are pre-allocated, you may use the storage (without creating a new array) using the following syntax (`i` being either `1` or `2`):
If the vector/matrix to store the results are pre-allocated, you may use the storage (without creating a new array) using the following syntax (`dims` being either `1` or `2`):

```julia
colwise!(r, dist, X, Y)
pairwise!(R, dist, X, Y, dims=i)
pairwise!(R, dist, X, dims=i)
pairwise!(R, dist, X, Y, dims=2)
pairwise!(R, dist, X, dims=2)
```

Please pay attention to the difference, the functions for inplace computation are `colwise!` and `pairwise!` (instead of `colwise` and `pairwise`).
Expand Down
23 changes: 4 additions & 19 deletions src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,6 @@ function _pairwise!(r::AbstractMatrix, metric::SemiMetric, a::AbstractMatrix)
r
end

function deprecated_dims(dims::Union{Nothing,Integer})
if dims === nothing
Base.depwarn("implicit `dims=2` argument now has to be passed explicitly " *
"to specify that distances between columns should be computed",
:pairwise!)
return 2
else
return dims
end
end

"""
pairwise!(r::AbstractMatrix, metric::PreMetric,
a::AbstractMatrix, b::AbstractMatrix=a; dims)
Expand All @@ -144,8 +133,7 @@ If a single matrix `a` is provided, compute distances between its rows or column
"""
function pairwise!(r::AbstractMatrix, metric::PreMetric,
a::AbstractMatrix, b::AbstractMatrix;
dims::Union{Nothing,Integer}=nothing)
dims = deprecated_dims(dims)
dims::Integer=2)
dims in (1, 2) || throw(ArgumentError("dims should be 1 or 2 (got $dims)"))
if dims == 1
na, ma = size(a)
Expand All @@ -168,8 +156,7 @@ function pairwise!(r::AbstractMatrix, metric::PreMetric,
end

function pairwise!(r::AbstractMatrix, metric::PreMetric, a::AbstractMatrix;
dims::Union{Nothing,Integer}=nothing)
dims = deprecated_dims(dims)
dims::Integer=2)
dims in (1, 2) || throw(ArgumentError("dims should be 1 or 2 (got $dims)"))
if dims == 1
n, m = size(a)
Expand All @@ -195,8 +182,7 @@ compute distances between its rows or columns.
`a` and `b` must have the same numbers of columns if `dims=1`, or of rows if `dims=2`.
"""
function pairwise(metric::PreMetric, a::AbstractMatrix, b::AbstractMatrix;
dims::Union{Nothing,Integer}=nothing)
dims = deprecated_dims(dims)
dims::Integer=2)
dims in (1, 2) || throw(ArgumentError("dims should be 1 or 2 (got $dims)"))
m = size(a, dims)
n = size(b, dims)
Expand All @@ -205,8 +191,7 @@ function pairwise(metric::PreMetric, a::AbstractMatrix, b::AbstractMatrix;
end

function pairwise(metric::PreMetric, a::AbstractMatrix;
dims::Union{Nothing,Integer}=nothing)
dims = deprecated_dims(dims)
dims::Integer=2)
dims in (1, 2) || throw(ArgumentError("dims should be 1 or 2 (got $dims)"))
n = size(a, dims)
r = Matrix{result_type(metric, a, a)}(undef, n, n)
Expand Down

0 comments on commit e1e893b

Please sign in to comment.