-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: add blas/base/srotmg
#9711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DhruvArvindSingh
wants to merge
6
commits into
stdlib-js:develop
Choose a base branch
from
DhruvArvindSingh:feat/srotmg
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fb98a6e
feat: add blas/base/srotmg
DhruvArvindSingh c3858a1
fix: native benchmark
DhruvArvindSingh a949f52
fix: benchmarks ,headers and readme
DhruvArvindSingh 82d4e50
fix: lib and src
DhruvArvindSingh 31bd604
fix: lib and src
DhruvArvindSingh 45a77a9
fix: benchmark and test
DhruvArvindSingh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,266 @@ | ||
| <!-- | ||
|
|
||
| @license Apache-2.0 | ||
|
|
||
| Copyright (c) 2026 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. | ||
|
|
||
| --> | ||
|
|
||
| # srotmg | ||
|
|
||
| > Construct a Givens plane rotation. | ||
|
|
||
| <section class="usage"> | ||
|
|
||
| ## Usage | ||
|
|
||
| ```javascript | ||
| var srotmg = require( '@stdlib/blas/base/srotmg' ); | ||
| ``` | ||
|
|
||
| #### srotmg( d1, d2, x1, y1 ) | ||
|
|
||
| Constructs a Givens plane rotation provided four single-precision floating-point values `d1`, `d2`, `x1` and `y1`. | ||
|
|
||
| ```javascript | ||
| var out = srotmg( 5.0, 4.0, 1.0, -2.0 ); | ||
| // returns <Float32Array>[ 1.0, -0.625, 0.0, 0.0, -0.5 ] | ||
| ``` | ||
|
|
||
| The function has the following parameters: | ||
|
|
||
| - **d1**: scaling factor for the first vector component. | ||
| - **d2**: scaling factor for the second vector component. | ||
| - **x1**: first component of the first vector. | ||
| - **y1**: first component of the second vector. | ||
|
|
||
| #### srotmg.assign( d1, d2, x1, y1, out, stride, offset ) | ||
|
|
||
| Constructs a Givens plane rotation provided two single-precision floating-point values d1, d2, x1 and y1 and assigns results to an output array. | ||
|
|
||
| ```javascript | ||
| var Float32Array = require( '@stdlib/array/float32' ); | ||
|
|
||
| var out = new Float32Array( 5 ); | ||
|
|
||
| var y = srotmg.assign( 5.0, 4.0, 1.0, -2.0, out, 1, 0 ); | ||
| // returns <Float32Array>[ 1.0, -0.625, 0.0, 0.0, -0.5 ] | ||
|
|
||
| var bool = ( y === out ); | ||
| // returns true | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.usage --> | ||
|
|
||
| <section class="notes"> | ||
|
|
||
| ## Notes | ||
|
|
||
| - `srotmg()` corresponds to the [BLAS][blas] level 1 function [`srotmg`][srotmg]. | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.notes --> | ||
|
|
||
| ## Examples | ||
|
|
||
| <section class="examples"> | ||
|
|
||
| ```javascript | ||
| var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ); | ||
| var srotmg = require( '@stdlib/blas/base/srotmg' ); | ||
|
|
||
| var out; | ||
| var y1; | ||
| var x1; | ||
| var d2; | ||
| var d1; | ||
| var i; | ||
| for ( i = 0; i < 100; i++ ) { | ||
| d1 = discreteUniform( -5, 5 ); | ||
| d2 = discreteUniform( -5, 5 ); | ||
| x1 = discreteUniform( -5, 5 ); | ||
| y1 = discreteUniform( -5, 5 ); | ||
| out = srotmg( d1, d2, x1, y1 ); | ||
| console.log( out ); | ||
| } | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.examples --> | ||
|
|
||
| <!-- C interface documentation. --> | ||
|
|
||
| * * * | ||
|
|
||
| <section class="c"> | ||
|
|
||
| ## C APIs | ||
|
|
||
| <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="intro"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.intro --> | ||
|
|
||
| <!-- C usage documentation. --> | ||
|
|
||
| <section class="usage"> | ||
|
|
||
| ### Usage | ||
|
|
||
| ```c | ||
| #include "stdlib/blas/base/srotmg.h" | ||
| ``` | ||
|
|
||
| #### c_srotmg( d1, d2, x1, y1, \*Out, strideOut ) | ||
|
|
||
| Constructs a Givens plane rotation provided four single-precision floating-point values `d1`, `d2`, `x1` & `y1`and assigns results to an output array. | ||
|
|
||
|
|
||
| ```c | ||
| float Out[5]; | ||
|
|
||
| c_srotmg( 5.0, 4.0, 1.0, -2.0, Out, 1 ); | ||
| // Out => <Float32Array>[ 1.0, -0.625, 0.0, 0.0, -0.5] | ||
| ``` | ||
|
|
||
| The function accepts the following arguments: | ||
|
|
||
| - **d1**: `[in] float` scaling factor for the first vector component. | ||
| - **d2**: `[in] float` scaling factor for the second vector component. | ||
| - **x1**: `[in] float` first component of the first vector. | ||
| - **y1**: `[in] float` first component of the second vector. | ||
| - **Out**: `[inout] float*` output array. | ||
| - **strideOut**: `[in] CBLAS_INT` stride length for `Out`. | ||
|
|
||
|
|
||
| ```c | ||
| void c_srotmg( float d1, float d2, float x1, float y1, float* Out, const CBLAS_INT strideOut ); | ||
| ``` | ||
|
|
||
| #### c_srotmg_assign( d1, d2, x1, y1, \*Out, strideOut, offsetOut ) | ||
|
|
||
| Constructs a Givens plane rotation provided four single-precision floating-point values `d1`, `d2`, `x1` & `y1`and assigns results to an output array using alternative indexing semantics.. | ||
|
|
||
| ```c | ||
| float Out[5]; | ||
|
|
||
| c_srotmg( 5.0, 4.0, 1.0, -2.0, Out, 1, 0 ); | ||
| // Out => <Float32Array>[ 1.0, -0.625, 0.0, 0.0, -0.5] | ||
| ``` | ||
|
|
||
| The function accepts the following arguments: | ||
|
|
||
| - **d1**: `[in] float` scaling factor for the first vector component. | ||
| - **d2**: `[in] float` scaling factor for the second vector component. | ||
| - **x1**: `[in] float` first component of the first vector. | ||
| - **y1**: `[in] float` first component of the second vector. | ||
| - **Out**: `[inout] float*` output array. | ||
| - **strideOut**: `[in] CBLAS_INT` stride length for `Out`. | ||
| - **offsetOut**: `[in] CBLAS_INT` starting index for `Out`. | ||
|
|
||
| Givens transformation. | ||
|
|
||
| ```c | ||
| void c_srotmg_assign( float d1, float d2, float x1, float y1, float* Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut ); | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.usage --> | ||
|
|
||
| <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="notes"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.notes --> | ||
|
|
||
| <!-- C API usage examples. --> | ||
|
|
||
| <section class="examples"> | ||
|
|
||
| ### Examples | ||
|
|
||
| ```c | ||
| #include "stdlib/blas/base/srotmg.h" | ||
| #include <stdio.h> | ||
|
|
||
| int main( void ) { | ||
| const float d1 = 5.0; | ||
| const float d2 = 4.0; | ||
| const float x1 = 1.0; | ||
| const float y1 = -2.0; | ||
| int i; | ||
|
|
||
| // Create strided arrays: | ||
| float out[ 5 ]; | ||
|
|
||
| // Specify stride lengths: | ||
| const int strideOut = 1; | ||
|
|
||
| // Apply plane rotation: | ||
| c_srotmg( d1, d2, x1, y1, out, strideOut ); | ||
|
|
||
| // Print the result: | ||
| for ( i = 0; i < 5; i++ ) { | ||
| printf( "out[%d] = %f\n", i, out[ i ] ); | ||
| } | ||
|
|
||
| // Apply plane rotation | ||
| c_srotmg_assign( d1, d2, x1, y1, out, strideOut, 0 ); | ||
|
|
||
| // Print the result: | ||
| for ( i = 0; i < 5; i++ ) { | ||
| printf( "out[%d] = %f\n", i, out[ i ] ); | ||
| } | ||
| } | ||
|
|
||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.examples --> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.c --> | ||
|
|
||
| <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||
|
|
||
| <section class="related"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.related --> | ||
|
|
||
| <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="links"> | ||
|
|
||
| [blas]: http://www.netlib.org/blas | ||
|
|
||
| [srotmg]: http://www.netlib.org/lapack/explore-html/df/d28/group__single__blas__level1.html | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.links --> | ||
69 changes: 69 additions & 0 deletions
69
lib/node_modules/@stdlib/blas/base/srotmg/benchmark/benchmark.assign.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /** | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 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' ); | ||
| var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); | ||
| var isnanf = require( '@stdlib/math/base/assert/is-nanf' ); | ||
| var Float32Array = require( '@stdlib/array/float32' ); | ||
| var format = require( '@stdlib/string/format' ); | ||
| var pkg = require( './../package.json' ).name; | ||
| var srotmg = require( './../lib/assign.js' ); | ||
|
|
||
|
|
||
| // VARIABLES // | ||
|
|
||
| var options = { | ||
| 'dtype': 'float32' | ||
| }; | ||
|
|
||
|
|
||
| // MAIN // | ||
|
|
||
| bench( format( '%s:assign', pkg ), function benchmark( b ) { | ||
| var out; | ||
| var d1; | ||
| var d2; | ||
| var x1; | ||
| var y1; | ||
| var z; | ||
| var i; | ||
|
|
||
| d1 = discreteUniform( 100, -5, 5, options ); | ||
| d2 = discreteUniform( 100, -5, 5, options ); | ||
| x1 = discreteUniform( 100, -5, 5, options ); | ||
| y1 = discreteUniform( 100, -5, 5, options ); | ||
| out = new Float32Array( 5 ); | ||
|
|
||
| b.tic(); | ||
| for ( i = 0; i < b.iterations; i++ ) { | ||
| z = srotmg( d1[ i%d1.length ], d2[ i%d2.length ], x1[ i%x1.length ], y1[ i%y1.length ], out, 1, 0 ); // eslint-disable-line max-len | ||
| if ( typeof z !=='object' ) { | ||
| b.fail( 'should return an array' ); | ||
| } | ||
| } | ||
| b.toc(); | ||
| if ( isnanf( z[ i%5 ] ) ) { | ||
| b.fail( 'should return the output array' ); | ||
| } | ||
| b.pass( 'benchmark finished' ); | ||
| b.end(); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.