|
| 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 | +# dlange |
| 22 | + |
| 23 | +> Compute an `LU` factorization of a real tridiagonal matrix `A` using elimination with partial pivoting and row interchanges. |
| 24 | +
|
| 25 | +<section class="intro"> |
| 26 | + |
| 27 | +The `dlange` routine computes the value of a specified norm of a real M-by-N matrix `A`. The norm to be computed is selected using the parameter `norm`, which may specify the **Max norm**, **One norm**, **Infinity norm**, or **Frobenius norm**. |
| 28 | + |
| 29 | +The supported norms are: |
| 30 | + |
| 31 | +- **Max Absolute Value** (`norm` = `'max'`): returns the largest absolute element in `A`. |
| 32 | + |
| 33 | +<!-- <equation class="equation" label="eq:lu_decomposition" align="center" raw="\|A\|_{\max} = \max_{i,j} |a_{i,j}|" alt="Maximum absolute value of a matrix."> --> |
| 34 | + |
| 35 | +```math |
| 36 | +\|A\|_{\max} = \max_{i,j} |a_{i,j}| |
| 37 | +``` |
| 38 | + |
| 39 | +<!-- </equation> --> |
| 40 | + |
| 41 | +- **One Norm** (`norm` = `'one'`): returns the maximum absolute column sum in `A`. |
| 42 | + |
| 43 | +<!-- <equation class="equation" label="eq:lu_decomposition" align="center" raw="\|A\|_1 = \max_j \sum_{i=1}^M |a_{i,j}|" alt="Definition of one norm of a matrix."> --> |
| 44 | + |
| 45 | +```math |
| 46 | +\|A\|_1 = \max_j \sum_{i=1}^M |a_{i,j}| |
| 47 | +``` |
| 48 | + |
| 49 | +<!-- </equation> --> |
| 50 | + |
| 51 | +- **Infinity Norm** (`norm` = `'infinity'`): returns the maximum absolute row sum in `A`. |
| 52 | + |
| 53 | +<!-- <equation class="equation" label="eq:lu_decomposition" align="center" raw="\|A\|_{\infty} = \max_i \sum_{j=1}^N |a_{i,j}|" alt="Definition of infinity norm of a matrix."> --> |
| 54 | + |
| 55 | +```math |
| 56 | +\|A\|_{\infty} = \max_i \sum_{j=1}^N |a_{i,j}| |
| 57 | +``` |
| 58 | + |
| 59 | +<!-- </equation> --> |
| 60 | + |
| 61 | +- **Frobenius Norm** (`norm` = `'frobenius'`): returns the square root of the sum of the squares of all elements in `A`. |
| 62 | + |
| 63 | +<!-- <equation class="equation" label="eq:lu_decomposition" align="center" raw="\|A\|_F = \left(\sum_{i=1}^M \sum_{j=1}^N |a_{i,j}|^2 \right)^{1/2}" alt="Definition of frobenius norm of a matrix."> --> |
| 64 | + |
| 65 | +```math |
| 66 | +\|A\|_F = \left(\sum_{i=1}^M \sum_{j=1}^N |a_{i,j}|^2 \right)^{1/2} |
| 67 | +``` |
| 68 | + |
| 69 | +<!-- </equation> --> |
| 70 | + |
| 71 | +</section> |
| 72 | + |
| 73 | +<!-- /.intro --> |
| 74 | + |
| 75 | +<section class="usage"> |
| 76 | + |
| 77 | +## Usage |
| 78 | + |
| 79 | +```javascript |
| 80 | +var dlange = require( '@stdlib/lapack/base/dlange' ); |
| 81 | +``` |
| 82 | + |
| 83 | +#### dlange( N, DL, D, DU, DU2, IPIV ) |
| 84 | + |
| 85 | +Computes the value of the one norm, or the frobenius norm, or the infinity norm, or the element with the largest absolute value of a real matrix `A`. |
| 86 | + |
| 87 | +<!-- eslint-disable max-len --> |
| 88 | + |
| 89 | +```javascript |
| 90 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 91 | + |
| 92 | +var A = new Float64Array( [ 1.0, 4.0, 7.0, 10.0, 2.0, 5.0, 8.0, 11.0, 3.0, 6.0, 9.0, 12.0 ] ); |
| 93 | + |
| 94 | +/* |
| 95 | + A = [ |
| 96 | + [ 1.0, 4.0, 7.0, 10.0 ], |
| 97 | + [ 2.0, 5.0, 8.0, 11.0 ], |
| 98 | + [ 3.0, 6.0, 9.0, 12.0 ] |
| 99 | + ] |
| 100 | +*/ |
| 101 | + |
| 102 | +var work = new Float64Array( 3 ); |
| 103 | +var out = dlange( 'row-major', 'frobenius', 3, 4, A, 4, work ); |
| 104 | +// returns ~25.5 |
| 105 | +``` |
| 106 | + |
| 107 | +The function has the following parameters: |
| 108 | + |
| 109 | +- **order**: storage layout. |
| 110 | +- **norm**: specifies the type of norm to be calculated, should be one of the following: `max`, `one`, `frobenius` or `infinity`. |
| 111 | +- **M**: number of rows in `A`. |
| 112 | +- **N**: number of columns in `A`. |
| 113 | +- **A**: input [`Float64Array`][mdn-float64array]. |
| 114 | +- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). |
| 115 | +- **work**: [`Float64Array`][mdn-float64array] used to compute the infinity norm, should have `M` indexed elements if computing the infinity norm otherwise it's fine to pass a dummy array. |
| 116 | + |
| 117 | +Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. |
| 118 | + |
| 119 | +<!-- eslint-disable stdlib/capitalized-comments, max-len --> |
| 120 | + |
| 121 | +```javascript |
| 122 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 123 | + |
| 124 | +var A0 = new Float64Array( [ 0.0, 1.0, 4.0, 7.0, 10.0, 2.0, 5.0, 8.0, 11.0, 3.0, 6.0, 9.0, 12.0 ] ); |
| 125 | +var work0 = new Float64Array( 4 ); |
| 126 | + |
| 127 | +/* |
| 128 | + A = [ |
| 129 | + [ 1.0, 4.0, 7.0, 10.0 ], |
| 130 | + [ 2.0, 5.0, 8.0, 11.0 ], |
| 131 | + [ 3.0, 6.0, 9.0, 12.0 ] |
| 132 | + ] |
| 133 | +*/ |
| 134 | + |
| 135 | +// Create offset views... |
| 136 | +var A = new Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 137 | +var work = new Float64Array( work0.buffer, work0.BYTES_PER_ELEMENT*1 ); // start at 2nd element |
| 138 | + |
| 139 | +var out = dlange( 'row-major', 'frobenius', 3, 4, A, 4, work ); |
| 140 | +// returns ~25.5 |
| 141 | +``` |
| 142 | + |
| 143 | +<!-- lint disable maximum-heading-length --> |
| 144 | + |
| 145 | +#### dlange.ndarray( norm, A, strideA1, strideA2, offsetA, work, strideWork, offsetWork ) |
| 146 | + |
| 147 | +Computes the value of the one norm, or the frobenius norm, or the infinity norm, or the element with the largest absolute value of a real matrix `A` using alternative indexing semantics. |
| 148 | + |
| 149 | +<!-- eslint-disable max-len --> |
| 150 | + |
| 151 | +```javascript |
| 152 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 153 | + |
| 154 | +var A = new Float64Array( [ 1.0, 4.0, 7.0, 10.0, 2.0, 5.0, 8.0, 11.0, 3.0, 6.0, 9.0, 12.0 ] ); |
| 155 | + |
| 156 | +/* |
| 157 | + A = [ |
| 158 | + [ 1.0, 4.0, 7.0, 10.0 ], |
| 159 | + [ 2.0, 5.0, 8.0, 11.0 ], |
| 160 | + [ 3.0, 6.0, 9.0, 12.0 ] |
| 161 | + ] |
| 162 | +*/ |
| 163 | + |
| 164 | +var work = new Float64Array( 3 ); |
| 165 | +var out = dlange.ndarray( 'frobenius', 3, 4, A, 4, 1, 0, work, 1, 0 ); |
| 166 | +// returns ~25.5 |
| 167 | +``` |
| 168 | + |
| 169 | +The function has the following additional parameters: |
| 170 | + |
| 171 | +- **norm**: specifies the type of norm to be calculated, should be one of the following: `max`, `one`, `frobenius` or `infinity`. |
| 172 | +- **M**: number of rows in `A`. |
| 173 | +- **N**: number of columns in `A`. |
| 174 | +- **A**: input [`Float64Array`][mdn-float64array]. |
| 175 | +- **strideA1**: stride of the first dimension of `A`. |
| 176 | +- **strideA2**: stride of the second dimension of `A`. |
| 177 | +- **offsetA**: starting index for `A`. |
| 178 | +- **work**: [`Float64Array`][mdn-float64array] used to compute the infinity norm, should have `M` indexed elements if computing the infinity norm otherwise it's fine to pass a dummy array. |
| 179 | +- **strideWork**: stride length of `work`. |
| 180 | +- **offsetWork**: starting index of `work`. |
| 181 | + |
| 182 | +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, |
| 183 | + |
| 184 | +<!-- eslint-disable max-len --> |
| 185 | + |
| 186 | +```javascript |
| 187 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 188 | + |
| 189 | +var A = new Float64Array( [ 0.0, 1.0, 4.0, 7.0, 10.0, 2.0, 5.0, 8.0, 11.0, 3.0, 6.0, 9.0, 12.0 ] ); |
| 190 | + |
| 191 | +/* |
| 192 | + A = [ |
| 193 | + [ 1.0, 4.0, 7.0, 10.0 ], |
| 194 | + [ 2.0, 5.0, 8.0, 11.0 ], |
| 195 | + [ 3.0, 6.0, 9.0, 12.0 ] |
| 196 | + ] |
| 197 | +*/ |
| 198 | + |
| 199 | +var work = new Float64Array( 4 ); |
| 200 | +var out = dlange.ndarray( 'frobenius', 3, 4, A, 4, 1, 1, work, 1, 1 ); |
| 201 | +// returns ~25.5 |
| 202 | +``` |
| 203 | + |
| 204 | +</section> |
| 205 | + |
| 206 | +<!-- /.usage --> |
| 207 | + |
| 208 | +<section class="notes"> |
| 209 | + |
| 210 | +## Notes |
| 211 | + |
| 212 | +- `dlange()` corresponds to the [LAPACK][LAPACK] routine [`dlange`][lapack-dlange]. |
| 213 | + |
| 214 | +</section> |
| 215 | + |
| 216 | +<!-- /.notes --> |
| 217 | + |
| 218 | +<section class="examples"> |
| 219 | + |
| 220 | +## Examples |
| 221 | + |
| 222 | +<!-- eslint no-undef: "error" --> |
| 223 | + |
| 224 | +```javascript |
| 225 | +var Float64Array = require( '@stdlib/array/float64' ); |
| 226 | +var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); |
| 227 | +var uniform = require( '@stdlib/random/array/uniform' ); |
| 228 | +var numel = require( '@stdlib/ndarray/base/numel' ); |
| 229 | +var dlange = require( '@stdlib/lapack/base/dlange' ); |
| 230 | + |
| 231 | +// Specify matrix meta data: |
| 232 | +var shape = [ 3, 4 ]; |
| 233 | +var strides = [ 4, 1 ]; |
| 234 | +var offset = 0; |
| 235 | +var N = numel( shape ); |
| 236 | +var order = 'row-major'; |
| 237 | + |
| 238 | +// Create a matrix stored in linear memory: |
| 239 | +var A = uniform( N, -10, 10, { |
| 240 | + 'dtype': 'float64' |
| 241 | +}); |
| 242 | +console.log( ndarray2array( A, shape, strides, offset, order ) ); |
| 243 | + |
| 244 | +var work = new Float64Array( shape[ 0 ] ); |
| 245 | + |
| 246 | +// Calculate the infinity norm: |
| 247 | +var out = dlange( order, 'infinity', shape[ 0 ], shape[ 1 ], A, strides[ 0 ], work ); |
| 248 | +console.log( 'Infinity norm: ', out ); |
| 249 | +``` |
| 250 | + |
| 251 | +</section> |
| 252 | + |
| 253 | +<!-- /.examples --> |
| 254 | + |
| 255 | +<!-- C interface documentation. --> |
| 256 | + |
| 257 | +* * * |
| 258 | + |
| 259 | +<section class="c"> |
| 260 | + |
| 261 | +## C APIs |
| 262 | + |
| 263 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 264 | + |
| 265 | +<section class="intro"> |
| 266 | + |
| 267 | +</section> |
| 268 | + |
| 269 | +<!-- /.intro --> |
| 270 | + |
| 271 | +<!-- C usage documentation. --> |
| 272 | + |
| 273 | +<section class="usage"> |
| 274 | + |
| 275 | +### Usage |
| 276 | + |
| 277 | +```c |
| 278 | +TODO |
| 279 | +``` |
| 280 | + |
| 281 | +#### TODO |
| 282 | + |
| 283 | +TODO. |
| 284 | + |
| 285 | +```c |
| 286 | +TODO |
| 287 | +``` |
| 288 | + |
| 289 | +TODO |
| 290 | + |
| 291 | +```c |
| 292 | +TODO |
| 293 | +``` |
| 294 | + |
| 295 | +</section> |
| 296 | + |
| 297 | +<!-- /.usage --> |
| 298 | + |
| 299 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 300 | + |
| 301 | +<section class="notes"> |
| 302 | + |
| 303 | +</section> |
| 304 | + |
| 305 | +<!-- /.notes --> |
| 306 | + |
| 307 | +<!-- C API usage examples. --> |
| 308 | + |
| 309 | +<section class="examples"> |
| 310 | + |
| 311 | +### Examples |
| 312 | + |
| 313 | +```c |
| 314 | +TODO |
| 315 | +``` |
| 316 | + |
| 317 | +</section> |
| 318 | + |
| 319 | +<!-- /.examples --> |
| 320 | + |
| 321 | +</section> |
| 322 | + |
| 323 | +<!-- /.c --> |
| 324 | + |
| 325 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 326 | + |
| 327 | +<section class="related"> |
| 328 | + |
| 329 | +</section> |
| 330 | + |
| 331 | +<!-- /.related --> |
| 332 | + |
| 333 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 334 | + |
| 335 | +<section class="links"> |
| 336 | + |
| 337 | +[lapack]: https://www.netlib.org/lapack/explore-html/ |
| 338 | + |
| 339 | +[lapack-dlange]: https://www.netlib.org/lapack/explore-html/d8/d2e/group__lange_ga8581d687290b36c6e24fe76b3be7caa3.html |
| 340 | + |
| 341 | +[mdn-float64array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array |
| 342 | + |
| 343 | +[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray |
| 344 | + |
| 345 | +</section> |
| 346 | + |
| 347 | +<!-- /.links --> |
0 commit comments