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

[RFC]: add blas/base/zdotu #2125

Open
3 tasks done
performant23 opened this issue Apr 5, 2024 · 8 comments
Open
3 tasks done

[RFC]: add blas/base/zdotu #2125

performant23 opened this issue Apr 5, 2024 · 8 comments
Assignees
Labels
Accepted RFC feature request which has been accepted. BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). C Issue involves or relates to C. difficulty: 3 Likely to be challenging but manageable. Feature Issue or pull request for adding a new feature. Fortran Issue involves or relates to Fortran. JavaScript Issue involves or relates to JavaScript. Native Addons Issue involves or relates to Node.js native add-ons. priority: High High priority concern or feature request.

Comments

@performant23
Copy link
Contributor

Description

This RFC proposes adding the package @stdlib/blas/base/zdotu for performing dot product of 2 complex double-precision vectors:

void c_zdotu( const int *N, const void *X, const int *strideX, const void *Y, const int *strideY);

Related Issues

Related Issue: Tracker

Questions

No.

Other

No.

Checklist

  • I have read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.
  • The issue name begins with RFC:.
@performant23
Copy link
Contributor Author

Hi, I'd like to work on this issue!

@performant23 performant23 changed the title [RFC]: [RFC]: add blas/base/zdotu Apr 5, 2024
@kgryte
Copy link
Member

kgryte commented Apr 5, 2024

@performant23 That'd be great! Thanks for volunteering to work on this!

@kgryte kgryte added Feature Issue or pull request for adding a new feature. difficulty: 3 Likely to be challenging but manageable. Native Addons Issue involves or relates to Node.js native add-ons. Accepted RFC feature request which has been accepted. BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). priority: High High priority concern or feature request. JavaScript Issue involves or relates to JavaScript. C Issue involves or relates to C. labels Apr 5, 2024
@kgryte kgryte added the Fortran Issue involves or relates to Fortran. label Apr 5, 2024
@performant23
Copy link
Contributor Author

performant23 commented Apr 6, 2024

Perfect! Also, just had a few doubts as I was moving onto the C implementation.

First, building on the previous PR review, we replaced complex(kind=8) with complex(kind=kind(0.0d0)). So, in the first case, we treat the parts of the complex number as 8 bytes in the memory while in the second case, we let the kind parameter return the value of a dummy complex number to determine its kind. So, I think it should be mainly since some machines/compilers would have different definitions of precisions and how they're allocated.
So, just to confirm, we'd be dynamically creating allocatable arrays in all our complex double-precision routines right?
E.g.

(A). Array Arguments:

  complex(kind=kind(0.0d0)), intent(in) :: zx(*), zy(*)

Also importantly, what happens to the routines with return values that are complex double-precision for JS, C, and Fortran?

E.g.

(B). Function signatures:

complex(kind=kind(0.0d0)) function zdotu( N, zx, strideX, zy, strideY )
.
.
.

So, currently I didn't find any double-precision complex implementations for JS as such (including blasjs), and also CBLAS doesn't provide any significant help in understanding it since there a wrapper is used to call the Fortran implementation (but here I'm not sure how we'd proceed with actually implementing in C)

(C). Second, since we're returning a double-precision complex number, Node.js doesn't seem to have built-in support for complex numbers.

So, for these cases, would we use something like napi_create_object (In addon.c)?

Like for this one:

double real_part = stdlib_real(dot);
double imag_part = stdlib_imag(dot);

napi_value real, imag, result;
status = napi_create_double(env, real_part, &real);
assert(status == napi_ok);
status = napi_create_double(env, imag_part, &imag);
assert(status == napi_ok);

status = napi_create_object(env, &result);
assert(status == napi_ok);
status = napi_set_named_property(env, result, "real", real);
assert(status == napi_ok);
status = napi_set_named_property(env, result, "imag", imag);
assert(status == napi_ok);

return result;

where dot is the result we get after passing it to c_zdotu.

@performant23
Copy link
Contributor Author

Hi @kgryte, hope you had a restful weekend! I was just wondering if you have any comments on my above questions. This would help me immensely since currently it's blocking me and your clarification on this would enable me to continue the development on this!

Thanks!

@kgryte
Copy link
Member

kgryte commented Apr 17, 2024

C) Returning an object with real and imaginary components, yes, that should work, and it's what we do for unary math functions. See

. Note, however, you should follow our re and im property name conventions.

B) that looks fine.

A) I went with kind(0.0d0), as specifying 8 is not necessarily portable in older Fortran versions. kind(0.0d0) effectively queries the byte size of a double.

@performant23
Copy link
Contributor Author

Thanks, @kgryte! This is really helpful for adding this and all subsequent L1 z* packages which return double-precision complex values!

@kgryte
Copy link
Member

kgryte commented Apr 18, 2024

@performant23 FYI: for returning a complex number-like object, I added macro support to simplify JS value creation: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/napi/create-complex-like. You'll need to merge in the latest develop to use.

You can see something similar at work for returning a JS double: e96e888

@kgryte
Copy link
Member

kgryte commented Apr 18, 2024

This should hopefully eliminate the need for (C), as you can use the macro instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted RFC feature request which has been accepted. BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). C Issue involves or relates to C. difficulty: 3 Likely to be challenging but manageable. Feature Issue or pull request for adding a new feature. Fortran Issue involves or relates to Fortran. JavaScript Issue involves or relates to JavaScript. Native Addons Issue involves or relates to Node.js native add-ons. priority: High High priority concern or feature request.
Projects
None yet
Development

No branches or pull requests

2 participants