Skip to content

Commit 37909ad

Browse files
committed
fix: add javascript implementation for /blas/base/dger
--- 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: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: missing_dependencies - 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 4b27caa commit 37909ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2965
-1729
lines changed

lib/node_modules/@stdlib/blas/base/dger/README.md

100644100755
Lines changed: 117 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,112 @@ limitations under the License.
2020

2121
# dger
2222

23-
> TODO.
23+
> Perform the rank 1 operation `A = α*x*y^T + A`.
2424
25-
<section class="intro">
25+
<section class = "usage">
2626

27-
TODO
27+
## Usage
2828

29-
</section>
29+
```javascript
30+
var dger = require( '@stdlib/blas/base/dger' );
31+
```
3032

31-
<!-- /.intro -->
33+
#### dger( ord, M, N, α, x, sx, y, sy, A, lda )
3234

33-
<section class="usage">
35+
Performs the rank 1 operation `A = α*x*y^T + A`, where `α` is a scalar, `x` is an `M` element vector, `y` is an `N` element vector and `A` is an `M` by `N` matrix.
3436

35-
## Usage
37+
```javascript
38+
var Float64Array = require( '@stdlib/array/float64' );
39+
40+
var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
41+
var x = new Float64Array( [ 1.0, 1.0 ] );
42+
var y = new Float64Array( [ 1.0, 1.0, 1.0 ] );
43+
44+
dger( 'row-major', 2, 3, 1.0, x, 1, y, 1, A, 3 );
45+
// A => <Float64Array>[ 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ]
46+
```
47+
48+
The function has the following parameters:
49+
50+
- **ord**: storage layout.
51+
- **M**: number of rows in the matrix `A`.
52+
- **N**: number of columns in the matrix `A`.
53+
- **α**: scalar constant.
54+
- **x**: input [`Float64Array`][mdn-float64array].
55+
- **sx**: index increment for `x`.
56+
- **y**: output [`Float64Array`][mdn-float64array].
57+
- **sy**: index increment for `y`.
58+
- **A**: input matrix stored in linear memory as a [`Float64Array`][mdn-float64array].
59+
- **lda**: stride of the first dimension of `A` (leading dimension of `A`).
60+
61+
The stride parameters determine how operations are performed. For example, to iterate over every other element in `x` and `y`,
3662

3763
```javascript
38-
var dger = require( '@stdlib/blas/base/dger' );
64+
var Float64Array = require( '@stdlib/array/float64' );
65+
66+
var A = new Float64Array( [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] );
67+
var x = new Float64Array( [ 1.0, 0.0, 1.0, 0.0 ] );
68+
var y = new Float64Array( [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ] );
69+
70+
dger( 'column-major', 2, 3, 1.0, x, 2, y, 2, A, 2 );
71+
// A => <Float64Array>[ 2.0, 5.0, 3.0, 6.0, 4.0, 7.0 ]
3972
```
4073

41-
#### TODO
74+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
4275

43-
TODO
76+
<!-- eslint-disable stdlib/capitalized-comments -->
4477

4578
```javascript
46-
/* to-do */
79+
var Float64Array = require( '@stdlib/array/float64' );
80+
81+
// Initial arrays...
82+
var x0 = new Float64Array( [ 0.0, 1.0, 1.0 ] );
83+
var y0 = new Float64Array( [ 0.0, 1.0, 1.0, 1.0 ] );
84+
var A = new Float64Array( [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] );
85+
86+
// Create offset views...
87+
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
88+
var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
89+
90+
dger( 'column-major', 2, 3, 1.0, x1, -1, y1, -1, A, 2 );
91+
// A => <Float64Array>[ 2.0, 5.0, 3.0, 6.0, 4.0, 7.0 ]
4792
```
4893

