Skip to content

Commit ec6bf9d

Browse files
committed
feat: add /blas/base/srotmg
1 parent 8785e54 commit ec6bf9d

File tree

13 files changed

+1202
-0
lines changed

13 files changed

+1202
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2023 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# srotmg
22+
23+
> Constructs the parameters for a modified Givens plane rotation.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var srotmg = require( '@stdlib/blas/base/srotmg' );
31+
```
32+
33+
#### srotmg( d1, d2, x1, y1 )
34+
35+
Constructs a Givens plane rotation provided two single-precision floating-point values `d1` and `d2`.
36+
37+
```javascript
38+
var out = srotmg( -3.0, -4.0, 1.5, 2.5 );
39+
// returns <Float32Array>[ 0.6000000238418579, 0.800000011920929, 2, 1.5, 2.5 ]
40+
```
41+
42+
The function has the following parameters:
43+
44+
- **d1**: scaling factor for the first vector component.
45+
- **d2**: scaling factor for the second vector component.
46+
- **x1**: first component of the first vector.
47+
- **y1**: first component of the second vector.
48+
49+
#### srotmg.assign( d1, d2, x1, y1, out, stride, offset )
50+
51+
Constructs a Givens plane rotation provided two single-precision floating-point values `d1` and `d2` and assigns results to an output array.
52+
53+
```javascript
54+
var Float32Array = require( '@stdlib/array/float32' );
55+
56+
var out = new Float32Array( 5 );
57+
58+
var y = srotmg.assign( -3.0, -4.0, 1.5, 2.5, out, 1, 0 );
59+
// returns <Float32Array>[ 0.6000000238418579, 0.800000011920929, 2, 1.5, 2.5 ]
60+
61+
var bool = ( y === out );
62+
// returns true
63+
```
64+
65+
</section>
66+
67+
<!-- /.usage -->
68+
69+
<section class="notes">
70+
71+
## Notes
72+
73+
- `srotmg()` corresponds to the [BLAS][blas] level 1 function [`srotmg`][srotmg].
74+
75+
</section>
76+
77+
<!-- /.notes -->
78+
79+
<section class="examples">
80+
81+
```javascript
82+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
83+
var srotmg = require( '@stdlib/blas/base/srotmg' );
84+
85+
var out;
86+
var i;
87+
for ( i = 0; i < 100; i++ ) {
88+
d1 = discreteUniform( -5, 5 );
89+
d2 = discreteUniform( -5, 5 );
90+
x1 = discreteUniform( -5, 5 );
91+
y1 = discreteUniform( -5, 5 );
92+
out = srotmg( d1, d2, x1, y1 );
93+
console.log( out );
94+
}
95+
```
96+
97+
</section>
98+
99+
<!-- /.examples -->
100+
101+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
102+
103+
<section class="related">
104+
105+
</section>
106+
107+
<!-- /.related -->
108+
109+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
110+
111+
<section class="links">
112+
113+
[blas]: http://www.netlib.org/blas
114+
115+
[srotmg]: http://www.netlib.org/lapack/explore-html/df/d28/group__single__blas__level1.html
116+
117+
</section>
118+
119+
<!-- /.links -->
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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 discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
25+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26+
var Float32Array = require( '@stdlib/array/float32' );
27+
var pkg = require( './../package.json' ).name;
28+
var srotmg = require( './../lib' );
29+
30+
31+
// VARIABLES //
32+
33+
var OPTS = {
34+
'dtype': 'float32'
35+
};
36+
37+
38+
// MAIN //
39+
40+
bench( pkg, function benchmark( b ) {
41+
var out;
42+
var d1;
43+
var d2;
44+
var x1;
45+
var y1;
46+
var i;
47+
48+
d1 = discreteUniform( 100, -5, 5, OPTS );
49+
d2 = discreteUniform( 100, -5, 5, OPTS );
50+
x1 = discreteUniform( 100, -5, 5, OPTS );
51+
y1 = discreteUniform( 100, -5, 5, OPTS );
52+
53+
b.tic();
54+
for ( i = 0; i < b.iterations; i++ ) {
55+
out = srotmg( d1[ i%d1.length ], d2[ i%d2.length ], x1[ i%x1.length ], y1[ i%y1.length ] );
56+
if ( isnanf( out[ i%5 ] ) ) {
57+
b.fail( 'should not return NaN' );
58+
}
59+
}
60+
b.toc();
61+
if ( isnanf( out[ i%5 ] ) ) {
62+
b.fail( 'should not return NaN' );
63+
}
64+
b.pass( 'benchmark finished' );
65+
b.end();
66+
});
67+
68+
bench( pkg+':assign', function benchmark( b ) {
69+
var out;
70+
var d1;
71+
var d2;
72+
var x1;
73+
var y1;
74+
var z;
75+
var i;
76+
77+
d1 = discreteUniform( 100, -5, 5, OPTS );
78+
d2 = discreteUniform( 100, -5, 5, OPTS );
79+
x1 = discreteUniform( 100, -5, 5, OPTS );
80+
y1 = discreteUniform( 100, -5, 5, OPTS );
81+
out = new Float32Array( 5 );
82+
83+
b.tic();
84+
for ( i = 0; i < b.iterations; i++ ) {
85+
z = srotmg.assign( d1[ i%d1.length ], d2[ i%d2.length ], x1[ i%x1.length ], y1[ i%y1.length ], out, 1, 0 );
86+
if ( typeof z !=='object' ) {
87+
b.fail( 'should return an array' );
88+
}
89+
}
90+
b.toc();
91+
if ( isnanf( z[ i%5 ] ) ) {
92+
b.fail( 'should return the output array' );
93+
}
94+
b.pass( 'benchmark finished' );
95+
b.end();
96+
});
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
{{alias}}( d1, d2, x1, y1 )
3+
Constructs the parameters for a modified Givens plane rotation.
4+
5+
Parameters
6+
----------
7+
d1: float
8+
Scaling factor for the first vector component.
9+
10+
d2: float
11+
Scaling factor for the second vector component.
12+
13+
x1: float
14+
First component of the first vector.
15+
16+
y1: float
17+
First component of the second vector.
18+
19+
Returns
20+
-------
21+
out: Float32Array
22+
Computed values.
23+
24+
Examples
25+
--------
26+
> var out = {{alias}}( 1.0, 1.0, 1.0, 0.0 )
27+
<Float32Array>[ -2.0, 0.0, 0.0, 1.0, 0.0 ]
28+
29+
30+
{{alias}}.assign( d1, d2, x1. y1, out, stride, offset )
31+
Constructs the parameters for a modified Givens plane rotation.
32+
33+
Parameters
34+
----------
35+
d1: float
36+
Scaling factor for the first vector component.
37+
38+
d2: float
39+
Scaling factor for the second vector component.
40+
41+
x1: float
42+
First component of the first vector.
43+
44+
y1: float
45+
First component of the second vector.
46+
47+
out: Float32Array
48+
Output array.
49+
50+
stride: integer
51+
Output array stride.
52+
53+
offset: integer
54+
Output array index offset.
55+
56+
Returns
57+
-------
58+
out: Float32Array
59+
Output array.
60+
61+
Examples
62+
--------
63+
> var out = new {{alias:@stdlib/array/float32}}( 5 );
64+
> var y = {{alias}}.assign( 1.0, 1.0, 1.0, 0.0, out, 1, 0 )
65+
<Float32Array>[ -2.0, 0.0, 0.0, 1.0, 0.0 ]
66+
> var bool = ( y === out )
67+
true
68+
69+
See Also
70+
--------
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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+
// TypeScript Version: 4.1
20+
21+
/**
22+
* Inteface describing `srotmg`.
23+
*/
24+
interface Routine {
25+
/**
26+
* Constructs the parameters for a modified Givens plane rotation.
27+
*
28+
* @param d1 - scaling factor for the first vector component
29+
* @param d2 - scaling factor for the second vector component
30+
* @param x1 - first component of the first vector
31+
* @param y1 - first component of the second vector
32+
* @returns - output array containing the rotation parameters
33+
*
34+
* @example
35+
* var Float32Array = require( '@stdlib/array/float32' );
36+
*
37+
* var out = srotmg( 1.0, 1.0, 1.0, 0.0 );
38+
* // returns <Float32Array>[ 0.0, 1.0, 0.0, 1.0, 0.0 ]
39+
*/
40+
( d1: number, d2: number, x1: number, y1: number ): Float32Array;
41+
42+
/**
43+
* Constructs the parameters for a modified Givens plane rotation.
44+
*
45+
* @param d1 - scaling factor for the first vector component
46+
* @param d2 - scaling factor for the second vector component
47+
* @param x1 - first component of the first vector
48+
* @param y1 - first component of the second vector
49+
* @param out - output array
50+
* @param stride - index increment
51+
* @param offset - starting index
52+
* @returns - output array containing the rotation parameters
53+
*
54+
* @example
55+
* var Float32Array = require( '@stdlib/array/float32' );
56+
*
57+
* var out = srotmg( 1.0, 1.0, 1.0, 0.0 );
58+
* // returns <Float32Array>[ 0.0, 1.0, 0.0, 1.0, 0.0 ]
59+
*
60+
* var bool = (y === out);
61+
* // returns true
62+
*/
63+
assign( d1: number, d2: number, x1: number, y1: number, out: Float32Array, stride: number, offset: number ): Float32Array;
64+
}
65+
66+
/**
67+
* Constructs the parameters for a modified Givens plane rotation.
68+
*
69+
* @param d1 - scaling factor for the first vector component
70+
* @param d2 - scaling factor for the second vector component
71+
* @param x1 - first component of the first vector
72+
* @param y1 - first component of the second vector
73+
* @param out - output array
74+
* @param stride - index increment
75+
* @param offset - starting index
76+
* @returns - output array containing the rotation parameters
77+
*
78+
* @example
79+
* var Float32Array = require( '@stdlib/array/float32' );
80+
*
81+
* var out = srotmg( 1.0, 1.0, 1.0, 0.0 );
82+
* // returns <Float32Array>[ 0.0, 1.0, 0.0, 1.0, 0.0 ]
83+
*
84+
* var bool = (y === out);
85+
* // returns true
86+
*/
87+
declare var srotmg: Routine;
88+
89+
// EXPORTS //
90+
91+
export = srotmg;

0 commit comments

Comments
 (0)