Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ var z = dcosineSimilarity.ndarray( 3, x, 2, 1, y, -1, y.length-1 );

## Notes

- If `N <= 0`, both functions return `0.0`.
- If `N <= 0`, both functions return `NaN`.

</section>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Indexing is relative to the first index. To introduce an offset, use a typed
array view.

If `N <= 0`, the function returns `0`.
If `N <= 0`, the function returns `NaN`.

Parameters
----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function dcosineSimilarity( N, x, strideX, offsetX, y, strideY, offsetY ) {
var dot;

if ( N <= 0 ) {
return 0.0;
return NaN;
}
dot = ddot( N, x, strideX, offsetX, y, strideY, offsetY );
xnrm = dnrm2( N, x, strideX, offsetX );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ double API_SUFFIX( stdlib_strided_dcosine_similarity_ndarray )( const CBLAS_INT
double dot;

if ( N <= 0 ) {
return 0.0;
return 0.0 / 0.0;
}
dot = c_ddot_ndarray( N, X, strideX, offsetX, Y, strideY, offsetY );
xnrm = c_dnrm2_ndarray( N, X, strideX, offsetX );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ tape( 'the function calculates the cosine similarity of two strided arrays', fun
t.end();
});

tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `0`', function test( t ) {
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) {
var sim;
var x;
var y;
Expand All @@ -70,10 +70,10 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu
y = new Float64Array( [ 1.0, -2.0, 3.0 ] );

sim = dcosineSimilarity( 0, x, 1, y, 1 );
t.strictEqual( isAlmostSameValue( sim, 0.0, 1 ), true, 'returns expected value' );
t.strictEqual( isAlmostSameValue( sim, NaN, 1 ), true, 'returns expected value' );

sim = dcosineSimilarity( -4, x, 1, y, 1 );
t.strictEqual( isAlmostSameValue( sim, 0.0, 1 ), true, 'returns expected value' );
t.strictEqual( isAlmostSameValue( sim, NaN, 1 ), true, 'returns expected value' );
t.end();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ tape( 'the function calculates the cosine similarity of two strided arrays', opt
t.end();
});

tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `0`', opts, function test( t ) {
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', opts, function test( t ) {
var sim;
var x;
var y;
Expand All @@ -80,11 +80,11 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu

// Test against textbook algorithm for computing cosine similarity:
sim = dcosineSimilarity( 0, x, 1, y, 1 );
t.strictEqual( isAlmostSameValue( sim, 0.0, 1 ), true, 'returns expected value' );
t.strictEqual( isAlmostSameValue( sim, NaN, 1 ), true, 'returns expected value' );

// Test against textbook algorithm for computing cosine similarity:
sim = dcosineSimilarity( -4, x, 1, y, 1 );
t.strictEqual( isAlmostSameValue( sim, 0.0, 1 ), true, 'returns expected value' );
t.strictEqual( isAlmostSameValue( sim, NaN, 1 ), true, 'returns expected value' );
t.end();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ tape( 'the function calculates the cosine similarity of two strided arrays', fun
t.end();
});

tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `0`', function test( t ) {
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) {
var sim;
var x;
var y;
Expand All @@ -71,11 +71,11 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu

// Test against textbook algorithm for computing cosine similarity:
sim = dcosineSimilarity( 0, x, 1, 0, y, 1, 0 );
t.strictEqual( isAlmostSameValue( sim, 0.0, 1 ), true, 'returns expected value' );
t.strictEqual( isAlmostSameValue( sim, NaN, 1 ), true, 'returns expected value' );

// Test against textbook algorithm for computing cosine similarity:
sim = dcosineSimilarity( -4, x, 1, 0, y, 1, 0 );
t.strictEqual( isAlmostSameValue( sim, 0.0, 1 ), true, 'returns expected value' );
t.strictEqual( isAlmostSameValue( sim, NaN, 1 ), true, 'returns expected value' );
t.end();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ tape( 'the function calculates the cosine similarity of two strided arrays', opt
t.end();
});

tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `0`', opts, function test( t ) {
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', opts, function test( t ) {
var sim;
var x;
var y;
Expand All @@ -80,11 +80,11 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu

// Test against textbook algorithm for computing cosine similarity:
sim = dcosineSimilarity( 0, x, 1, 0, y, 1, 0 );
t.strictEqual( isAlmostSameValue( sim, 0.0, 1 ), true, 'returns expected value' );
t.strictEqual( isAlmostSameValue( sim, NaN, 1 ), true, 'returns expected value' );

// Test against textbook algorithm for computing cosine similarity:
sim = dcosineSimilarity( -4, x, 1, 0, y, 1, 0 );
t.strictEqual( isAlmostSameValue( sim, 0.0, 1 ), true, 'returns expected value' );
t.strictEqual( isAlmostSameValue( sim, NaN, 1 ), true, 'returns expected value' );
t.end();
});

Expand Down