49-
TODO
94+
#### dger.ndarray( M, N, α, x, sx, ox, y, sy, oy, A, sa1, sa2, oa )
95+
96+
Performs the rank 1 operation `A = α*x*y^T + A`, using alternative indexing semantics and where `α` is a scalar, `x` is an `M` element vector, `y` is an `N` element vector and `A` is an `M` by `N` matrix.
97+
98+
```javascript
99+
var Float64Array = require( '@stdlib/array/float64' );
100+
101+
var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
102+
var x = new Float64Array( [ 1.0, 1.0 ] );
103+
var y = new Float64Array( [ 1.0, 1.0, 1.0 ] );
104+
105+
dger.ndarray( 2, 3, 1.0, x, 1, 0, y, 1, 0, A, 3, 1, 0 );
106+
// A => <Float64Array>[ 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 ]
107+
```
108+
109+
The function has the following additional parameters:
110+
111+
- **sa1**: stride of the first dimension of `A`.
112+
- **sa2**: stride of the second dimension of `A`.
113+
- **oa**: starting index for `A`.
114+
- **ox**: starting index for `x`.
115+
- **oy**: starting index for `y`.
116+
117+
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,
118+
119+
```javascript
120+
var Float64Array = require( '@stdlib/array/float64' );
121+
122+
var A = new Float64Array( [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] );
123+
var x = new Float64Array( [ 1.0, 0.0, 1.0, 0.0 ] );
124+
var y = new Float64Array( [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ] );
125+
126+
dger.ndarray( 2, 3, 1.0, x, 2, 0, y, 2, 0, A, 1, 2, 0 );
127+
// A => <Float64Array>[ 2.0, 5.0, 3.0, 6.0, 4.0, 7.0 ]
128+
```
50129

51130
</section>
52131

@@ -56,7 +135,7 @@ TODO
56135

57136
## Notes
58137

59-
- `dger()` corresponds to the [BLAS][blas] level 2 function [`dger`][dger].
138+
- `dger()` corresponds to the [BLAS][blas] level 2 function [`dger`][blas-dger].
60139

61140
</section>
62141

@@ -69,7 +148,26 @@ TODO
69148
<!-- eslint no-undef: "error" -->
70149

71150
```javascript
72-
/* to-do */
151+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
152+
var dger = require( '@stdlib/blas/base/dger' );
153+
154+
var opts = {
155+
'dtype': 'float64'
156+
};
157+
158+
var M = 3;
159+
var N = 5;
160+
161+
var A = discreteUniform( M*N, 0, 255, opts );
162+
var x = discreteUniform( M, 0, 255, opts );
163+
var y = discreteUniform( N, 0, 255, opts );
164+
165+
dger( 'row-major', M, N, 1.0, x, 1, y, 1, A, N );
166+
console.log( A );
167+
168+
dger.ndarray( M, N, 1.0, x, 1, 0, y, 1, 0, A, 1, M, 0 );
169+
console.log(A);
170+
73171
```
74172

75173
</section>
@@ -160,7 +258,11 @@ TODO
160258

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

