Skip to content

feat: add lapack/base/dlaset #2558

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

Draft
wants to merge 20 commits into
base: develop
Choose a base branch
from
Draft

Conversation

Pranavchiku
Copy link
Member

Description

What is the purpose of this pull request?

This pull request adds JS implementation for lapack/base/dlaset

Related Issues

Does this pull request have any related issues?

No.

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

@Pranavchiku Pranavchiku added the LAPACK Issue or pull request related to the Linear Algebra Package (LAPACK). label Jul 11, 2024
@Pranavchiku Pranavchiku marked this pull request as ready for review July 11, 2024 07:55
@kgryte kgryte added the Feature Issue or pull request for adding a new feature. label Jul 14, 2024
// A0 => <Float64Array>[ 0.0, 3.7, 0.0, 0.0, 3.1, 3.7, 0.0, 3.1, 3.1, 3.7 ]
```

#### dlaset.ndarray( order, uplo, M, N, alpha, beta, A, LDA, offsetA )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pranavchiku Would you minding updating the implementation to support separate dimension strides, as discussed elsewhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On it, thus marking it as draft.

var i;
var j;

if ( uplo === 'upper' ) {
Copy link
Member

@kgryte kgryte Jul 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect that it may be possible to perform loop interchange in this implementation, which may allow consolidating loops.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be an equivalence relation between, e.g., upper and column-major and lower and row-major. You should verify. But if true, you should be able to reduce nested loop duplication.

return A;
}
// All of the matrix `A`
if ( order === 'column-major' ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These loops should definitely support loop interchange, thus allowing consolidation into a single set of nested loops.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pranavchiku You can have a look at the most recent changes to the dlacpy PR. #2548

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in that PR, I suggest splitting this implementation up into separate sub-functions.

@kgryte kgryte added the Needs Changes Pull request which needs changes before being merged. label Jul 14, 2024
@Pranavchiku Pranavchiku marked this pull request as draft July 15, 2024 07:57
@Pranavchiku Pranavchiku marked this pull request as ready for review July 16, 2024 11:47
@Pranavchiku Pranavchiku added Needs Review A pull request which needs code review. and removed Needs Changes Pull request which needs changes before being merged. labels Jul 16, 2024
@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. JavaScript Issue involves or relates to JavaScript. and removed Needs Review A pull request which needs code review. labels Jul 28, 2024
@Pranavchiku Pranavchiku marked this pull request as draft August 3, 2024 06:56
@Pranavchiku Pranavchiku added Needs Review A pull request which needs code review. and removed Needs Changes Pull request which needs changes before being merged. labels Aug 3, 2024
@Pranavchiku Pranavchiku marked this pull request as ready for review August 3, 2024 08:08
@kgryte kgryte added Needs Changes Pull request which needs changes before being merged. and removed Needs Review A pull request which needs code review. labels Aug 3, 2024
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pranavchiku It is not clear to me (a) why you did not leverage loop interchange in the implementations below and (b) why you are not accounting for row- and column-major stride order. E.g., if strides are in column-major and need to set the upper triangular part, I would expect that the loop would be different than if the strides are in row-major and need to set the upper triangular part. Currently, your implementations favor one order over the other.

Additionally, when M == N, you can have "optimized" implementations where column-major strides upper is equivalent to row-major strides lower. I would expect that we'd include such implementations here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, when M == N, you can have "optimized" implementations where column-major strides upper is equivalent to row-major strides lower. I would expect that we'd include such implementations here.

The trouble here is that now we need to take a transpose of output matrix before returning.

Copy link
Member Author

@Pranavchiku Pranavchiku Aug 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or let me check again

Copy link
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some refactoring, but more refactoring remains. My primary feedback at this point is that we need to account for stride order.

for ( i = 0; i < M; i++ ) {
ia = offsetA + ( i * strideA1 );
for ( j = i + 1; j < min( M, N ); j++ ) {
if ( i !== j ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pranavchiku Given that j = i + 1, in what circumstance is i equal to j?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, it fails without that check.

if ( isRowMajor( [ strideA1, strideA2 ] ) ) {
for ( i = 0; i < M; i++ ) {
ia = offsetA + ( i * strideA1 );
for ( j = i; j >= 0; j-- ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're setting the diagonal at L150, why initialize j = i here?

@Pranavchiku Pranavchiku marked this pull request as draft August 12, 2024 14:16
@kgryte
Copy link
Member

kgryte commented Jan 19, 2025

@aman-095 You can see 8995729, where we implemented laset for double-precision complex floating-point. The real-valued version should be able to take inspiration accordingly. That commit addresses the concerns raised above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Issue or pull request for adding a new feature. JavaScript Issue involves or relates to JavaScript. LAPACK Issue or pull request related to the Linear Algebra Package (LAPACK). Needs Changes Pull request which needs changes before being merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants