Skip to content
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

feat: add C ndarray implementation for blas/base/dscal #2915

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

aman-095
Copy link
Member

Progresses #2039.

Description

What is the purpose of this pull request?

This pull request:

  • adds C ndarray API for blas/base/dscal.

Related Issues

Does this pull request have any related issues?

This pull request:

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

@stdlib-bot stdlib-bot added the BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). label Sep 17, 2024
@kgryte kgryte added Feature Issue or pull request for adding a new feature. C Issue involves or relates to C. labels Sep 17, 2024
@aman-095 aman-095 marked this pull request as ready for review September 19, 2024 03:45
x[ i ] *= alpha;
}
return x;
return ndarray( N, alpha, x, stride, 0 );
Copy link
Member

Choose a reason for hiding this comment

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

@aman-095 I believe we want to support negative strides here. That means using stride2offset to compute the offset before calling into the ndarray API.

Copy link
Member Author

Choose a reason for hiding this comment

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

But, native dscal implementation from lapack doesn't allow for negative stride.

Copy link
Member

Choose a reason for hiding this comment

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

That was my point about converting from negative to positive. But here, our ndarray.js file should support negative strides. In C, we should convert the stride before calling CBLAS. Meaning, we are free to support negative strides, but we need to ensure that if and when we call a library following LAPACK that we only pass along positive strides. In short, for all our Level 1 routines, we should be consistent in supporting negative strides. The current situation of some supporting and others not supporting is just confusing.

Copy link
Member Author

Choose a reason for hiding this comment

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

It means that for our Js implementation, we should allow negative strides for all BLAS Level 1 and only for CBLAS, or other hardware-optimized libraries we use the same convention of stride conversion.

Copy link
Member

Choose a reason for hiding this comment

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

Correct. We need to update our JS implementations to support negative strides.

X[ i ] *= alpha;
}
return;
API_SUFFIX(c_dscal_ndarray)( N, alpha, X, stride, 0 );
Copy link
Member

Choose a reason for hiding this comment

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

@aman-095 Similarly, we should go ahead and support negative strides here.

* @param offset starting index
*/
void API_SUFFIX(c_dscal_ndarray)( const CBLAS_INT N, const double alpha, double *X, const CBLAS_INT stride, const CBLAS_INT offset ) {
X += stdlib_strided_min_view_buffer_index( N, stride, offset ); // adjust array pointer
Copy link
Member

Choose a reason for hiding this comment

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

@aman-095 Before L47, we should convert stride to a positive stride before calling into CBLAS, which may or may not support negative strides. By always passing in a positive stride, we avoid backward compat breaks.

@@ -31,3 +32,17 @@
void API_SUFFIX(c_dscal)( const CBLAS_INT N, const double alpha, double *X, const CBLAS_INT stride ) {
API_SUFFIX(cblas_dscal)( N, alpha, X, stride );
Copy link
Member

Choose a reason for hiding this comment

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

@aman-095 We should also support negative strides here.

@@ -31,3 +32,21 @@
void API_SUFFIX(c_dscal)( const CBLAS_INT N, const double alpha, double *X, const CBLAS_INT stride ) {
dscal( &N, &alpha, X, &stride );
Copy link
Member

Choose a reason for hiding this comment

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

@aman-095 We should also support negative strides here.

*/
void API_SUFFIX(c_dscal_ndarray)( const CBLAS_INT N, const double alpha, double *X, const CBLAS_INT stride, const CBLAS_INT offset ) {
CBLAS_INT sx = stride;
if( sx < 0 ) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if( sx < 0 ) {
if ( sx < 0 ) {

@kgryte kgryte added the Needs Changes Pull request which needs changes before being merged. label Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). C Issue involves or relates to C. Feature Issue or pull request for adding a new feature. Needs Changes Pull request which needs changes before being merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants