-
-
Notifications
You must be signed in to change notification settings - Fork 845
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
Open
aayush0325
wants to merge
24
commits into
stdlib-js:develop
Choose a base branch
from
aayush0325:lapack-dlange
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
87ea9c0
feat: add base implementation
aayush0325 a6a19f3
feat: add main exports
aayush0325 d51e004
test: add initial tests
aayush0325 5653d0f
test: add initial ndarray tests
aayush0325 861ec2c
refactor: pointer arithmetic
aayush0325 3c69a60
test: add all tests
aayush0325 df66e94
feat: add benchmarks and examples
aayush0325 b895055
docs: add index.d.ts
aayush0325 e5bd831
docs: add test.ts
aayush0325 9883b18
refactor: loop reordering
aayush0325 2e8ed5c
refactor: cleanup
aayush0325 bc63789
refactor: cleanup
aayush0325 42175c0
refactor: cleanup
aayush0325 5cbf09d
refactor: move branches to separate functions
aayush0325 651c006
refactor: better error messages
aayush0325 6e0d355
docs: add readme
aayush0325 d0d96ed
docs: add repl.txt
aayush0325 fafa627
refactor: optimise loops
aayush0325 086fc3c
refactor: optimise loops
aayush0325 44c54a9
docs: update docs
aayush0325 0689326
chore: cleaning up
aayush0325 bfe5443
refactor: use manual loops instead of loop reordering
aayush0325 078b545
chore: remove nested object
aayush0325 bdba98f
chore: cleanup
aayush0325 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. | ||
aayush0325 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- **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]. | ||
aayush0325 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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 | ||
aayush0325 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- **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 --> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.