Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Nov 1, 2023
1 parent 0b78015 commit b0dce01
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 298 deletions.
1 change: 1 addition & 0 deletions .github/.keepalive
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023-11-01T04:33:17.905Z
12 changes: 10 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ jobs:
fi
# Trim leading and trailing whitespace:
dep=$(echo "$dep" | xargs)
version="^$(npm view $dep version)"
version="$(npm view $dep version)"
if [[ -z "$version" ]]; then
continue
fi
version="^$version"
jq -r --arg dep "$dep" --arg version "$version" '.dependencies[$dep] = $version' package.json > package.json.tmp
mv package.json.tmp package.json
done
Expand All @@ -192,7 +196,11 @@ jobs:
fi
# Trim leading and trailing whitespace:
dep=$(echo "$dep" | xargs)
version="^$(npm view $dep version)"
version="$(npm view $dep version)"
if [[ -z "$version" ]]; then
continue
fi
version="^$version"
jq -r --arg dep "$dep" --arg version "$version" '.devDependencies[$dep] = $version' package.json > package.json.tmp
mv package.json.tmp package.json
done
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ Stephannie Jiménez Gacha <[email protected]>
Yernar Yergaziyev <[email protected]>
orimiles5 <[email protected]>
rei2hu <[email protected]>
Robert Gislason <[email protected]>
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
"@stdlib/types": "^0.1.0"
},
"devDependencies": {
"@stdlib/array-float32": "^0.1.0",
"@stdlib/array-float64": "^0.1.0",
"@stdlib/array-float32": "^0.1.1",
"@stdlib/array-float64": "^0.1.1",
"@stdlib/bench": "^0.1.0",
"@stdlib/math-base-assert-is-nan": "^0.1.1",
"@stdlib/math-base-special-pow": "^0.1.0",
Expand Down
298 changes: 4 additions & 294 deletions test/dist/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2020 The Stdlib Authors.
* Copyright (c) 2023 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,303 +21,13 @@
// MODULES //

var tape = require( 'tape' );
var Float64Array = require( '@stdlib/array-float64' );
var Float32Array = require( '@stdlib/array-float32' );
var array = require( '@stdlib/ndarray-array' );
var ndarray = require( '@stdlib/ndarray-ctor' );
var ddot = require( './../../dist' );
var main = require( './../../dist' );


// TESTS //

tape( 'main export is a function', function test( t ) {
tape( 'main export is defined', function test( t ) {
t.ok( true, __filename );
t.strictEqual( typeof ddot, 'function', 'main export is a function' );
t.end();
});

tape( 'the function has an arity of 2', function test( t ) {
t.strictEqual( ddot.length, 2, 'has expected arity' );
t.end();
});

tape( 'the function throws an error if provided a first argument which is not a 1-dimensional ndarray containing double-precision floating-point numbers', function test( t ) {
var values;
var i;

values = [
5,
'5',
true,
false,
null,
void 0,
{},
[],
function noop() {},
array( new Float32Array( 10 ) )
];

for ( i = 0; i < values.length; i++ ) {
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
}
t.end();

function badValue( value ) {
var y = array( new Float64Array( 10 ) );

return function badValue() {
ddot( value, y );
};
}
});

tape( 'the function throws an error if provided a second argument which is not a 1-dimensional ndarray containing double-precision floating-point numbers', function test( t ) {
var values;
var i;

values = [
5,
'5',
true,
false,
null,
void 0,
{},
[],
function noop() {},
array( new Float32Array( 10 ) )
];

for ( i = 0; i < values.length; i++ ) {
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
}
t.end();

function badValue( value ) {
var x = array( new Float64Array( 10 ) );

return function badValue() {
ddot( x, value );
};
}
});

tape( 'the function throws an error if provided unequal length vectors', function test( t ) {
t.throws( badValue, RangeError, 'throws an error' );
t.end();

function badValue() {
var x = array( new Float64Array( 10 ) );
var y = array( new Float64Array( 100 ) );
ddot( x, y );
}
});
tape( 'the function calculates the dot product of vectors `x` and `y`', function test( t ) {
var dot;
var x;
var y;

x = new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 2.0, -5.0, 6.0 ] );
y = new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 8.0, 2.0, -3.0 ] );

x = array( x );
y = array( y );

dot = ddot( x, y );
t.strictEqual( dot, -17.0, 'returns expected value' );

t.end();
});