163-
[dger]: https://www.netlib.org/lapack/explore-html/dc/da8/dger_8f_source.html
261+
[blas-dger]: https://www.netlib.org/lapack/explore-html-3.6.1/d7/d15/group__double__blas__level2_ga458222e01b4d348e9b52b9343d52f828.html
262+
263+
[mdn-float64array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
264+
265+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
164266

165267
</section>
166268

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var floor = require( '@stdlib/math/base/special/floor' );
28+
var pkg = require( './../package.json' ).name;
29+
var dger = require( './../lib/dger.js' );
30+
31+
32+
// VARIABLES //
33+
34+
var options = {
35+
'dtype': 'float64'
36+
};
37+
38+
39+
// FUNCTIONS //
40+
41+
/**
42+
* Creates a benchmark function.
43+
*
44+
* @private
45+
* @param {PositiveInteger} N - array dimension size
46+
* @returns {Function} benchmark function
47+
*/
48+
function createBenchmark( N ) {
49+
var x = uniform( N, -10.0, 10.0, options );
50+
var y = uniform( N, -10.0, 10.0, options );
51+
var A = uniform( N*N, -10.0, 10.0, options );
52+
return benchmark;
53+
54+
/**
55+
* Benchmark function.
56+
*
57+
* @private
58+
* @param {Benchmark} b - benchmark instance
59+
*/
60+
function benchmark( b ) {
61+
var z;
62+
var i;
63+
64+
b.tic();
65+
for ( i = 0; i < b.iterations; i++ ) {
66+
z = dger( 'row-major', N, N, 1.0, x, 1, y, 1, A, N );
67+
if ( isnan( z[ i%z.length ] ) ) {
68+
b.fail( 'should not return NaN' );
69+
}
70+
}
71+
b.toc();
72+
if ( isnan( z[ i%z.length ] ) ) {
73+
b.fail( 'should not return NaN' );
74+
}
75+
b.pass( 'benchmark finished' );
76+
b.end();
77+
}
78+
}
79+
80+
81+
// MAIN //
82+
83+
/**
84+
* Main execution sequence.
85+
*
86+
* @private
87+
*/
88+
function main() {
89+
var len;
90+
var min;
91+
var max;
92+
var f;
93+
var i;
94+
95+
min = 1; // 10^min
96+
max = 6; // 10^max
97+
98+
for ( i = min; i <= max; i++ ) {
99+
len = floor( pow( pow( 10, i ), 1.0/2.0 ) );
100+
f = createBenchmark( len );
101+
bench( pkg+':size='+(len*len), f );
102+
}
103+
}
104+
105+
main();
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/array/uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var floor = require( '@stdlib/math/base/special/floor' );
28+
var pkg = require( './../package.json' ).name;
29+
var dger = require( './../lib/ndarray.js' );
30+
31+
32+
// VARIABLES //
33+
34+
var options = {
35+
'dtype': 'float64'
36+
};
37+
38+
39+
// FUNCTIONS //
40+
41+
/**
42+
* Creates a benchmark function.
43+
*
44+
* @private
45+
* @param {PositiveInteger} N - array dimension size
46+
* @returns {Function} benchmark function
47+
*/
48+
function createBenchmark( N ) {
49+
var x = uniform( N, -10.0, 10.0, options );
50+
var y = uniform( N, -10.0, 10.0, options );
51+
var A = uniform( N*N, -10.0, 10.0, options );
52+
return benchmark;
53+
54+
/**
55+
* Benchmark function.
56+
*
57+
* @private
58+
* @param {Benchmark} b - benchmark instance
59+
*/
60+
function benchmark( b ) {
61+
var z;
62+
var i;
63+
64+
b.tic();
65+
for ( i = 0; i < b.iterations; i++ ) {
66+
z = dger( N, N, 1.0, x, 1, 0, y, 1, 0, A, N, 1, 0 );
67+
if ( isnan( z[ i%z.length ] ) ) {
68+
b.fail( 'should not return NaN' );
69+
}
70+
}
71+
b.toc();
72+
if ( isnan( z[ i%z.length ] ) ) {
73+
b.fail( 'should not return NaN' );
74+
}
75+
b.pass( 'benchmark finished' );
76+
b.end();
77+
}
78+
}
79+
80+
81+
// MAIN //
82+
83+
/**
84+
* Main execution sequence.
85+
*
86+
* @private
87+
*/
88+
function main() {
89+
var len;
90+
var min;
91+
var max;
92+
var f;
93+
var i;
94+
95+
min = 1; // 10^min
96+
max = 6; // 10^max
97+
98+
for ( i = min; i <= max; i++ ) {
99+
len = floor( pow( pow( 10, i ), 1.0/2.0 ) );
100+
f = createBenchmark( len );
101+
bench( pkg+':ndarray:size='+(len*len), f );
102+
}
103+
}
104+
105+
main();

0 commit comments

Comments
 (0)