|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 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 | +# dorg2r |
| 22 | + |
| 23 | +> LAPACK routine to generate an M-by-N real matrix Q with orthonormal columns. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var dorg2r = require( '@stdlib/lapack/base/dorg2r' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### dorg2r( order, M, N, K, A, LDA, tau, work ) |
| 34 | + |
| 35 | +Generates an M-by-N real matrix Q with orthonormal columns. The matrix Q is defined as the first N columns of a product of K elementary reflectors of order M. `Q = H(1) H(2) . . . H(K)` as returned by `dgeqrf`. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 39 | + |
| 40 | +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 41 | +var tau = new Float64Array( [ 0.0, 0.0 ] ); |
| 42 | +var work = new Float64Array( 10 ); |
| 43 | + |
| 44 | +dorg2r( 'column-major', 3, 2, 2, A, 3, tau, work ); |
| 45 | +// A => <Float64Array>[ 1.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] |
| 46 | +``` |
| 47 | + |
| 48 | +The function has the following parameters: |
| 49 | + |
| 50 | +- **order**: storage layout. |
| 51 | +- **M**: number of rows in matrix `A`. |
| 52 | +- **N**: number of columns in matrix `A`. |
| 53 | +- **K**: number of elementary reflectors whose product defines the matrix Q. |
| 54 | +- **A**: input matrix (overwritten by Householder vectors from `dgeqrf`) stored in linear memory as a [`Float64Array`][mdn-float64array]. |
| 55 | +- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). |
| 56 | +- **tau**: vector of K scalar factors of the elementary reflectors as a [`Float64Array`][mdn-float64array]. |
| 57 | +- **work**: workspace array as a [`Float64Array`][mdn-float64array]. |
| 58 | + |
| 59 | +The function returns the input matrix `A` overwritten with the orthogonal matrix Q. |
| 60 | + |
| 61 | +#### dorg2r.ndarray( M, N, K, A, sa1, sa2, oa, tau, st, ot, work, sw, ow ) |
| 62 | + |
| 63 | +Generates an M-by-N real matrix Q with orthonormal columns using alternative indexing semantics. The matrix Q is defined as the first N columns of a product of K elementary reflectors of order M. `Q = H(1) H(2) . . . H(K)` as returned by `dgeqrf`. |
| 64 | + |
| 65 | +```javascript |
| 66 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 67 | + |
| 68 | +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 69 | +var tau = new Float64Array( [ 0.0, 0.0 ] ); |
| 70 | +var work = new Float64Array( 10 ); |
| 71 | + |
| 72 | +dorg2r.ndarray( 3, 2, 2, A, 1, 3, 0, tau, 1, 0, work, 1, 0 ); |
| 73 | +// A => <Float64Array>[ 1.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] |
| 74 | +``` |
| 75 | + |
| 76 | +The function has the following additional parameters: |
| 77 | + |
| 78 | +- **M**: number of rows in matrix `A`. |
| 79 | +- **N**: number of columns in matrix `A`. |
| 80 | +- **K**: number of elementary reflectors whose product defines the matrix Q. |
| 81 | +- **A**: input matrix (overwritten by Householder vectors from `dgeqrf`) stored in linear memory as a [`Float64Array`][mdn-float64array]. |
| 82 | +- **sa1**: stride of the first dimension of `A`. |
| 83 | +- **sa2**: stride of the second dimension of `A`. |
| 84 | +- **oa**: index offset for `A`. |
| 85 | +- **tau**: vector of K scalar factors of the elementary reflectors as a [`Float64Array`][mdn-float64array]. |
| 86 | +- **st**: stride length for `tau`. |
| 87 | +- **ot**: index offset for `tau`. |
| 88 | +- **work**: workspace array as a [`Float64Array`][mdn-float64array]. |
| 89 | +- **sw**: stride length for `work`. |
| 90 | +- **ow**: index offset for `work`. |
| 91 | + |
| 92 | +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, |
| 93 | + |
| 94 | +<!-- eslint-disable max-len --> |
| 95 | + |
| 96 | +```javascript |
| 97 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 98 | + |
| 99 | +var A = new Float64Array( [ 0.0, 0.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); |
| 100 | +var tau = new Float64Array( [ 0.0, 0.0, 0.0, 0.0 ] ); |
| 101 | +var work = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); |
| 102 | + |
| 103 | +dorg2r.ndarray( 3, 2, 2, A, 1, 3, 3, tau, 1, 2, work, 1, 0 ); |
| 104 | +// A => <Float64Array>[ 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0 ] |
| 105 | +``` |
| 106 | + |
| 107 | +</section> |
| 108 | + |
| 109 | +<!-- /.usage --> |
| 110 | + |
| 111 | +<section class="notes"> |
| 112 | + |
| 113 | +## Notess |
| 114 | + |
| 115 | +- The function overwrites the input matrix `A` with the orthogonal matrix `Q`. |
| 116 | +- The matrix Q is generated from the Householder vectors and scalar factors returned by `dgeqrf`. |
| 117 | +- `dorg2r()` corresponds to the [LAPACK][LAPACK] function [`dorg2r`][lapack-dorg2r]. |
| 118 | + |
| 119 | +</section> |
| 120 | + |
| 121 | +<!-- /.notes --> |
| 122 | + |
| 123 | +<section class="examples"> |
| 124 | + |
| 125 | +## Examples |
| 126 | + |
| 127 | +<!-- eslint no-undef: "error" --> |
| 128 | + |
| 129 | +<!-- eslint-disable max-len --> |
| 130 | + |
| 131 | +```javascript |
| 132 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 133 | +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); |
| 134 | +var dorg2r = require( '@stdlib/lapack/base/dorg2r' ); |
| 135 | + |
| 136 | +// Specify matrix meta data: |
| 137 | +var M = 4; |
| 138 | +var N = 3; |
| 139 | +var K = 2; |
| 140 | + |
| 141 | +// Create a matrix stored in linear memory: |
| 142 | +var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); |
| 143 | +console.log( 'Original matrix A containing Householder vectors:' ); |
| 144 | +console.log( ndarray2array( A, [ M, N ], [ 1, M ], 0, 'column-major' ) ); |
| 145 | + |
| 146 | +// Define scalar factors of the elementary reflectors: |
| 147 | +var tau = new Float64Array( [ 1.2, 0.8 ] ); |
| 148 | + |
| 149 | +// Create workspace array: |
| 150 | +var work = new Float64Array( N ); |
| 151 | + |
| 152 | +// Generate the orthogonal matrix Q: |
| 153 | +dorg2r( 'column-major', M, N, K, A, M, tau, work ); |
| 154 | +console.log( 'Resulting orthogonal matrix Q:' ); |
| 155 | +console.log( ndarray2array( A, [ M, N ], [ 1, M ], 0, 'column-major' ) ); |
| 156 | +``` |
| 157 | + |
| 158 | +</section> |
| 159 | + |
| 160 | +<!-- /.examples --> |
| 161 | + |
| 162 | +<!-- C interface documentation. --> |
| 163 | + |
| 164 | +* * * |
| 165 | + |
| 166 | +<section class="c"> |
| 167 | + |
| 168 | +## C APIs |
| 169 | + |
| 170 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 171 | + |
| 172 | +<section class="intro"> |
| 173 | + |
| 174 | +</section> |
| 175 | + |
| 176 | +<!-- /.intro --> |
| 177 | + |
| 178 | +<!-- C usage documentation. --> |
| 179 | + |
| 180 | +<section class="usage"> |
| 181 | + |
| 182 | +### Usage |
| 183 | + |
| 184 | +```c |
| 185 | +TODO |
| 186 | +``` |
| 187 | + |
| 188 | +#### TODO |
| 189 | + |
| 190 | +TODO. |
| 191 | + |
| 192 | +```c |
| 193 | +TODO |
| 194 | +``` |
| 195 | + |
| 196 | +TODO |
| 197 | + |
| 198 | +```c |
| 199 | +TODO |
| 200 | +``` |
| 201 | + |
| 202 | +</section> |
| 203 | + |
| 204 | +<!-- /.usage --> |
| 205 | + |
| 206 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 207 | + |
| 208 | +<section class="notes"> |
| 209 | + |
| 210 | +</section> |
| 211 | + |
| 212 | +<!-- /.notes --> |
| 213 | + |
| 214 | +<!-- C API usage examples. --> |
| 215 | + |
| 216 | +<section class="examples"> |
| 217 | + |
| 218 | +### Examples |
| 219 | + |
| 220 | +```c |
| 221 | +TODO |
| 222 | +``` |
| 223 | + |
| 224 | +</section> |
| 225 | + |
| 226 | +<!-- /.examples --> |
| 227 | + |
| 228 | +</section> |
| 229 | + |
| 230 | +<!-- /.c --> |
| 231 | + |
| 232 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 233 | + |
| 234 | +<section class="related"> |
| 235 | + |
| 236 | +</section> |
| 237 | + |
| 238 | +<!-- /.related --> |
| 239 | + |
| 240 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 241 | + |
| 242 | +<section class="links"> |
| 243 | + |
| 244 | +[lapack]: https://www.netlib.org/lapack/explore-html/ |
| 245 | + |
| 246 | +[lapack-dorg2r]: https://netlib.org/lapack/explore-html/da/da2/group__ung2r_ga8877e79ab6e262ae7497f11d8534635c.html#ga8877e79ab6e262ae7497f11d8534635c |
| 247 | + |
| 248 | +[mdn-float64array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array |
| 249 | + |
| 250 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 251 | + |
| 252 | +</section> |
| 253 | + |
| 254 | +<!-- /.links --> |
0 commit comments