Skip to content

Commit 74ce3de

Browse files
chore: update according to code review
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 4d1a80e commit 74ce3de

File tree

15 files changed

+58
-46
lines changed

15 files changed

+58
-46
lines changed

lib/node_modules/@stdlib/stats/strided/distances/dcosine-similarity/README.md

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,27 @@ limitations under the License.
1818
1919
-->
2020

21-
# dcosine-similarity
21+
# dcosineSimilarity
2222

23-
> Computes the cosine similarity of two double-precision floating-point vectors.
23+
> Compute the cosine similarity of two double-precision floating-point strided arrays.
2424
2525
<section class="intro">
2626

27+
The [cosine similarity][wikipedia-cosine-similarity] is defined as
28+
29+
<!-- <equation class="equation" label="eq:cosine_similarity" align="center"
30+
raw="sim=\frac{A\cdot B}{\|A\|\|B\|} alt="Equation for cosine similarity."> -->
31+
32+
```math
33+
sim = \frac{A \cdot B}{\|A\| \, \|B\|}
34+
```
35+
36+
<!-- <div class="equation" align="center" data-raw-text="sim=\frac{A\cdot B}{\|A\|\|B\|} data-equation="eq:cosine_similarity"> <img src="" alt="Cosine similarity equation."> <br>
37+
38+
</div> -->
39+
40+
<!-- </equation> -->
41+
2742
</section>
2843

