|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2024 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 | +# srotm |
| 22 | + |
| 23 | +> Apply a modified Givens plane rotation. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var srotm = require( '@stdlib/blas/base/srotm' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### srotm( N, x, strideX, y, strideY, param ) |
| 34 | + |
| 35 | +Applies a modified Givens plane rotation. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var Float32Array = require( '@stdlib/array/float32' ); |
| 39 | + |
| 40 | +var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); |
| 41 | +var y = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); |
| 42 | +var param = new Float32Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); |
| 43 | + |
| 44 | +srotm( 2, x, 2, y, 1, param ); |
| 45 | +// x => <Float32Array>[ ~-17.0, 2.0, ~-18.0, 4.0, 5.0 ] |
| 46 | +// y => <Float32Array>[ ~8.0, ~13.0, 8.0, 9.0, 10.0 ] |
| 47 | +``` |
| 48 | + |
| 49 | +The function has the following parameters: |
| 50 | + |
| 51 | +- **N**: number of indexed elements. |
| 52 | +- **x**: first input [`Float32Array`][mdn-float32array]. |
| 53 | +- **strideX**: index increment for `x`. |
| 54 | +- **y**: second input [`Float32Array`][mdn-float32array]. |
| 55 | +- **strideY**: index increment for `y`. |
| 56 | +- **param**: parameters for the modified Givens transformation |
| 57 | + |
| 58 | +The `N` and stride parameters determine how values in the strided arrays are accessed at runtime. For example, to apply a modified Givens plane rotation to every other element, |
| 59 | + |
| 60 | +```javascript |
| 61 | +var Float32Array = require( '@stdlib/array/float32' ); |
| 62 | + |
| 63 | +var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 64 | +var y = new Float32Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); |
| 65 | +var param = new Float32Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); |
| 66 | + |
| 67 | +srotm( 3, x, 2, y, 2, param ); |
| 68 | +// x => <Float32Array>[ ~-20.0, 2.0, ~-24.0, 4.0, ~-28.0, 6.0 ] |
| 69 | +// y => <Float32Array>[ ~9.0, 8.0, ~15.0, 10.0, ~21.0, 12.0 ] |
| 70 | +``` |
| 71 | + |
| 72 | +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. |
| 73 | + |
| 74 | +<!-- eslint-disable stdlib/capitalized-comments --> |
| 75 | + |
| 76 | +```javascript |
| 77 | +var Float32Array = require( '@stdlib/array/float32' ); |
| 78 | + |
| 79 | +// Initial arrays... |
| 80 | +var x0 = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); |
| 81 | +var y0 = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); |
| 82 | +var param = new Float32Array( [ 1.0, 0.0, 2.0, 3.0, 0.0 ] ); |
| 83 | + |
| 84 | +// Create offset views... |
| 85 | +var x1 = new Float32Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 86 | +var y1 = new Float32Array( y0.buffer, y0.BYTES_PER_ELEMENT*3 ); // start at 4th element |
| 87 | + |
| 88 | +srotm( 2, x1, 1, y1, 1, param ); |
| 89 | +// x0 => <Float32Array>[ 1.0, ~9.0, ~10.0, 4.0, 5.0 ] |
| 90 | +// y0 => <Float32Array>[ 6.0, 7.0, 8.0, ~-2.0, ~-3.0 ] |
| 91 | +``` |
| 92 | + |
| 93 | +#### srotm.ndarray( N, x, strideX, offsetX, y, strideY, offsetY, param ) |
| 94 | + |
| 95 | +Applies a modified Givens plane rotation using alternative indexing semantics. |
| 96 | + |
| 97 | +```javascript |
| 98 | +var Float32Array = require( '@stdlib/array/float32' ); |
| 99 | + |
| 100 | +var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ); |
| 101 | +var y = new Float32Array( [ 6.0, 7.0, 8.0, 9.0, 10.0 ] ); |
| 102 | +var param = new Float32Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); |
| 103 | + |
| 104 | +srotm.ndarray( 2, x, 1, 0, y, 2, 1, param ); |
| 105 | +// x => <Float32Array>[ ~-20.0, ~-25.0, 3.0, 4.0, 5.0 ] |
| 106 | +// y => <Float32Array>[ 6.0, ~9.0, 8.0, ~13.0, 10.0 ] |
| 107 | +``` |
| 108 | + |
| 109 | +The function has the following additional parameters: |
| 110 | + |
| 111 | +- **offsetX**: starting index for `x`. |
| 112 | +- **offsetY**: starting index for `y`. |
| 113 | + |
| 114 | +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, to apply a modified Givens plane rotation to every other element starting from the second element, |
| 115 | + |
| 116 | +```javascript |
| 117 | +var Float32Array = require( '@stdlib/array/float32' ); |
| 118 | + |
| 119 | +var x = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 120 | +var y = new Float32Array( [ 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); |
| 121 | +var param = new Float32Array( [ 0.0, 0.0, 2.0, -3.0, 0.0 ] ); |
| 122 | + |
| 123 | +srotm.ndarray( 3, x, 2, 1, y, 2, 1, param ); |
| 124 | +// x => <Float32Array>[ 1.0, ~-22.0, 3.0, ~-26.0, 5.0, ~-30.0 ] |
| 125 | +// y => <Float32Array>[ 7.0, ~12.0, 9.0, ~18.0, 11.0, ~24.0 ] |
| 126 | +``` |
| 127 | + |
| 128 | +</section> |
| 129 | + |
| 130 | +<!-- /.usage --> |
| 131 | + |
| 132 | +<section class="notes"> |
| 133 | + |
| 134 | +## Notes |
| 135 | + |
| 136 | +- If `N <= 0`, both functions leave `x` and `y` unchanged. |
| 137 | +- `srotm()` corresponds to the [BLAS][blas] level 1 function [`srotm`][srotm]. |
| 138 | + |
| 139 | +</section> |
| 140 | + |
| 141 | +<!-- /.notes --> |
| 142 | + |
| 143 | +<section class="examples"> |
| 144 | + |
| 145 | +## Examples |
| 146 | + |
| 147 | +<!-- eslint no-undef: "error" --> |
| 148 | + |
| 149 | +```javascript |
| 150 | +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); |
| 151 | +var srotm = require( '@stdlib/blas/base/srotm' ); |
| 152 | + |
| 153 | +var opts = { |
| 154 | + 'dtype': 'float32' |
| 155 | +}; |
| 156 | +var x = discreteUniform( 10, 0, 500, opts ); |
| 157 | +console.log( x ); |
| 158 | + |
| 159 | +var y = discreteUniform( x.length, 0, 255, opts ); |
| 160 | +console.log( y ); |
| 161 | + |
| 162 | +var param = discreteUniform( 5, -5, 5, opts ); |
| 163 | +console.log( param ); |
| 164 | + |
| 165 | +// Apply a plane rotation: |
| 166 | +srotm( x.length, x, 1, y, 1, param ); |
| 167 | +console.log( x ); |
| 168 | +console.log( y ); |
| 169 | +``` |
| 170 | + |
| 171 | +</section> |
| 172 | + |
| 173 | +<!-- /.examples --> |
| 174 | + |
| 175 | +<!-- C interface documentation. --> |
| 176 | + |
| 177 | +* * * |
| 178 | + |
| 179 | +<section class="c"> |
| 180 | + |
| 181 | +## C APIs |
| 182 | + |
| 183 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 184 | + |
| 185 | +<section class="intro"> |
| 186 | + |
| 187 | +</section> |
| 188 | + |
| 189 | +<!-- /.intro --> |
| 190 | + |
| 191 | +<!-- C usage documentation. --> |
| 192 | + |
| 193 | +<section class="usage"> |
| 194 | + |
| 195 | +### Usage |
| 196 | + |
| 197 | +```c |
| 198 | +#include "stdlib/blas/base/srotm.h" |
| 199 | +``` |
| 200 | + |
| 201 | +#### c_srotm( N, \*X, strideX, \*Y, strideY, param ) |
| 202 | + |
| 203 | +Applies a modified Givens plane rotation. |
| 204 | + |
| 205 | +```c |
| 206 | +float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f }; |
| 207 | +float y[] = { 6.0f, 7.0f, 8.0f, 9.0f, 10.0f }; |
| 208 | +const float param[5] = { 0.0f, 0.0f, 2.0f, -3.0f, 0.0f }; |
| 209 | + |
| 210 | +c_srotm( 5, x, 1, y, 1, param ); |
| 211 | +``` |
| 212 | +
|
| 213 | +The function accepts the following arguments: |
| 214 | +
|
| 215 | +- **N**: `[in] CBLAS_INT` number of indexed elements. |
| 216 | +- **X**: `[inout] float*` first input array. |
| 217 | +- **strideX**: `[in] CBLAS_INT` index increment for `X`. |
| 218 | +- **Y**: `[inout] float*` second input array. |
| 219 | +- **strideY**: `[in] CBLAS_INT` index increment for `Y`. |
| 220 | +- **param**: `[in] float` parameters for the modified Givens transformation. |
| 221 | +
|
| 222 | +```c |
| 223 | +void c_srotm( const CBLAS_INT N, float *X, const CBLAS_INT strideX, float *Y, const CBLAS_INT strideY, const float *param ); |
| 224 | +``` |
| 225 | + |
| 226 | +</section> |
| 227 | + |
| 228 | +<!-- /.usage --> |
| 229 | + |
| 230 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 231 | + |
| 232 | +<section class="notes"> |
| 233 | + |
| 234 | +</section> |
| 235 | + |
| 236 | +<!-- /.notes --> |
| 237 | + |
| 238 | +<!-- C API usage examples. --> |
| 239 | + |
| 240 | +<section class="examples"> |
| 241 | + |
| 242 | +### Examples |
| 243 | + |
| 244 | +```c |
| 245 | +#include "stdlib/blas/base/srotm.h" |
| 246 | +#include <stdio.h> |
| 247 | + |
| 248 | +int main( void ) { |
| 249 | + // Create strided arrays: |
| 250 | + float x[] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f }; |
| 251 | + float y[] = { 6.0f, 7.0f, 8.0f, 9.0f, 10.0f }; |
| 252 | + |
| 253 | + // Specify the number of elements: |
| 254 | + const int N = 5; |
| 255 | + |
| 256 | + // Specify stride lengths: |
| 257 | + const int strideX = 1; |
| 258 | + const int strideY = 1; |
| 259 | + |
| 260 | + // Specify parameters for the modified Givens transformation: |
| 261 | + const float param[5] = { 0.0f, 0.0f, 2.0f, -3.0f, 0.0f }; |
| 262 | + |
| 263 | + // Apply plane rotation: |
| 264 | + c_srotm( N, x, strideX, y, strideY, param ); |
| 265 | + |
| 266 | + // Print the result: |
| 267 | + for ( int i = 0; i < 5; i++ ) { |
| 268 | + printf( "x[ %i ] = %f, y[ %i ] = %f\n", i, x[ i ], i, y[ i ] ); |
| 269 | + } |
| 270 | +} |
| 271 | +``` |
| 272 | +
|
| 273 | +</section> |
| 274 | +
|
| 275 | +<!-- /.examples --> |
| 276 | +
|
| 277 | +</section> |
| 278 | +
|
| 279 | +<!-- /.c --> |
| 280 | +
|
| 281 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 282 | +
|
| 283 | +<section class="related"> |
| 284 | +
|
| 285 | +</section> |
| 286 | +
|
| 287 | +<!-- /.related --> |
| 288 | +
|
| 289 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 290 | +
|
| 291 | +<section class="links"> |
| 292 | +
|
| 293 | +[blas]: http://www.netlib.org/blas |
| 294 | +
|
| 295 | +[srotm]: https://www.netlib.org/lapack/explore-html/d1/d45/group__rot_gae48ef017306866ac2d5a8c5a52617858.html#gae48ef017306866ac2d5a8c5a5261785 |
| 296 | +
|
| 297 | +[mdn-float32array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array |
| 298 | +
|
| 299 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 300 | +
|
| 301 | +</section> |
| 302 | +
|
| 303 | +<!-- /.links --> |
0 commit comments