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

feature request: abs for param complex #24125

Closed
mppf opened this issue Jan 2, 2024 · 1 comment · Fixed by #24127
Closed

feature request: abs for param complex #24125

mppf opened this issue Jan 2, 2024 · 1 comment · Fixed by #24127

Comments

@mppf
Copy link
Member

mppf commented Jan 2, 2024

Summary of Problem

abs on a param complex number does not produce a param, but I would expect it to.

In order to implement this, we will a need param-time sqrt for real numbers. That should also be available to users.

Steps to Reproduce

Source Code:

param c:complex(128) = 1.0i;    
param x = abs(c); // error: Initializing parameter 'x' to value not known at compile time

Associated Future Test(s):

test/library/standard/AutoMath/absparamscomplex.chpl #24127

@damianmoz
Copy link

Not urgent.

mppf added a commit that referenced this issue Jan 17, 2024
For issue #24119.
Resolves #24125.

This PR adds overloads to AutoMath to implement `param` versions of:
 * `abs` for all numeric types
 * `sqrt` for floating-point types.
 
Additionally, while testing, I realized that `complex.re` and
`complex.im` did not have `param` returning versions, so this PR also
adds such param-returning versions to ChapelBase.

To implement these, I:
* added `PRIM_SQRT` and `PRIM_ABS`. For now, these are just used for
computing these functions on `param`s and they will cause the compiler
to error out one makes it to code-generation time.
* implemented folding for `PRIM_ABS`, `PRIM_SQRT`, `PRIM_GET_REAL`, and
`PRIM_GET_IMAG` in num.cpp
* enabled `postFoldPrimop` to fold `PRIM_ABS`, `PRIM_SQRT`,
`PRIM_GET_REAL`, and `PRIM_GET_IMAG`

This PR also updates the spec description of `complex` to make it
clearer. While there, it removes `proc complex.bits` from the spec,
since this method does not exist other than in the spec.

Reviewed by @DanilaFe - thanks!

- [x] full comm=none testing

Future Work:
 * #22809
* in particular, resolve two confusing errors I posted as comments based
on work on this PR
* update the dyno resolver to assert `PRIM_ABS`, `PRIM_SQRT` are only
used on `param` values
* update the dyno resolver to implement `PRIM_GET_REAL` and
`PRIM_GET_IMAG` on `param` values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants