-
-
Notifications
You must be signed in to change notification settings - Fork 851
feat: add blas/base/dtrsm
#2518
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
Closed
Closed
Changes from 17 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
2252453
feat: add blas/base/dtrsm/lib
Pranavchiku 12708a5
chore: apply suggestions from code review
Pranavchiku 4b951ba
enh: support offsetA and offsetB
Pranavchiku 5d0646d
fix: incorrect base implementation
Pranavchiku 4fe27b2
chore: add examples
Pranavchiku 510cc17
chore: add readme
Pranavchiku 6569dc8
chore: add package.json
Pranavchiku bc4f4c2
fix: incorrect readme example
Pranavchiku d121f15
chore: add repl.txt
Pranavchiku 6b3562f
chore: add docs/types
Pranavchiku 2f00ec3
chore: add benchmark
Pranavchiku 78d49ac
test: add and register
Pranavchiku 9ad1e43
enh: files in lib/
Pranavchiku 851ed80
fix: incorrect description of ndarray api in readme
Pranavchiku 93204fd
refactor: base implementation
Pranavchiku 86d36ca
fix: lint warnings in base.js
Pranavchiku df96605
chore: apply code review
Pranavchiku 8b7a997
fix: lint error in repl.txt part 1
Pranavchiku 4ff0296
Merge branch 'dtrsm' of https://github.com/Pranavchiku/stdlib into dtrsm
Pranavchiku 6ceef42
refactor: base implementation and consequent changes
Pranavchiku acc78cc
refactor: repl.txt
Pranavchiku 35db166
chore: apply suggestion from code review
Pranavchiku 48b8231
refactor: base implementation to compute offsets before loop
Pranavchiku 2eea9ee
chore: work in progress
Pranavchiku 53e44c9
Merge branch 'develop' into dtrsm
Pranavchiku 355a56e
refactor: remove fixtures
Pranavchiku 17b2671
refactor: remove fixtures from ndarray tests
Pranavchiku 9deb187
refactor: docs/repl.txt
Pranavchiku 5f3be19
chore: update description of tests
Pranavchiku 2bae813
chore: update description of ndarray tests
Pranavchiku b50078f
test: add tests for complex access patterns
Pranavchiku 7e295de
fix: incorrect spelling of contiguous
Pranavchiku 6585a6a
chore: apply suggestions from code review
Pranavchiku f710cd3
Merge branch 'develop' into dtrsm
Pranavchiku 03532e0
refactor: base implementation and consequent changes
Pranavchiku d0183d3
test: add more values
Pranavchiku 449f2d5
Merge branch 'dtrsm' of https://github.com/Pranavchiku/stdlib into dtrsm
Pranavchiku 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,247 @@ | ||
<!-- | ||
|
||
@license Apache-2.0 | ||
|
||
Copyright (c) 2024 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. | ||
|
||
--> | ||
|
||
# dtrsm | ||
|
||
> Solve matrix equation `op(A) * X = alpha * B` or `X * op(A) = alpha * B` where `alpha` is a scalar, `X` and `B` are m by n matrices, `A` is a unit, or non-unit, upper or lower triangular matrix and `op( A )` is one of `op( A ) = A` or `op( A ) = A ** T`. The matrix `X` is overwritten on `B`. | ||
|
||
<section class = "usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var dtrsm = require( '@stdlib/blas/base/dtrsm' ); | ||
``` | ||
|
||
#### dtrsm( order, side, uplo, transa, diag, m, n, alpha, A, LDA, B, LDB ) | ||
|
||
Solves matrix equation `op(A) * X = alpha * B` or `X * op(A) = alpha * B` where `alpha` is a scalar, `X` and `B` are m by n matrices, `A` is a unit, or non-unit, upper or lower triangular matrix and `op( A )` is one of `op( A ) = A` or `op( A ) = A ** T`. The matrix `X` is overwritten on `B`. | ||
Pranavchiku marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```javascript | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
|
||
A = new Float64Array( [ 1.0, 3.0, 0.0, 4.0 ] ); | ||
B = new Float64Array( [ 5.0, 7.0, 0.0, 8.0 ] ); | ||
|
||
dtrsm( 'row-major', 'left', 'upper', 'none', 'non-unit', 2, 2, 6.0, A, 2, B, 2 ); | ||
// B => <Float64Array>[ 30.0, 6.0, 0.0, 12.0 ] | ||
``` | ||
|
||
The function has the following parameters: | ||
|
||
- **order**: storage layout of `A` and `B`. | ||
- **side**: specifies whether `op( A )` appears on the left or right side of `X`. | ||
- **uplo**: specifies whether the upper or lower triangular part of the matrix `A` is supplied. | ||
- **transa**: specifies the form of `op( A )` to be used in the matrix multiplication. | ||
- **diag**: specifies whether or not `A` is unit triangular. | ||
- **m**: number of rows in `B`. | ||
- **n**: number of columns in `B`. | ||
- **alpha**: scalar constant. | ||
- **A**: input matrix `A`. | ||
- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`). | ||
- **B**: input matrix `B`. | ||
- **LDB**: stride of the first dimension of `B` (a.k.a., leading dimension of the matrix `B`). | ||
|
||
```javascript | ||
Pranavchiku marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var Float64Array = require( '@stdlib/array/float64' ); | ||
|
||
A = new Float64Array( [ 1.0, 3.0, 0.0, 4.0 ] ); | ||
B = new Float64Array( [ 5.0, 7.0, 0.0, 8.0 ] ); | ||
|
||
dtrsm( 'row-major', 'left', 'upper', 'none', 'non-unit', 2, 2, 6.0, A, 2, B, 2 ); | ||
// B => <Float64Array>[ 30.0, 6.0, 0.0, 12.0 ] | ||
``` | ||
|
||
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 --> | ||
|
||
```javascript | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
|
||
// Initial arrays... | ||
var A0 = new Float64Array( [ 0.0, 1.0, 3.0, 0.0, 4.0 ] ); | ||
var B0 = new Float64Array( [ 0.0, 5.0, 7.0, 0.0, 8.0 ] ); | ||
|
||
// Create offset views... | ||
var A1 = new Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 1st element | ||
var B1 = new Float64Array( B0.buffer, B0.BYTES_PER_ELEMENT*1 ); // start at 1st element | ||
Pranavchiku marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
dtrsm( 'row-major', 'left', 'upper', 'none', 'non-unit', 2, 2, 6.0, A1, 2, B1, 2 ); | ||
// B0 => <Float64Array>[ 0.0, 30.0, 6.0, 0.0, 12.0 ] | ||
``` | ||
|
||
#### dtrsm.ndarray( ord, side, ul, ta, diag, m, n, α, A, LDA, oa, B, LDB, ob ) | ||
Pranavchiku marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Solves matrix equation `op(A) * X = alpha * B` or `X * op(A) = alpha * B` using alternative indexing semantics where `alpha` is a scalar, `X` and `B` are m by n matrices, `A` is a unit, or non-unit, upper or lower triangular matrix and `op( A )` is one of `op( A ) = A` or `op( A ) = A**T`. The matrix `X` is overwritten on `B`. | ||
Pranavchiku marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```javascript | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
|
||
A = new Float64Array( [ 0.0, 0.0, 1.0, 3.0, 0.0, 4.0 ] ); | ||
B = new Float64Array( [ 0.0, 5.0, 7.0, 0.0, 8.0 ] ); | ||
|
||
dtrsm.ndarray( 'row-major', 'left', 'upper', 'none', 'non-unit', 2, 2, 6.0, A, 2, 2, B, 2, 1 ); | ||
// B => <Float64Array>[ 0.0, 30.0, 6.0, 0.0, 12.0 ] | ||
``` | ||
|
||
The function has the following additional parameters: | ||
Pranavchiku marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- **oa**: starting index for `A`. | ||
- **ob**: starting index for `B`. | ||
|
||
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, | ||
|
||
```javascript | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
|
||
A = new Float64Array( [ 0.0, 0.0, 1.0, 3.0, 0.0, 4.0 ] ); | ||
B = new Float64Array( [ 0.0, 5.0, 7.0, 0.0, 8.0 ] ); | ||
|
||
dtrsm.ndarray( 'row-major', 'left', 'upper', 'none', 'non-unit', 2, 2, 6.0, A, 2, 2, B, 2, 1 ); | ||
// B => <Float64Array>[ 0.0, 30.0, 6.0, 0.0, 12.0 ] | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<section class="notes"> | ||
|
||
## Notes | ||
|
||
- `dtrsm()` corresponds to the [BLAS][blas] level 3 function [`dtrsm`][dtrsm]. | ||
|
||
</section> | ||
|
||
<!-- /.notes --> | ||
|
||
<section class="examples"> | ||
|
||
## Examples | ||
|
||
<!-- eslint no-undef: "error" --> | ||
|
||
```javascript | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
var dtrsm = require( '@stdlib/blas/base/dtrsm' ); | ||
|
||
var A = new Float64Array( [ 1.0, 0.0, 3.0, 4.0 ] ); | ||
var B = new Float64Array( [ 5.0, 0.0, 7.0, 8.0 ] ); | ||
|
||
dtrsm( 'row-major', 'left', 'lower', 'none', 'non-unit', 2, 2, 6.0, A, 2, B, 2 ); | ||
console.log( B ); | ||
``` | ||
|
||
</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"> | ||
|
||
[blas]: http://www.netlib.org/blas | ||
|
||
[dtrsm]: https://www.netlib.org/lapack/explore-html/d9/de5/group__trsm_ga7120d931d7b1a15e12d50d328799df8a.html#ga7120d931d7b1a15e12d50d328799df8a | ||
|
||
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray | ||
|
||
</section> | ||
|
||
<!-- /.links --> |
104 changes: 104 additions & 0 deletions
104
lib/node_modules/@stdlib/blas/base/dtrsm/benchmark/benchmark.js
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,104 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* Copyright (c) 2024 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// MODULES // | ||
|
||
var bench = require( '@stdlib/bench' ); | ||
var uniform = require( '@stdlib/random/array/uniform' ); | ||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
var pow = require( '@stdlib/math/base/special/pow' ); | ||
var floor = require( '@stdlib/math/base/special/floor' ); | ||
var pkg = require( './../package.json' ).name; | ||
var dtrsm = require( './../lib/dtrsm.js' ); | ||
|
||
|
||
// FUNCTIONS // | ||
|
||
/** | ||
* Creates a benchmark function. | ||
* | ||
* @private | ||
* @param {PositiveInteger} N - number of elements along each dimension | ||
* @returns {Function} benchmark function | ||
*/ | ||
function createBenchmark( N ) { | ||
var A; | ||
var B; | ||
|
||
A = uniform( N*N, 1.0, 10.0, { | ||
'dtype': 'float64' | ||
}); | ||
B = uniform( N*N, 1.0, 10.0, { | ||
'dtype': 'float64' | ||
}); | ||
return benchmark; | ||
|
||
/** | ||
* Benchmark function. | ||
* | ||
* @private | ||
* @param {Benchmark} b - benchmark instance | ||
*/ | ||
function benchmark( b ) { | ||
var z; | ||
var i; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
z = dtrsm( 'column-major', 'left', 'upper', 'none', 'non-unit', N, N, 1.0, A, N, B, N ); | ||
if ( isnan( z[ i%z.length ] ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( isnan( z[ i%z.length ] ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
} | ||
} | ||
|
||
|
||
// MAIN // | ||
|
||
/** | ||
* Main execution sequence. | ||
* | ||
* @private | ||
*/ | ||
function main() { | ||
var min; | ||
var max; | ||
var N; | ||
var f; | ||
var i; | ||
|
||
min = 1; // 10^min | ||
max = 6; // 10^max | ||
|
||
for ( i = min; i <= max; i++ ) { | ||
N = floor( pow( pow( 10, i ), 1.0/2.0 ) ); | ||
f = createBenchmark( N ); | ||
bench( pkg+':order=column-major,size='+(N*N), f ); | ||
} | ||
} | ||
|
||
main(); |
Oops, something went wrong.
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.