tape( 'if provided empty vectors, the function returns `0`', function test( t ) {
var dot;
var x;
var y;

x = new Float64Array();
y = new Float64Array();

x = array( x );
y = array( y );

dot = ddot( x, y );
t.strictEqual( dot, 0.0, 'returns expected value' );

t.end();
});

tape( 'the function supports a strided vector for the first argument', function test( t ) {
var dot;
var x;
var y;

x = new Float64Array([
2.0, // 0
-3.0,
-5.0, // 1
7.0,
6.0 // 2
]);
y = new Float64Array([
8.0, // 0
2.0, // 1
-3.0 // 2
]);

x = ndarray( 'float64', x, [ 3 ], [ 2 ], 0, 'row-major' );
y = ndarray( 'float64', y, [ 3 ], [ 1 ], 0, 'row-major' );

dot = ddot( x, y );
t.strictEqual( dot, -12.0, 'returns expected value' );

t.end();
});

tape( 'the function supports a strided vector for the second argument', function test( t ) {
var dot;
var x;
var y;

x = new Float64Array([
2.0, // 0
-3.0, // 1
-5.0 // 2
]);
y = new Float64Array([
8.0, // 0
2.0,
-3.0, // 1
3.0,
-4.0, // 2
1.0
]);

x = ndarray( 'float64', x, [ 3 ], [ 1 ], 0, 'row-major' );
y = ndarray( 'float64', y, [ 3 ], [ 2 ], 0, 'row-major' );

dot = ddot( x, y );
t.strictEqual( dot, 45.0, 'returns expected value' );

t.end();
});

tape( 'the function supports negative strides', function test( t ) {
var dot;
var x;
var y;

x = new Float64Array([
1.0, // 2
2.0,
3.0, // 1
4.0,
5.0 // 0
]);
y = new Float64Array([
6.0, // 2
7.0, // 1
8.0 // 0
]);

x = ndarray( 'float64', x, [ 3 ], [ -2 ], x.length-1, 'row-major' );
y = ndarray( 'float64', y, [ 3 ], [ -1 ], y.length-1, 'row-major' );

dot = ddot( x, y );
t.strictEqual( dot, 67.0, 'returns expected value' );

t.end();
});

tape( 'the function supports complex access patterns', function test( t ) {
var dot;
var x;
var y;

x = new Float64Array([
1.0, // 0
2.0,
3.0, // 1
4.0,
5.0 // 2
]);
y = new Float64Array([
6.0, // 2
7.0, // 1
8.0 // 0
]);

x = ndarray( 'float64', x, [ 3 ], [ 2 ], 0, 'row-major' );
y = ndarray( 'float64', y, [ 3 ], [ -1 ], y.length-1, 'row-major' );

dot = ddot( x, y );
t.strictEqual( dot, 59.0, 'returns expected value' );

t.end();
});

tape( 'the function supports strided vectors having offsets', function test( t ) {
var dot;
var x;
var y;

x = new Float64Array([
0.0,
2.0, // 0
-3.0,
-5.0, // 1
7.0,
6.0 // 2
]);
y = new Float64Array([
0.0,
0.0,
8.0, // 0
2.0, // 1
-3.0 // 2
]);

x = ndarray( 'float64', x, [ 3 ], [ 2 ], 1, 'row-major' );
y = ndarray( 'float64', y, [ 3 ], [ 1 ], 2, 'row-major' );

dot = ddot( x, y );
t.strictEqual( dot, -12.0, 'returns expected value' );

t.end();
});

tape( 'the function supports underlying data buffers with view offsets', function test( t ) {
var dot;
var x0;
var y0;
var x1;
var y1;

x0 = new Float64Array([
1.0,
2.0, // 0
3.0,
4.0, // 1
5.0,
6.0 // 2
]);
y0 = new Float64Array([
6.0,
7.0,
8.0,
9.0, // 0
10.0, // 1
11.0 // 2
]);

x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 );

x1 = ndarray( 'float64', x1, [ 3 ], [ 2 ], 0, 'row-major' );
y1 = ndarray( 'float64', y1, [ 3 ], [ 1 ], 0, 'row-major' );

dot = ddot( x1, y1 );
t.strictEqual( dot, 124.0, 'returns expected value' );

t.strictEqual( main !== void 0, true, 'main export is defined' );
t.end();
});

0 comments on commit b0dce01

Please sign in to comment.