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 Dec 2, 2023
1 parent 8d54607 commit b0508d2
Show file tree
Hide file tree
Showing 27 changed files with 292 additions and 411 deletions.
41 changes: 12 additions & 29 deletions base/ddot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,15 @@ The function has the following parameters:
- **y**: input [`Float64Array`][@stdlib/array/float64].
- **strideY**: index increment for `y`.

The `N` and `stride` parameters determine which elements in `x` and `y` are accessed at runtime. For example, to calculate the dot product of every other value in `x` and the first `N` elements of `y` in reverse order,
The `N` and strides parameters determine which elements in the strided arrays are accessed at runtime. For example, to calculate the dot product of every other value in `x` and the first `N` elements of `y` in reverse order,

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var floor = require( '@stdlib/math/base/special/floor' );

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

var N = floor( x.length / 2 );

var z = ddot( N, x, 2, y, -1 );
var z = ddot( 3, x, 2, y, -1 );
// returns 9.0
```

Expand All @@ -94,7 +91,6 @@ Note that indexing is relative to the first index. To introduce an offset, use [

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var floor = require( '@stdlib/math/base/special/floor' );

// Initial arrays...
var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
Expand All @@ -104,9 +100,7 @@ var y0 = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element

var N = floor( x0.length / 2 );

var z = ddot( N, x1, -2, y1, 1 );
var z = ddot( 3, x1, -2, y1, 1 );
// returns 128.0
```

Expand All @@ -129,18 +123,15 @@ The function has the following additional parameters:
- **offsetX**: starting index for `x`.
- **offsetY**: starting index for `y`.

While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offsetX` and `offsetY` parameters support indexing semantics based on starting indices. For example, to calculate the dot product of every other value in `x` starting from the second value with the last 3 elements in `y` in reverse order
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the offset parameters support indexing semantics based on starting indices. For example, to calculate the dot product of every other value in `x` starting from the second value with the last 3 elements in `y` in reverse order

```javascript
var Float64Array = require( '@stdlib/array/float64' );
var floor = require( '@stdlib/math/base/special/floor' );

var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var y = new Float64Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );

var N = floor( x.length / 2 );

var z = ddot.ndarray( N, x, 2, 1, y, -1, y.length-1 );
var z = ddot.ndarray( 3, x, 2, 1, y, -1, y.length-1 );
// returns 128.0
```

Expand All @@ -166,26 +157,18 @@ var z = ddot.ndarray( N, x, 2, 1, y, -1, y.length-1 );
<!-- eslint no-undef: "error" -->

```javascript
var randu = require( '@stdlib/random/base/randu' );
var round = require( '@stdlib/math/base/special/round' );
var Float64Array = require( '@stdlib/array/float64' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var ddot = require( '@stdlib/blas/base/ddot' );

var x;
var y;
var i;

x = new Float64Array( 10 );
y = new Float64Array( 10 );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = round( randu() * 100.0 );
y[ i ] = round( randu() * 10.0 );
}
var x = filledarrayBy( 10, 'float64', discreteUniform( 0, 100 ) );
console.log( x );

var y = filledarrayBy( x.length, 'float64', discreteUniform( 0, 10 ) );
console.log( y );

