-
-
Notifications
You must be signed in to change notification settings - Fork 834
feat: add lapack/base/dlange
#7195
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
base: develop
Are you sure you want to change the base?
Changes from all commits
87ea9c0
a6a19f3
d51e004
5653d0f
861ec2c
3c69a60
df66e94
b895055
e5bd831
9883b18
2e8ed5c
bc63789
42175c0
5cbf09d
651c006
6e0d355
d0d96ed
fafa627
086fc3c
44c54a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,351 @@ | ||||||||||
<!-- | ||||||||||
|
||||||||||
@license Apache-2.0 | ||||||||||
|
||||||||||
Copyright (c) 2025 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. | ||||||||||
|
||||||||||
--> | ||||||||||
|
||||||||||
# dlange | ||||||||||
|
||||||||||
> LAPACK routine to compute 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`. | ||||||||||
|
||||||||||
<section class="intro"> | ||||||||||
|
||||||||||
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**. | ||||||||||
|
||||||||||
The supported norms are: | ||||||||||
|
||||||||||
- **Max Absolute Value** (`norm` = `'max'`): returns the largest absolute element in `A`. | ||||||||||
|
||||||||||
<!-- <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."> --> | ||||||||||
|
||||||||||
```math | ||||||||||
\|A\|_{\max} = \max_{i,j} |a_{i,j}| | ||||||||||
``` | ||||||||||
|
||||||||||
<!-- </equation> --> | ||||||||||
|
||||||||||
- **One Norm** (`norm` = `'one'`): returns the maximum absolute column sum in `A`. | ||||||||||
|
||||||||||
<!-- <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."> --> | ||||||||||
|
||||||||||
```math | ||||||||||
\|A\|_1 = \max_j \sum_{i=1}^M |a_{i,j}| | ||||||||||
``` | ||||||||||
|
||||||||||
<!-- </equation> --> | ||||||||||
|
||||||||||
- **Infinity Norm** (`norm` = `'infinity'`): returns the maximum absolute row sum in `A`. | ||||||||||
|
||||||||||
<!-- <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."> --> | ||||||||||
|
||||||||||
```math | ||||||||||
\|A\|_{\infty} = \max_i \sum_{j=1}^N |a_{i,j}| | ||||||||||
``` | ||||||||||
|
||||||||||
<!-- </equation> --> | ||||||||||
|
||||||||||
- **Frobenius Norm** (`norm` = `'frobenius'`): returns the square root of the sum of the squares of all elements in `A`. | ||||||||||
|
||||||||||
<!-- <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."> --> | ||||||||||
|
||||||||||
```math | ||||||||||
\|A\|_F = \left(\sum_{i=1}^M \sum_{j=1}^N |a_{i,j}|^2 \right)^{1/2} | ||||||||||
``` | ||||||||||
|
||||||||||
<!-- </equation> --> | ||||||||||
|
||||||||||
</section> | ||||||||||
|
||||||||||
<!-- /.intro --> | ||||||||||
|
||||||||||
<section class="usage"> | ||||||||||
|
||||||||||
## Usage | ||||||||||
|
||||||||||
```javascript | ||||||||||
var dlange = require( '@stdlib/lapack/base/dlange' ); | ||||||||||
``` | ||||||||||
|
||||||||||
#### dlange( norm, M, N, A, LDA, work ) | ||||||||||
|
||||||||||
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`. | ||||||||||
|
||||||||||
<!-- eslint-disable max-len --> | ||||||||||
|
||||||||||
```javascript | ||||||||||
var Float64Array = require( '@stdlib/array/float64' ); | ||||||||||
|
||||||||||
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 ] ); | ||||||||||
|
||||||||||
/* | ||||||||||
A = [ | ||||||||||
[ 1.0, 4.0, 7.0, 10.0 ], | ||||||||||
[ 2.0, 5.0, 8.0, 11.0 ], | ||||||||||
[ 3.0, 6.0, 9.0, 12.0 ] | ||||||||||
] | ||||||||||
*/ | ||||||||||
|
||||||||||
var work = new Float64Array( 3 ); | ||||||||||
var out = dlange( 'row-major', 'frobenius', 3, 4, A, 4, work ); | ||||||||||
// returns ~25.5 | ||||||||||
``` | ||||||||||
|
||||||||||
The function has the following parameters: | ||||||||||
|
||||||||||
- **order**: storage layout. | ||||||||||
- **norm**: specifies the type of norm to be calculated, should be one of the following: `max`, `one`, `frobenius` or `infinity`. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Oxford comma. |
||||||||||
- **M**: number of rows in `A`. | ||||||||||
- **N**: number of columns in `A`. | ||||||||||
- **A**: input [`Float64Array`][mdn-float64array]. | ||||||||||
- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). | ||||||||||
- **work**: [`Float64Array`][mdn-float64array] used as a temporary workspace. | ||||||||||
|
||||||||||
`work` should have `N` indexed elements if calculating the one norm in a row-major layout and `M` indexed elements if calculating the infinity norm in column-major layout, in all other cases it is fine to pass a dummy [`Float64Array`][mdn-float64array]. | ||||||||||
Comment on lines
+115
to
+117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views. | ||||||||||
|
||||||||||
<!-- eslint-disable stdlib/capitalized-comments, max-len --> | ||||||||||
|
||||||||||
```javascript | ||||||||||
var Float64Array = require( '@stdlib/array/float64' ); | ||||||||||
|
||||||||||
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 ] ); | ||||||||||
var work0 = new Float64Array( 4 ); | ||||||||||
|
||||||||||
/* | ||||||||||
A = [ | ||||||||||
[ 1.0, 4.0, 7.0, 10.0 ], | ||||||||||
[ 2.0, 5.0, 8.0, 11.0 ], | ||||||||||
[ 3.0, 6.0, 9.0, 12.0 ] | ||||||||||
] | ||||||||||
*/ | ||||||||||
|
||||||||||
// Create offset views... | ||||||||||
var A = new Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element | ||||||||||
var work = new Float64Array( work0.buffer, work0.BYTES_PER_ELEMENT*1 ); // start at 2nd element | ||||||||||
|
||||||||||
var out = dlange( 'row-major', 'frobenius', 3, 4, A, 4, work ); | ||||||||||
// returns ~25.5 | ||||||||||
``` | ||||||||||
|
||||||||||
<!-- lint disable maximum-heading-length --> | ||||||||||
|
||||||||||
#### dlange.ndarray( norm, A, strideA1, strideA2, offsetA, work, strideWork, offsetWork ) | ||||||||||
|
||||||||||
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. | ||||||||||
|
||||||||||
<!-- eslint-disable max-len --> | ||||||||||
|
||||||||||
```javascript | ||||||||||
var Float64Array = require( '@stdlib/array/float64' ); | ||||||||||
|
||||||||||
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 ] ); | ||||||||||
|
||||||||||
/* | ||||||||||
A = [ | ||||||||||
[ 1.0, 4.0, 7.0, 10.0 ], | ||||||||||
[ 2.0, 5.0, 8.0, 11.0 ], | ||||||||||
[ 3.0, 6.0, 9.0, 12.0 ] | ||||||||||
] | ||||||||||
*/ | ||||||||||
|
||||||||||
var work = new Float64Array( 3 ); | ||||||||||
var out = dlange.ndarray( 'frobenius', 3, 4, A, 4, 1, 0, work, 1, 0 ); | ||||||||||
// returns ~25.5 | ||||||||||
``` | ||||||||||
|
||||||||||
The function has the following additional parameters: | ||||||||||
|
||||||||||
- **norm**: specifies the type of norm to be calculated, should be one of the following: `max`, `one`, `frobenius` or `infinity`. | ||||||||||
- **M**: number of rows in `A`. | ||||||||||
- **N**: number of columns in `A`. | ||||||||||
- **A**: input [`Float64Array`][mdn-float64array]. | ||||||||||
- **strideA1**: stride of the first dimension of `A`. | ||||||||||
- **strideA2**: stride of the second dimension of `A`. | ||||||||||
- **offsetA**: starting index for `A`. | ||||||||||
- **work**: [`Float64Array`][mdn-float64array] used as a temporary workspace | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same changes as above. |
||||||||||
- **strideWork**: stride length of `work`. | ||||||||||
- **offsetWork**: starting index of `work`. | ||||||||||
|
||||||||||
`work` should have `N` indexed elements if calculating the one norm in a row-major layout and `M` indexed elements if calculating the infinity norm in column-major layout, in all other cases it is fine to pass a dummy [`Float64Array`][mdn-float64array]. | ||||||||||
|
||||||||||
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, | ||||||||||
|
||||||||||
<!-- eslint-disable max-len --> | ||||||||||
|
||||||||||
```javascript | ||||||||||
var Float64Array = require( '@stdlib/array/float64' ); | ||||||||||
|
||||||||||
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 ] ); | ||||||||||
|
||||||||||
/* | ||||||||||
A = [ | ||||||||||
[ 1.0, 4.0, 7.0, 10.0 ], | ||||||||||
[ 2.0, 5.0, 8.0, 11.0 ], | ||||||||||
[ 3.0, 6.0, 9.0, 12.0 ] | ||||||||||
] | ||||||||||
*/ | ||||||||||
|
||||||||||
var work = new Float64Array( 4 ); | ||||||||||
var out = dlange.ndarray( 'frobenius', 3, 4, A, 4, 1, 1, work, 1, 1 ); | ||||||||||
// returns ~25.5 | ||||||||||
``` | ||||||||||
|
||||||||||
</section> | ||||||||||
|
||||||||||
<!-- /.usage --> | ||||||||||
|
||||||||||
<section class="notes"> | ||||||||||
|
||||||||||
## Notes | ||||||||||
|
||||||||||
- `dlange()` corresponds to the [LAPACK][LAPACK] routine [`dlange`][lapack-dlange]. | ||||||||||
|
||||||||||
</section> | ||||||||||
|
||||||||||
<!-- /.notes --> | ||||||||||
|
||||||||||
<section class="examples"> | ||||||||||
|
||||||||||
## Examples | ||||||||||
|
||||||||||
<!-- eslint no-undef: "error" --> | ||||||||||
|
||||||||||
```javascript | ||||||||||
var Float64Array = require( '@stdlib/array/float64' ); | ||||||||||
var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); | ||||||||||
var uniform = require( '@stdlib/random/array/uniform' ); | ||||||||||
var numel = require( '@stdlib/ndarray/base/numel' ); | ||||||||||
var dlange = require( '@stdlib/lapack/base/dlange' ); | ||||||||||
|
||||||||||
// Specify matrix meta data: | ||||||||||
var shape = [ 3, 4 ]; | ||||||||||
var strides = [ 4, 1 ]; | ||||||||||
var offset = 0; | ||||||||||
var N = numel( shape ); | ||||||||||
var order = 'row-major'; | ||||||||||
|
||||||||||
// Create a matrix stored in linear memory: | ||||||||||
var A = uniform( N, -10, 10, { | ||||||||||
'dtype': 'float64' | ||||||||||
}); | ||||||||||
console.log( ndarray2array( A, shape, strides, offset, order ) ); | ||||||||||
|
||||||||||
var work = new Float64Array( shape[ 0 ] ); | ||||||||||
|
||||||||||
// Calculate the infinity norm: | ||||||||||
var out = dlange( order, 'infinity', shape[ 0 ], shape[ 1 ], A, strides[ 0 ], work ); | ||||||||||
console.log( 'Infinity norm: ', 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 | ||||||||||
TODO | ||||||||||
``` | ||||||||||
|
||||||||||
#### TODO | ||||||||||
|
||||||||||
TODO. | ||||||||||
|
||||||||||
```c | ||||||||||
TODO | ||||||||||
``` | ||||||||||
|
||||||||||
TODO | ||||||||||
|
||||||||||
```c | ||||||||||
TODO | ||||||||||
``` | ||||||||||
|
||||||||||
</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 | ||||||||||
TODO | ||||||||||
``` | ||||||||||
|
||||||||||
</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"> | ||||||||||
|
||||||||||
[lapack]: https://www.netlib.org/lapack/explore-html/ | ||||||||||
|
||||||||||
[lapack-dlange]: https://www.netlib.org/lapack/explore-html/d8/d2e/group__lange_ga8581d687290b36c6e24fe76b3be7caa3.html | ||||||||||
|
||||||||||
[mdn-float64array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array | ||||||||||
|
||||||||||
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray | ||||||||||
|
||||||||||
</section> | ||||||||||
|
||||||||||
<!-- /.links --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aayush0325 I think you need to update the label for this and the other equations. Each label should be unique. This appears to be a copy-paste mistake.