Skip to content

Commit 6cdb5ff

Browse files
committed
feat: add BLAS Level 2 routine for sger
1 parent 16db19b commit 6cdb5ff

37 files changed

+3268
-0
lines changed
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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
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 sger = require( './../lib/sger.js' );
30+
31+
32+
// VARIABLES //
33+
34+
var options = {
35+
'dtype': 'float32'
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 = sger( 'row-major', N, N, 1, 0, x, 1, y, 1, A, N );
67+
if ( isnanf( z[ i%z.length ] ) ) {
68+
b.fail( 'should not return NaN' );
69+
}
70+
}
71+
b.toc();
72+
if ( isnanf( 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 isnanf = require( '@stdlib/math/base/assert/is-nanf' );
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 sger = require( './../lib/ndarray.js' );
30+
31+
32+
// VARIABLES //
33+
34+
var options = {
35+
'dtype': 'float32'
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 = sger( N, N, 1.0, x, 1, 0, y, 1, 0, A, N, 1, 0 );
67+
if ( isnanf( z[ i%z.length ] ) ) {
68+
b.fail( 'should not return NaN' );
69+
}
70+
}
71+
b.toc();
72+
if ( isnanf( 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();
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
2+
{{alias}}( ord, M, N, α, x, sx, y, sy, A, lda )
3+
Performs the rank 1 operation `A = α*x*y^T + A`, where `α` is a scalar, `x`
4+
is an `M` element vector, `y` is an `N` element vector and `A` is an `M` by
5+
`N` matrix.
6+
7+
Indexing is relative to the first index. To introduce an offset, use typed
8+
array views.
9+
10+
If `M` or `N` or `α` is equal to `0`, the function returns `A` unchanged.
11+
12+
Parameters
13+
----------
14+
ord: string
15+
Row-major (C-style) or column-major (Fortran-style) order.
16+
17+
M: integer
18+
Number of rows in `A`.
19+
20+
N: integer
21+
Number of columns in `A`.
22+
23+
α: number
24+
Scalar constant.
25+
26+
x: Float32Array
27+
First input vector.
28+
29+
sx: integer
30+
Index increment for `x`.
31+
32+
y: Float32Array
33+
Second input vector.
34+
35+
sy: integer
36+
Index increment for `y`.
37+
38+
A: Float32Array
39+
Input Matrix.
40+
41+
lda: integer
42+
Stride of the first dimension of `A` (a.k.a., leading dimension of the
43+
matrix `A`).
44+
45+
Returns
46+
-------
47+
A: Float32Array
48+
Input Matrix.
49+
50+
Examples
51+
--------
52+
// Standard usage:
53+
> var x = new {{alias:@stdlib/array/float32}}( [ 1.0, 1.0 ] );
54+
> var y = new {{alias:@stdlib/array/float32}}( [ 1.0, 1.0 ] );
55+
> var A = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0 ] );
56+
> var ord = 'row-major';
57+
> {{alias}}( ord, 2, 2, 1.0, x, 1, y, 1, A, 2 )
58+
<Float32Array>[ 2.0, 3.0, 4.0, 5.0 ]
59+
60+
// Advanced indexing:
61+
> x = new {{alias:@stdlib/array/float32}}( [ 1.0, 1.0 ] );
62+
> y = new {{alias:@stdlib/array/float32}}( [ 1.0, 1.0 ] );
63+
> A = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0 ] );
64+
> {{alias}}( ord, 2, 2, 1.0, x, -1, y, -1, A, 2 )
65+
<Float32Array>[ 2.0, 3.0, 4.0, 5.0 ]
66+
67+
68+
{{alias}}.ndarray( M, N, α, x, sx, ox, y, sy, oy, A, sa1, sa2, oa )
69+
Performs the rank 1 operation `A = α*x*y^T + A`, using alternative indexing
70+
semantics and where `α` is a scalar, `x` is an `M` element vector, `y` is an
71+
`N` element vector and `A` is an `M` by `N` matrix.
72+
73+
While typed array views mandate a view offset based on the underlying
74+
buffer, the offset parameters support indexing semantics based on starting
75+
indices.
76+
77+
Parameters
78+
----------
79+
M: integer
80+
Number of rows in `A`.
81+
82+
N: integer
83+
Number of columns in `A`.
84+
85+
α: number
86+
Scalar constant.
87+
88+
x: Float32Array
89+
First input vector.
90+
91+
sx: integer
92+
Index increment for `x`.
93+
94+
ox: integer
95+
Starting index for `x`.
96+
97+
y: Float32Array
98+
Second input vector.
99+
100+
sy: integer
101+
Index increment for `y`.
102+
103+
oy: integer
104+
Starting index for `y`.
105+
106+
A: Float32Array
107+
Input Matrix.
108+
109+
sa1: integer
110+
Stride of the first dimension of `A`.
111+
112+
sa2: integer
113+
Stride of the second dimension of `A`.
114+
115+
oa: integer
116+
Starting index for `A`.
117+
118+
Returns
119+
-------
120+
A: Float32Array
121+
Input Matrix.
122+
123+
Examples
124+
--------
125+
> var x = new {{alias:@stdlib/array/float32}}( [ 1.0, 1.0 ] );
126+
> var y = new {{alias:@stdlib/array/float32}}( [ 1.0, 1.0 ] );
127+
> var A = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 3.0, 4.0 ] );
128+
> {{alias}}.ndarray( 2, 2, 1.0, x, 1, 0, y, 1, 0, A, 2, 1, 0 )
129+
<Float32Array>[ 2.0, 3.0, 4.0, 5.0 ]
130+
131+
See Also
132+
--------

0 commit comments

Comments
 (0)