|
| 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 | +# dlaswp |
| 22 | + |
| 23 | +> Perform a series of row interchanges on an input matrix. |
| 24 | +
|
| 25 | +<section class = "usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var dlaswp = require( '@stdlib/lapack/base/dlaswp' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### dlaswp( N, A, LDA, k1, k2, IPIV, incx ) |
| 34 | + |
| 35 | +Perform a series of row interchanges on an input matrix `A` using pivot indices stored in `IPIV`. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var Int32Array = require( '@stdlib/array/int32' ); |
| 39 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 40 | + |
| 41 | +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] |
| 42 | +var IPIV = new Int32Array( [ 2, 0, 1 ] ); |
| 43 | + |
| 44 | +dlaswp( 'row-major', 2, A, 2, 0, 2, IPIV, 1 ); |
| 45 | +// A => <Float64Array>[ 3.0, 4.0, 1.0, 2.0, 5.0, 6.0 ] |
| 46 | +``` |
| 47 | + |
| 48 | +The function has the following parameters: |
| 49 | + |
| 50 | +- **order**: storage layout. |
| 51 | +- **N**: number of columns in `A`. |
| 52 | +- **A**: input matrix stored in linear memory as a [`Float64Array`][mdn-float64array]. |
| 53 | +- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). |
| 54 | +- **k1**: index of first row to interchange when `incx` is positive and the index of the last row to interchange when `incx` is negative. |
| 55 | +- **k2**: index of last row to interchange when `incx` is positive and the index of the first row to interchange when `incx` is negative. |
| 56 | +- **IPIV**: vector of pivot indices as an [`Int32Array`][mdn-int32array]. Must contain at least `k1+(k2-k1)*abs(incx)` elements. Only the elements in positions `k1` through `k1+(k2-k1)*abs(incx)` are accessed. |
| 57 | +- **incx**: increment between successive values of `IPIV`. Elements from `IPIV` are accessed according to `IPIV[k1+(k-k1)*abs(incx)] = j`, thus implying that rows `k` and `j` should be interchanged. If `incx` is negative, the pivots are applied in reverse order. |
| 58 | + |
| 59 | +The sign of the increment parameter `incx` determines the order in which pivots are applied. For example, to apply pivots in reverse order, |
| 60 | + |
| 61 | +```javascript |
| 62 | +var Int32Array = require( '@stdlib/array/int32' ); |
| 63 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 64 | + |
| 65 | +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] |
| 66 | +var IPIV = new Int32Array( [ 2, 0, 1 ] ); |
| 67 | + |
| 68 | +dlaswp( 'row-major', 2, A, 2, 0, 2, IPIV, -1 ); |
| 69 | +// A => <Float64Array>[ 3.0, 4.0, 1.0, 2.0, 5.0, 6.0 ] |
| 70 | +``` |
| 71 | + |
| 72 | +To perform strided access over `IPIV`, provide an `abs(incx)` value greater than one. For example, to access every other element in `IPIV`, |
| 73 | + |
| 74 | +```javascript |
| 75 | +var Int32Array = require( '@stdlib/array/int32' ); |
| 76 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 77 | + |
| 78 | +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] |
| 79 | +var IPIV = new Int32Array( [ 2, 999, 0, 999, 1 ] ); |
| 80 | + |
| 81 | +dlaswp( 'row-major', 2, A, 2, 0, 2, IPIV, 2 ); |
| 82 | +// A => <Float64Array>[ 3.0, 4.0, 1.0, 2.0, 5.0, 6.0 ] |
| 83 | +``` |
| 84 | + |
| 85 | +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. |
| 86 | + |
| 87 | +<!-- eslint-disable stdlib/capitalized-comments --> |
| 88 | + |
| 89 | +```javascript |
| 90 | +var Int32Array = require( '@stdlib/array/int32' ); |
| 91 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 92 | + |
| 93 | +// Initial arrays... |
| 94 | +var A0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 95 | +var IPIV0 = new Int32Array( [ 0, 2, 0, 1] ); |
| 96 | + |
| 97 | +// Create offset views... |
| 98 | +var A1 = new Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 1st element |
| 99 | +var IPIV1 = new Int32Array( IPIV0.buffer, IPIV0.BYTES_PER_ELEMENT*1 ); // start at 1st element |
| 100 | + |
| 101 | +dlaswp( 'row-major', 2, A1, 2, 0, 2, IPIV1, 1 ); |
| 102 | +// A0 => <Float64Array>[ 0.0, 3.0, 4.0, 1.0, 2.0, 5.0, 6.0 ] |
| 103 | +``` |
| 104 | + |
| 105 | +#### dlaswp.ndarray( order, N, A, sa1, sa2, oa, k1, k2, inck, IPIV, si, oi ) |
| 106 | + |
| 107 | +Performs a series of row interchanges on the matrix `A` using pivot indices stored in `IPIV` and alternative indexing semantics. |
| 108 | + |
| 109 | +```javascript |
| 110 | +var Int32Array = require( '@stdlib/array/int32' ); |
| 111 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 112 | + |
| 113 | +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] |
| 114 | +var IPIV = new Int32Array( [ 2, 0, 1 ] ); |
| 115 | + |
| 116 | +dlaswp.ndarray( 'row-major', 2, A, 2, 1, 0, 0, 2, 1, IPIV, 1, 0 ); |
| 117 | +// A => <Float64Array>[ 3.0, 4.0, 1.0, 2.0, 5.0, 6.0 ] |
| 118 | +``` |
| 119 | + |
| 120 | +The function has the following additional parameters: |
| 121 | + |
| 122 | +- **order**: storage layout. |
| 123 | +- **N**: number of columns in `A`. |
| 124 | +- **A**: input matrix stored in linear memory as a [`Float64Array`][mdn-float64array]. |
| 125 | +- **sa1**: stride of the first dimension of `A`. |
| 126 | +- **sa2**: stride of the second dimension of `A`. |
| 127 | +- **oa**: starting index for `A`. |
| 128 | +- **k1**: index of first row to interchange when `inck` is positive and the index of the last row to interchange when `inck` is negative. |
| 129 | +- **k2**: index of last row to interchange when `inck` is positive and the index of the first row to interchange when `inck` is negative. |
| 130 | +- **inck**: direction in which to apply pivots (-1 to apply pivots in reverse order; otherwise, apply in provided order). |
| 131 | +- **IPIV**: vector of pivot indices as an [`Int32Array`][mdn-int32array]. |
| 132 | +- **si**: index increment for `IPIV`. |
| 133 | +- **oi**: starting index for `IPIV`. |
| 134 | + |
| 135 | +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, |
| 136 | + |
| 137 | +<!-- eslint-disable max-len --> |
| 138 | + |
| 139 | +```javascript |
| 140 | +var Int32Array = require( '@stdlib/array/int32' ); |
| 141 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 142 | + |
| 143 | +var A = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 144 | +var IPIV = new Int32Array( [ 0, 0, 2, 0, 1 ] ); |
| 145 | + |
| 146 | +dlaswp.ndarray( 'row-major', 2, A, 2, 1, 4, 0, 2, 1, IPIV, 1, 2 ); |
| 147 | +// A => <Float64Array>[ 0.0, 0.0, 0.0, 0.0, 3.0, 4.0, 1.0, 2.0, 5.0, 6.0 ] |
| 148 | +``` |
| 149 | + |
| 150 | +</section> |
| 151 | + |
| 152 | +<!-- /.usage --> |
| 153 | + |
| 154 | +<section class="notes"> |
| 155 | + |
| 156 | +## Notes |
| 157 | + |
| 158 | +- Both functions access `k2-k1+1` elements from `IPIV`. |
| 159 | +- While `dlaswp` conflates the order in which pivots are applied with the order in which elements in `IPIV` are accessed, the `ndarray` method delineates control of those behaviors with separate parameters `inck` and `si`. |
| 160 | +- `dlaswp()` corresponds to the [LAPACK][LAPACK] level 1 function [`dlaswp`][dlaswp]. |
| 161 | + |
| 162 | +</section> |
| 163 | + |
| 164 | +<!-- /.notes --> |
| 165 | + |
| 166 | +<section class="examples"> |
| 167 | + |
| 168 | +## Examples |
| 169 | + |
| 170 | +<!-- eslint no-undef: "error" --> |
| 171 | + |
| 172 | +```javascript |
| 173 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 174 | +var Int32Array = require( '@stdlib/array/int32' ); |
| 175 | +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); |
| 176 | +var dlaswp = require( '@stdlib/lapack/base/dlaswp' ); |
| 177 | + |
| 178 | +// Specify matrix meta data: |
| 179 | +var shape = [ 4, 2 ]; |
| 180 | +var strides = [ 1, 4 ]; |
| 181 | +var offset = 0; |
| 182 | +var order = 'column-major'; |
| 183 | + |
| 184 | +// Create a matrix stored in linear memory: |
| 185 | +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ); |
| 186 | +console.log( ndarray2array( A, shape, strides, offset, order ) ); |
| 187 | + |
| 188 | +// Define a vector of pivot indices: |
| 189 | +var IPIV = new Int32Array( [ 2, 0, 3, 1 ] ); |
| 190 | + |
| 191 | +// Interchange rows: |
| 192 | +dlaswp( order, shape[ 1 ], A, strides[ 1 ], 0, shape[ 0 ]-1, IPIV, 1 ); |
| 193 | +console.log( ndarray2array( A, shape, strides, offset, order ) ); |
| 194 | +``` |
| 195 | + |
| 196 | +</section> |
| 197 | + |
| 198 | +<!-- /.examples --> |
| 199 | + |
| 200 | +<!-- C interface documentation. --> |
| 201 | + |
| 202 | +* * * |
| 203 | + |
| 204 | +<section class="c"> |
| 205 | + |
| 206 | +## C APIs |
| 207 | + |
| 208 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 209 | + |
| 210 | +<section class="intro"> |
| 211 | + |
| 212 | +</section> |
| 213 | + |
| 214 | +<!-- /.intro --> |
| 215 | + |
| 216 | +<!-- C usage documentation. --> |
| 217 | + |
| 218 | +<section class="usage"> |
| 219 | + |
| 220 | +### Usage |
| 221 | + |
| 222 | +```c |
| 223 | +TODO |
| 224 | +``` |
| 225 | + |
| 226 | +#### TODO |
| 227 | + |
| 228 | +TODO. |
| 229 | + |
| 230 | +```c |
| 231 | +TODO |
| 232 | +``` |
| 233 | + |
| 234 | +TODO |
| 235 | + |
| 236 | +```c |
| 237 | +TODO |
| 238 | +``` |
| 239 | + |
| 240 | +</section> |
| 241 | + |
| 242 | +<!-- /.usage --> |
| 243 | + |
| 244 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 245 | + |
| 246 | +<section class="notes"> |
| 247 | + |
| 248 | +</section> |
| 249 | + |
| 250 | +<!-- /.notes --> |
| 251 | + |
| 252 | +<!-- C API usage examples. --> |
| 253 | + |
| 254 | +<section class="examples"> |
| 255 | + |
| 256 | +### Examples |
| 257 | + |
| 258 | +```c |
| 259 | +TODO |
| 260 | +``` |
| 261 | + |
| 262 | +</section> |
| 263 | + |
| 264 | +<!-- /.examples --> |
| 265 | + |
| 266 | +</section> |
| 267 | + |
| 268 | +<!-- /.c --> |
| 269 | + |
| 270 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 271 | + |
| 272 | +<section class="related"> |
| 273 | + |
| 274 | +</section> |
| 275 | + |
| 276 | +<!-- /.related --> |
| 277 | + |
| 278 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 279 | + |
| 280 | +<section class="links"> |
| 281 | + |
| 282 | +[lapack]: https://www.netlib.org/lapack/explore-html/ |
| 283 | + |
| 284 | +[dlaswp]: https://www.netlib.org/lapack/explore-html/d7/d6b/dlaswp_8f_source.html |
| 285 | + |
| 286 | +[mdn-float64array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array |
| 287 | + |
| 288 | +[mdn-int32array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array |
| 289 | + |
| 290 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 291 | + |
| 292 | +</section> |
| 293 | + |
| 294 | +<!-- /.links --> |
0 commit comments