2944
<!-- /.intro -->
@@ -38,7 +53,7 @@ var dcosineSimilarity = require( '@stdlib/stats/strided/distances/dcosine-simila
3853

3954
#### dcosineSimilarity( N, x, strideX, y, strideY )
4055

41-
Calculates the cosine similarity of vectors `x` and `y`.
56+
Computes the cosine similarity of two double-precision floating-point strided arrays.
4257

4358
```javascript
4459
var Float64Array = require( '@stdlib/array/float64' );
@@ -58,7 +73,7 @@ The function has the following parameters:
5873
- **y**: input [`Float64Array`][@stdlib/array/float64].
5974
- **strideY**: stride length of `y`.
6075

61-
The `N` and strides parameters determine which elements in the strided arrays are accessed at runtime. For example, to calculate the cosine similarity of every other value in `x` and the first `N` elements of `y` in reverse order,
76+
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to calculate the cosine similarity of every other value in `x` and the first `N` elements of `y` in reverse order,
6277

6378
```javascript
6479
var Float64Array = require( '@stdlib/array/float64' );
@@ -91,7 +106,7 @@ var z = dcosineSimilarity( 3, x1, 1, y1, 1 );
91106

92107
#### dcosineSimilarity.ndarray( N, x, strideX, offsetX, y, strideY, offsetY )
93108

94-
Calculates the cosine similarity of `x` and `y` using alternative indexing semantics.
109+
Computes the cosine similarity of two double-precision floating-point strided arrays using alternative indexing semantics.
95110

96111
```javascript
97112
var Float64Array = require( '@stdlib/array/float64' );
@@ -189,7 +204,7 @@ console.log( out );
189204

190205
#### stdlib_strided_dcosine_similarity( N, \*X, strideX, \*Y, strideY )
191206

192-
Computes the cosine similarity of two double-precision floating-point vectors.
207+
Computes the cosine similarity of two double-precision floating-point strided arrays.
193208

194209
```c
195210
const double x[] = { 4.0, 2.0, -3.0, 5.0, -1.0 };
@@ -211,13 +226,13 @@ The function accepts the following arguments:
211226
double stdlib_strided_dcosine_similarity( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY );
212227
```
213228

214-
<!--lint ignore maximum-heading-length-->
229+
<!--lint disable maximum-heading-length-->
215230

216231
#### stdlib_strided_dcosine_similarity_ndarray( N, \*X, strideX, offsetX, \*Y, strideY, offsetY )
217232

218-
<!--lint ignore maximum-heading-length-->
233+
<!--lint enable maximum-heading-length-->
219234

220-
Computes the cosine similarity of two double-precision floating-point vectors using alternative indexing semantics.
235+
Computes the cosine similarity of two double-precision floating-point strided arrays using alternative indexing semantics.
221236

222237
```c
223238
const double x[] = { 4.0, 2.0, -3.0, 5.0, -1.0 };
@@ -313,6 +328,8 @@ int main( void ) {
313328
314329
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
315330
331+
[wikipedia-cosine-similarity]: https://en.wikipedia.org/wiki/Cosine_similarity
332+
316333
<!-- <related-links> -->
317334
318335
<!-- </related-links> -->

lib/node_modules/@stdlib/stats/strided/distances/dcosine-similarity/docs/repl.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
{{alias}}( N, x, strideX, y, strideY )
33
Computes the cosine similarity of two double-precision
4-
floating-point vectors.
4+
floating-point strided arrays.
55

66
The `N` and stride parameters determine which elements in the strided arrays
77
are accessed at runtime.
@@ -58,7 +58,7 @@
5858

5959
{{alias}}.ndarray( N, x, strideX, offsetX, y, strideY, offsetY )
6060
Computes the cosine similarity of two double-precision
61-
floating-point vectors using alternative indexing semantics.
61+
floating-point strided arrays using alternative indexing semantics.
6262

6363
While typed array views mandate a view offset based on the underlying
6464
buffer, the offset parameters support indexing based on a starting index.

lib/node_modules/@stdlib/stats/strided/distances/dcosine-similarity/docs/types/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424
interface Routine {
2525
/**
26-
* Computes the cosine similarity of two double-precision floating-point vectors.
26+
* Computes the cosine similarity of two double-precision floating-point strided arrays.
2727
*
2828
* @param N - number of indexed elements
2929
* @param x - first input array
@@ -44,7 +44,7 @@ interface Routine {
4444
( N: number, x: Float64Array, strideX: number, y: Float64Array, strideY: number ): number;
4545

4646
/**
47-
* Computes the cosine similarity of two double-precision floating-point vectors using alternative indexing semantics.
47+
* Computes the cosine similarity of two double-precision floating-point strided arrays using alternative indexing semantics.
4848
*
4949
* @param N - number of indexed elements
5050
* @param x - first input array
@@ -68,7 +68,7 @@ interface Routine {
6868
}
6969

7070
/**
71-
* Computes the cosine similarity of two double-precision floating-point vectors.
71+
* Computes the cosine similarity of two double-precision floating-point strided arrays.
7272
*
7373
* @param N - number of indexed elements
7474
* @param x - first input array

lib/node_modules/@stdlib/stats/strided/distances/dcosine-similarity/include/stdlib/stats/strided/distances/dcosine_similarity.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* limitations under the License.
1717
*/
1818

19-
#ifndef STDLIB_STATS_STRIDED_DCOSINE_SIMILARITY_H
20-
#define STDLIB_STATS_STRIDED_DCOSINE_SIMILARITY_H
19+
#ifndef STDLIB_STATS_STRIDED_DISTANCES_DCOSINE_SIMILARITY_H
20+
#define STDLIB_STATS_STRIDED_DISTANCES_DCOSINE_SIMILARITY_H
2121

2222
#include "stdlib/blas/base/shared.h"
2323

@@ -29,17 +29,17 @@ extern "C" {
2929
#endif
3030

3131
/**
32-
* Computes the cosine similarity of two double-precision floating-point vectors.
32+
* Computes the cosine similarity of two double-precision floating-point strided arrays.
3333
*/
3434
double API_SUFFIX( stdlib_strided_dcosine_similarity )( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY );
3535

3636
/**
37-
* Computes the cosine similarity of two double-precision floating-point vectors using alternative indexing semantics.
37+
* Computes the cosine similarity of two double-precision floating-point strided arrays using alternative indexing semantics.
3838
*/
3939
double API_SUFFIX( stdlib_strided_dcosine_similarity_ndarray )( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY );
4040

4141
#ifdef __cplusplus
4242
}
4343
#endif
4444

45-
#endif // !STDLIB_STATS_STRIDED_DCOSINE_SIMILARITY_H
45+
#endif // !STDLIB_STATS_STRIDED_DISTANCES_DCOSINE_SIMILARITY_H

lib/node_modules/@stdlib/stats/strided/distances/dcosine-similarity/lib/dcosine_similarity.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ var ndarray = require( './ndarray.js' );
2727
// MAIN //
2828

2929
/**
30-
* Computes the cosine similarity of two double-precision floating-point vectors.
30+
* Computes the cosine similarity of two double-precision floating-point strided arrays.
3131
*
32-
* @param {integer} N - number of indexed elements
32+
* @param {NonNegativeInteger} N - number of indexed elements
3333
* @param {Float64Array} x - first input array
3434
* @param {integer} strideX - stride length of `x`
3535
* @param {Float64Array} y - second input array

lib/node_modules/@stdlib/stats/strided/distances/dcosine-similarity/lib/dcosine_similarity.native.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ var addon = require( './../src/addon.node' );
2626
// MAIN //
2727

2828
/**
29-
* Computes the cosine similarity of two double-precision floating-point vectors.
29+
* Computes the cosine similarity of two double-precision floating-point strided arrays.
3030
*
31-
* @param {integer} N - number of indexed elements
31+
* @param {NonNegativeInteger} N - number of indexed elements
3232
* @param {Float64Array} x - first input array
3333
* @param {integer} strideX - stride length of `x`
3434
* @param {Float64Array} y - second input array

lib/node_modules/@stdlib/stats/strided/distances/dcosine-similarity/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'use strict';
2020

2121
/**
22-
* Compute the cosine similarity of two double-precision floating-point vectors.
22+
* Compute the cosine similarity of two double-precision floating-point strided arrays.
2323
*
2424
* @module @stdlib/stats/strided/distances/dcosine-similarity
2525
*

lib/node_modules/@stdlib/stats/strided/distances/dcosine-similarity/lib/ndarray.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ var dnrm2 = require( '@stdlib/blas/base/dnrm2' ).ndarray;
2727
// MAIN //
2828

2929
/**
30-
* Computes the cosine similarity of two double-precision floating-point vectors using alternative indexing semantics.
30+
* Computes the cosine similarity of two double-precision floating-point strided arrays using alternative indexing semantics.
3131
*
32-
* @param {integer} N - number of indexed elements
32+
* @param {NonNegativeInteger} N - number of indexed elements
3333
* @param {Float64Array} x - first input array
3434
* @param {integer} strideX - stride length of `x`
3535
* @param {NonNegativeInteger} offsetX - starting index for `x`
@@ -50,18 +50,15 @@ var dnrm2 = require( '@stdlib/blas/base/dnrm2' ).ndarray;
5050
function dcosineSimilarity( N, x, strideX, offsetX, y, strideY, offsetY ) {
5151
var ynrm;
5252
var xnrm;
53-
var num;
54-
var den;
53+
var dot;
5554

5655
if (N <= 0) {
5756
return 0.0;
5857
}
59-
60-
num = ddot( N, x, strideX, offsetX, y, strideY, offsetY );
58+
dot = ddot( N, x, strideX, offsetX, y, strideY, offsetY );
6159
xnrm = dnrm2( N, x, strideX, offsetX );
6260
ynrm = dnrm2( N, y, strideY, offsetY );
63-
den = xnrm * ynrm;
64-
return num / den;
61+
return dot / ( xnrm * ynrm );
6562
}
6663

6764

lib/node_modules/@stdlib/stats/strided/distances/dcosine-similarity/lib/ndarray.native.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ var addon = require( './../src/addon.node' );
2626
// MAIN //
2727

2828
/**
29-
* Computes the cosine similarity of two double-precision floating-point vectors using alternative indexing semantics.
29+
* Computes the cosine similarity of two double-precision floating-point strided arrays using alternative indexing semantics.
3030
*
31-
* @param {integer} N - number of indexed elements
31+
* @param {NonNegativeInteger} N - number of indexed elements
3232
* @param {Float64Array} x - first input array
3333
* @param {integer} strideX - stride length of `x`
3434
* @param {NonNegativeInteger} offsetX - starting index for `x`

lib/node_modules/@stdlib/stats/strided/distances/dcosine-similarity/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@stdlib/stats/strided/distances/dcosine-similarity",
33
"version": "0.0.0",
4-
"description": "Computes the cosine similarity of two double-precision floating-point vectors.",
4+
"description": "Compute the cosine similarity of two double-precision floating-point strided arrays.",
55
"license": "Apache-2.0",
66
"author": {
77
"name": "The Stdlib Authors",

0 commit comments

Comments
 (0)