Skip to content

Commit 3747ef8

Browse files
authored
add a code quoting to a word and remove double quotes
1 parent f69f788 commit 3747ef8

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ This package also provides optimized functions to compute column-wise and pairwi
3939
* Bray-Curtis dissimilarity
4040
* Bregman divergence
4141

42-
For ``Euclidean distance``, ``Squared Euclidean distance``, ``Cityblock distance``, ``Minkowski distance``, and ``Hamming distance``, a weighted version is also provided.
42+
For `Euclidean distance`, `Squared Euclidean distance`, `Cityblock distance`, `Minkowski distance`, and `Hamming distance`, a weighted version is also provided.
4343

4444

4545
## Basic use
@@ -55,7 +55,7 @@ r = evaluate(dist, x, y)
5555
r = dist(x, y)
5656
```
5757

58-
Here, dist is an instance of a distance type. For example, the type for Euclidean distance is ``Euclidean`` (more distance types will be introduced in the next section), then you can compute the Euclidean distance between ``x`` and ``y`` as
58+
Here, `dist` is an instance of a distance type. For example, the type for Euclidean distance is `Euclidean` (more distance types will be introduced in the next section), then you can compute the Euclidean distance between `x` and `y` as
5959

6060
```julia
6161
r = evaluate(Euclidean(), x, y)
@@ -70,57 +70,57 @@ r = euclidean(x, y)
7070

7171
#### Computing distances between corresponding columns
7272

73-
Suppose you have two ``m-by-n`` matrix ``X`` and ``Y``, then you can compute all distances between corresponding columns of ``X`` and ``Y`` in one batch, using the ``colwise`` function, as
73+
Suppose you have two `m-by-n` matrix `X` and `Y`, then you can compute all distances between corresponding columns of `X` and `Y` in one batch, using the `colwise` function, as
7474

7575
```julia
7676
r = colwise(dist, X, Y)
7777
```
7878

79-
The output ``r`` is a vector of length ``n``. In particular, ``r[i]`` is the distance between ``X[:,i]`` and ``Y[:,i]``. The batch computation typically runs considerably faster than calling ``evaluate`` column-by-column.
79+
The output `r` is a vector of length `n`. In particular, `r[i]` is the distance between `X[:,i]` and `Y[:,i]`. The batch computation typically runs considerably faster than calling `evaluate` column-by-column.
8080

81-
Note that either of ``X`` and ``Y`` can be just a single vector -- then the ``colwise`` function will compute the distance between this vector and each column of the other parameter.
81+
Note that either of `X` and `Y` can be just a single vector -- then the `colwise` function will compute the distance between this vector and each column of the other parameter.
8282

8383
#### Computing pairwise distances
8484

85-
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``:
85+
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`:
8686

8787
```julia
8888
R = pairwise(dist, X, Y, dims=2)
8989
```
9090

91-
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.
91+
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.
9292

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

9595
```julia
9696
R = pairwise(dist, X, dims=2)
9797
```
9898

99-
This statement will result in an ``m-by-m`` matrix, where ``R[i,j]`` is the distance between ``X[:,i]`` and ``X[:,j]``.
100-
``pairwise(dist, X)`` is typically more efficient than ``pairwise(dist, X, X)``, as the former will take advantage of the symmetry when ``dist`` is a semi-metric (including metric).
99+
This statement will result in an `m-by-m` matrix, where `R[i,j]` is the distance between `X[:,i]` and `X[:,j]`.
100+
`pairwise(dist, X)` is typically more efficient than `pairwise(dist, X, X)`, as the former will take advantage of the symmetry when `dist` is a semi-metric (including metric).
101101

102102
For performance reasons, it is recommended to use matrices with observations in columns (as shown above). Indeed,
103-
the ``Array`` type in Julia is column-major, making it more efficient to access memory column by column. However,
104-
matrices with observations stored in rows are also supported via the argument ``dims=1``.
103+
the `Array` type in Julia is column-major, making it more efficient to access memory column by column. However,
104+
matrices with observations stored in rows are also supported via the argument `dims=1`.
105105

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

108-
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``):
108+
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`):
109109

110110
```julia
111111
colwise!(r, dist, X, Y)
112112
pairwise!(R, dist, X, Y, dims=i)
113113
pairwise!(R, dist, X, dims=i)
114114
```
115115

