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 Aug 17, 2024
1 parent 48010c7 commit 57afceb
Show file tree
Hide file tree
Showing 16 changed files with 871 additions and 110 deletions.
1 change: 0 additions & 1 deletion .github/.keepalive

This file was deleted.

47 changes: 45 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,50 @@

> Package changelog.
<section class="release" id="unreleased">

## Unreleased (2024-08-17)

<section class="features">

### Features

- [`0eaf8b6`](https://github.com/stdlib-js/stdlib/commit/0eaf8b6263017bfe14c1b8769dfd885a19d1778e) - add support for operating on stacks of vectors

</section>

<!-- /.features -->

<section class="commits">

### Commits

<details>

- [`0eaf8b6`](https://github.com/stdlib-js/stdlib/commit/0eaf8b6263017bfe14c1b8769dfd885a19d1778e) - **feat:** add support for operating on stacks of vectors _(by Athan Reines)_

</details>

</section>

<!-- /.commits -->

<section class="contributors">

### Contributors

A total of 1 person contributed to this release. Thank you to this contributor:

- Athan Reines

</section>

<!-- /.contributors -->

</section>

<!-- /.release -->

<section class="release" id="v0.2.2">

## 0.2.2 (2024-07-28)
Expand Down Expand Up @@ -84,8 +128,7 @@ A total of 1 person contributed to this release. Thank you to this contributor:

### BREAKING CHANGES

- [`cca37d0`](https://github.com/stdlib-js/stdlib/commit/cca37d051d8c0209970fc681353fdb4e4d257a8a): update minimum TypeScript version
- [`cca37d0`](https://github.com/stdlib-js/stdlib/commit/cca37d051d8c0209970fc681353fdb4e4d257a8a): update minimum TypeScript version to 4.1
- [`cca37d0`](https://github.com/stdlib-js/stdlib/commit/cca37d051d8c0209970fc681353fdb4e4d257a8a): update minimum TypeScript version to 4.1

- To migrate, users should upgrade their TypeScript version to at least version 4.1.

Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Marcus Fantham <[email protected]>
Matt Cochrane <[email protected]>
Mihir Pandit <[email protected]>
Milan Raj <[email protected]>
Mohammad Kaif <[email protected]>
Momtchil Momtchev <[email protected]>
Muhammad Haris <[email protected]>
Naresh Jagadeesan <[email protected]>
Expand All @@ -70,6 +71,7 @@ Roman Stetsyk <[email protected]>
Rutam <[email protected]>
Ryan Seal <[email protected]>
Sai Srikar Dumpeti <[email protected]>
SarthakPaandey <[email protected]>
Seyyed Parsa Neshaei <[email protected]>
Shashank Shekhar Singh <[email protected]>
Shivam <[email protected]>
Expand Down
66 changes: 43 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ To view installation and usage instructions specific to each branch build, be su
var ddot = require( '@stdlib/blas-ddot' );
```

#### ddot( x, y )
#### ddot( x, y\[, dim] )

Calculates the dot product of two double-precision floating-point vectors `x` and `y`.

Expand All @@ -96,25 +96,38 @@ var x = array( new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] ) );
var y = array( new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ) );

var z = ddot( x, y );
// returns <ndarray>

var v = z.get();
// returns -5.0
```

The function has the following parameters:

- **x**: a 1-dimensional [`ndarray`][@stdlib/ndarray/array] whose underlying data type is `float64`.
- **y**: a 1-dimensional [`ndarray`][@stdlib/ndarray/array] whose underlying data type is `float64`.
- **x**: a non-zero-dimensional [`ndarray`][@stdlib/ndarray/ctor] whose underlying data type is `float64`. Must be [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with `y`.
- **y**: a non-zero-dimensional [`ndarray`][@stdlib/ndarray/ctor] whose underlying data type is `float64`. Must be [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with `x`.
- **dim**: dimension for which to compute the dot product. Must be a negative integer. Negative indices are resolved relative to the last array dimension, with the last dimension corresponding to `-1`. Default: `-1`.

If provided empty vectors, the function returns `0.0`.
If provided at least one input [`ndarray`][@stdlib/ndarray/ctor] having more than one dimension, the input [`ndarrays`][@stdlib/ndarray/ctor] are [broadcasted][@stdlib/ndarray/base/broadcast-shapes] to a common shape. For multi-dimensional input [`ndarrays`][@stdlib/ndarray/ctor], the function performs batched computation, such that the function computes the dot product for each pair of vectors in `x` and `y` according to the specified dimension index.

```javascript
var Float64Array = require( '@stdlib/array-float64' );
var array = require( '@stdlib/ndarray-array' );

var x = array( new Float64Array() );
var y = array( new Float64Array() );
var opts = {
'shape': [ 2, 3 ]
};
var x = array( new Float64Array( [ 4.0, 2.0, -3.0, 5.0, -1.0, 3.0 ] ), opts );
var y = array( new Float64Array( [ 2.0, 6.0, -1.0, -4.0, 8.0, 2.0 ] ), opts );

var z = ddot( x, y );
// returns 0.0
// returns <ndarray>

var v1 = z.get( 0 );
// returns 23.0

var v2 = z.get( 1 );
// returns -22.0
```

</section>
Expand All @@ -125,6 +138,11 @@ var z = ddot( x, y );

## Notes

- The size of the contracted dimension must be the same for both input [`ndarrays`][@stdlib/ndarray/ctor].
- The function resolves the dimension index for which to compute the dot product **before** broadcasting.
- Negative indices are resolved relative to the last [`ndarray`][@stdlib/ndarray/ctor] dimension, with the last dimension corresponding to `-1`.
- The output [`ndarray`][@stdlib/ndarray/ctor] has the same data type as the input [`ndarrays`][@stdlib/ndarray/ctor] and has a shape which is determined by broadcasting and excludes the contracted dimension.
- If provided empty vectors, the dot product is `0`.
- `ddot()` provides a higher-level interface to the [BLAS][blas] level 1 function [`ddot`][@stdlib/blas/base/ddot].

</section>
Expand All @@ -138,27 +156,27 @@ var z = ddot( x, y );
<!-- eslint no-undef: "error" -->

```javascript
var discreteUniform = require( '@stdlib/random-base-discrete-uniform' );
var Float64Array = require( '@stdlib/array-float64' );
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
var ndarray2array = require( '@stdlib/ndarray-to-array' );
var array = require( '@stdlib/ndarray-array' );
var ddot = require( '@stdlib/blas-ddot' );

var x = array( new Float64Array( 10 ) );
var y = array( new Float64Array( 10 ) );
var opts = {
'dtype': 'float64'
};

var rand1 = discreteUniform.factory( 0, 100 );
var rand2 = discreteUniform.factory( 0, 10 );
var x = array( discreteUniform( 10, 0, 100, opts ), {
'shape': [ 5, 2 ]
});
console.log( ndarray2array( x ) );

var i;
for ( i = 0; i < x.length; i++ ) {
x.set( i, rand1() );
y.set( i, rand2() );
}
console.log( x.toString() );
console.log( y.toString() );
var y = array( discreteUniform( 10, 0, 10, opts ), {
'shape': x.shape
});
console.log( ndarray2array( y ) );

var z = ddot( x, y );
console.log( z );
var z = ddot( x, y, -1 );
console.log( ndarray2array( z ) );
```

</section>
Expand Down Expand Up @@ -257,7 +275,9 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].

[blas]: http://www.netlib.org/blas

[@stdlib/ndarray/array]: https://github.com/stdlib-js/ndarray-array
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor

[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/ndarray-base-broadcast-shapes

<!-- <related-links> -->

Expand Down
37 changes: 19 additions & 18 deletions benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@
// MODULES //

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


// VARIABLES //

var opts = {
'dtype': 'float64'
};


// FUNCTIONS //

/**
Expand All @@ -40,34 +46,29 @@ var ddot = require( './../lib/main.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 < len; i++ ) {
x[ i ] = ( randu()*10.0 ) - 20.0;
y[ i ] = ( randu()*10.0 ) - 20.0;
}
x = array( x );
y = array( y );

var x = array( uniform( len, -100.0, 100.0, opts ) );
var y = array( uniform( len, -100.0, 100.0, opts ) );
return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var d;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
d = ddot( x, y );
if ( isnan( d ) ) {
if ( isnan( d.get() ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( d ) ) {
if ( isnan( d.get() ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
Expand Down Expand Up @@ -96,7 +97,7 @@ function main() {
for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( pkg+':len='+len, f );
bench( pkg+'::vectors:len='+len, f );
}
}

Expand Down
122 changes: 122 additions & 0 deletions benchmark/benchmark.stacks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2020 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench-harness' );
var isnan = require( '@stdlib/math-base-assert-is-nan' );
var pow = require( '@stdlib/math-base-special-pow' );
var uniform = require( '@stdlib/random-array-uniform' );
var numel = require( '@stdlib/ndarray-base-numel' );
var array = require( '@stdlib/ndarray-array' );
var pkg = require( './../package.json' ).name;
var ddot = require( './../lib/main.js' );


// VARIABLES //

var OPTS = {
'dtype': 'float64'
};


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveIntegerArray} shape - array shape
* @returns {Function} benchmark function
*/
function createBenchmark( shape ) {
var x;
var y;
var N;
var o;

N = numel( shape );
o = {
'shape': shape
};
x = array( uniform( N, -100.0, 100.0, OPTS ), o );
y = array( uniform( N, -100.0, 100.0, OPTS ), o );

return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var d;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
d = ddot( x, y );
if ( isnan( d.iget( 0 ) ) ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( isnan( d.iget( 0 ) ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var shape;
var min;
var max;
var N;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
N = pow( 10, i );

shape = [ 2, N/2 ];
f = createBenchmark( shape );
bench( pkg+'::stacks:size='+N+',ndims='+shape.length+',shape=('+shape.join( ',' )+')', f );

shape = [ N/2, 2 ];
f = createBenchmark( shape );
bench( pkg+'::stacks:size='+N+',ndims='+shape.length+',shape=('+shape.join( ',' )+')', f );
}
}

main();
Loading

0 comments on commit 57afceb

Please sign in to comment.