var z = ddot( x.length, x, 1, y, -1 );
console.log( z );
var out = ddot.ndarray( x.length, x, 1, 0, y, -1, y.length-1 );
console.log( out );
```

</section>
Expand Down
21 changes: 9 additions & 12 deletions base/ddot/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float64Array = require( '@stdlib/array/float64' );
var pkg = require( './../package.json' ).name;
var ddot = require( './../lib/ddot.js' );


// VARIABLES //

var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //

/**
Expand All @@ -39,16 +44,8 @@ var ddot = require( './../lib/ddot.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var y;
var i;

x = new Float64Array( len );
y = new Float64Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
y[ i ] = ( randu()*20.0 ) - 10.0;
}
var x = filledarrayBy( len, 'float64', rand );
var y = filledarrayBy( len, 'float64', rand );
return benchmark;

function benchmark( b ) {
Expand Down
17 changes: 5 additions & 12 deletions base/ddot/benchmark/benchmark.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float64Array = require( '@stdlib/array/float64' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand All @@ -36,6 +36,7 @@ var ddot = tryRequire( resolve( __dirname, './../lib/ddot.native.js' ) );
var opts = {
'skip': ( ddot instanceof Error )
};
var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //
Expand All @@ -48,16 +49,8 @@ var opts = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var y;
var i;

x = new Float64Array( len );
y = new Float64Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
y[ i ] = ( randu()*20.0 ) - 10.0;
}
var x = filledarrayBy( len, 'float64', rand );
var y = filledarrayBy( len, 'float64', rand );
return benchmark;

function benchmark( b ) {
Expand Down
21 changes: 9 additions & 12 deletions base/ddot/benchmark/benchmark.ndarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float64Array = require( '@stdlib/array/float64' );
var pkg = require( './../package.json' ).name;
var ddot = require( './../lib/ndarray.js' );


// VARIABLES //

var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //

/**
Expand All @@ -39,16 +44,8 @@ var ddot = require( './../lib/ndarray.js' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var y;
var i;

x = new Float64Array( len );
y = new Float64Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
y[ i ] = ( randu()*20.0 ) - 10.0;
}
var x = filledarrayBy( len, 'float64', rand );
var y = filledarrayBy( len, 'float64', rand );
return benchmark;

function benchmark( b ) {
Expand Down
17 changes: 5 additions & 12 deletions base/ddot/benchmark/benchmark.ndarray.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

var resolve = require( 'path' ).resolve;
var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var uniform = require( '@stdlib/random/base/uniform' ).factory;
var filledarrayBy = require( '@stdlib/array/filled-by' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var Float64Array = require( '@stdlib/array/float64' );
var tryRequire = require( '@stdlib/utils/try-require' );
var pkg = require( './../package.json' ).name;

Expand All @@ -36,6 +36,7 @@ var ddot = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
var opts = {
'skip': ( ddot instanceof Error )
};
var rand = uniform( -100.0, 100.0 );


// FUNCTIONS //
Expand All @@ -48,16 +49,8 @@ var opts = {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x;
var y;
var i;

x = new Float64Array( len );
y = new Float64Array( len );
for ( i = 0; i < x.length; i++ ) {
x[ i ] = ( randu()*20.0 ) - 10.0;
y[ i ] = ( randu()*20.0 ) - 10.0;
}
var x = filledarrayBy( len, 'float64', rand );
var y = filledarrayBy( len, 'float64', rand );
return benchmark;

function benchmark( b ) {
Expand Down
34 changes: 15 additions & 19 deletions base/ddot/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
{{alias}}( N, x, strideX, y, strideY )
Computes the dot product of two double-precision floating-point vectors.

The `N`, `strideX`, and `strideY` parameters determine which elements in `x`
and `y` are accessed at runtime.
The `N` and stride parameters determine which elements in the strided arrays
are accessed at runtime.

Indexing is relative to the first index. To introduce an offset, use a typed
array view.

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

Parameters
----------
Expand All @@ -29,40 +29,38 @@

Returns
-------
dot: number
The dot product of `x` and `y`.
out: number
Dot product.

Examples
--------
// Standard usage:
> var x = new {{alias:@stdlib/array/float64}}( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] );
> var y = new {{alias:@stdlib/array/float64}}( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] );
> var dot = {{alias}}( x.length, x, 1, y, 1 )
> var out = {{alias}}( x.length, x, 1, y, 1 )
-5.0

// Strides:
> x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
> y = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> dot = {{alias}}( N, x, 2, y, -1 )
> out = {{alias}}( 3, x, 2, y, -1 )
9.0

// Using view offsets:
> x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
> y = new {{alias:@stdlib/array/float64}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
> var x1 = new {{alias:@stdlib/array/float64}}( x.buffer, x.BYTES_PER_ELEMENT*1 );
> var y1 = new {{alias:@stdlib/array/float64}}( y.buffer, y.BYTES_PER_ELEMENT*3 );
> N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> dot = {{alias}}( N, x1, -2, y1, 1 )
> out = {{alias}}( 3, x1, -2, y1, 1 )
128.0


{{alias}}.ndarray( N, x, strideX, offsetX, y, strideY, offsetY )
Computes the dot product of two double-precision floating-point vectors
using alternative indexing semantics.

While typed array views mandate a view offset based on the underlying
buffer, the `offsetX` and `offsetY` parameters support indexing based on a
starting index.
buffer, the offset parameters support indexing based on a starting index.

Parameters
----------
Expand All @@ -89,29 +87,27 @@

Returns
-------
dot: number
The dot product of `x` and `y`.
out: number
Dot product.

Examples
--------
// Standard usage:
> var x = new {{alias:@stdlib/array/float64}}( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] );
> var y = new {{alias:@stdlib/array/float64}}( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] );
> var dot = {{alias}}.ndarray( x.length, x, 1, 0, y, 1, 0 )
> var out = {{alias}}.ndarray( x.length, x, 1, 0, y, 1, 0 )
-5.0

// Strides:
> x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
> y = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] );
> var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> dot = {{alias}}.ndarray( N, x, 2, 0, y, 2, 0 )
> out = {{alias}}.ndarray( 3, x, 2, 0, y, 2, 0 )
9.0

// Using offset indices:
> x = new {{alias:@stdlib/array/float64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
> y = new {{alias:@stdlib/array/float64}}( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
> N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
> dot = {{alias}}.ndarray( N, x, -2, x.length-1, y, 1, 3 )
> out = {{alias}}.ndarray( 3, x, -2, x.length-1, y, 1, 3 )
128.0

See Also
Expand Down
6 changes: 3 additions & 3 deletions base/ddot/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface Routine {
* @param strideX - `x` stride length
* @param y - second input array
* @param strideY - `y` stride length
* @returns dot product of `x` and `y`
* @returns dot product
*
* @example
* var Float64Array = require( `@stdlib/array/float64` );
Expand All @@ -53,7 +53,7 @@ interface Routine {
* @param y - second input array
* @param strideY - `y` stride length
* @param offsetY - starting index for `y`
* @returns dot product of `x` and `y`
* @returns dot product
*
* @example
* var Float64Array = require( `@stdlib/array/float64` );
Expand All @@ -75,7 +75,7 @@ interface Routine {
* @param strideX - `x` stride length
* @param y - second input array
* @param strideY - `y` stride length
* @returns dot product of `x` and `y`
* @returns dot product
*
* @example
* var Float64Array = require( `@stdlib/array/float64` );
Expand Down
Loading

0 comments on commit b0508d2

Please sign in to comment.