116-
Please pay attention to the difference, the functions for inplace computation are ``colwise!`` and ``pairwise!`` (instead of ``colwise`` and ``pairwise``).
116+
Please pay attention to the difference, the functions for inplace computation are `colwise!` and `pairwise!` (instead of `colwise` and `pairwise`).
117117

118118

119119
## Distance type hierarchy
120120

121121
The distances are organized into a type hierarchy.
122122

123-
At the top of this hierarchy is an abstract class **PreMetric**, which is defined to be a function ``d`` that satisfies
123+
At the top of this hierarchy is an abstract class **PreMetric**, which is defined to be a function `d` that satisfies
124124

125125
d(x, x) == 0 for all x
126126
d(x, y) >= 0 for all x, y
@@ -214,7 +214,7 @@ The tables below can be replicated using the script in `benchmark/print_table.jl
214214

215215
#### Column-wise benchmark
216216

217-
The table below compares the performance (measured in terms of average elapsed time of each iteration) of a straightforward loop implementation and an optimized implementation provided in *Distances.jl*. The task in each iteration is to compute a specific distance between corresponding columns in two ``200-by-10000`` matrices.
217+
The table below compares the performance (measured in terms of average elapsed time of each iteration) of a straightforward loop implementation and an optimized implementation provided in *Distances.jl*. The task in each iteration is to compute a specific distance between corresponding columns in two `200-by-10000` matrices.
218218

219219
| distance | loop | colwise | gain |
220220
|----------- | -------| ----------| -------|
@@ -244,11 +244,11 @@ The table below compares the performance (measured in terms of average elapsed t
244244
| Mahalanobis | 0.082180s | 0.019618s | 4.1891 |
245245
| BrayCurtis | 0.004464s | 0.001121s | 3.9809 |
246246

247-
We can see that using ``colwise`` instead of a simple loop yields considerable gain (2x - 4x), especially when the internal computation of each distance is simple. Nonetheless, when the computation of a single distance is heavy enough (e.g. *KLDivergence*, *RenyiDivergence*), the gain is not as significant.
247+
We can see that using `colwise` instead of a simple loop yields considerable gain (2x - 4x), especially when the internal computation of each distance is simple. Nonetheless, when the computation of a single distance is heavy enough (e.g. *KLDivergence*, *RenyiDivergence*), the gain is not as significant.
248248

249249
#### Pairwise benchmark
250250

251-
The table below compares the performance (measured in terms of average elapsed time of each iteration) of a straightforward loop implementation and an optimized implementation provided in *Distances.jl*. The task in each iteration is to compute a specific distance in a pairwise manner between columns in a ``100-by-200`` and ``100-by-250`` matrices, which will result in a ``200-by-250`` distance matrix.
251+
The table below compares the performance (measured in terms of average elapsed time of each iteration) of a straightforward loop implementation and an optimized implementation provided in *Distances.jl*. The task in each iteration is to compute a specific distance in a pairwise manner between columns in a `100-by-200` and `100-by-250` matrices, which will result in a `200-by-250` distance matrix.
252252

253253
| distance | loop | pairwise | gain |
254254
|----------- | -------| ----------| -------|
@@ -278,4 +278,4 @@ The table below compares the performance (measured in terms of average elapsed t
278278
| Mahalanobis | 0.197294s | 0.000420s | **470.2354** |
279279
| BrayCurtis | 0.012872s | 0.001489s | 8.6456 |
280280

281-
For distances of which a major part of the computation is a quadratic form (e.g. *Euclidean*, *CosineDist*, *Mahalanobis*), the performance can be drastically improved by restructuring the computation and delegating the core part to ``GEMM`` in *BLAS*. The use of this strategy can easily lead to 100x performance gain over simple loops (see the highlighted part of the table above).
281+
For distances of which a major part of the computation is a quadratic form (e.g. *Euclidean*, *CosineDist*, *Mahalanobis*), the performance can be drastically improved by restructuring the computation and delegating the core part to `GEMM` in *BLAS*. The use of this strategy can easily lead to 100x performance gain over simple loops (see the highlighted part of the table above).

0 commit comments

Comments
 (0)