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

Add cmath polar functions #1663

Merged
merged 2 commits into from
Apr 3, 2023
Merged

Add cmath polar functions #1663

merged 2 commits into from
Apr 3, 2023

Conversation

virendrakabra14
Copy link
Contributor

Adds phase, polar, and rect functions to cmath module.

@virendrakabra14
Copy link
Contributor Author

I tried using (LPython) math functions in cmath, but the import failed with this message

Module __main__ dependencies must contain math because a function present in it is getting called in __main__

I wasn't sure on where to add this dependency, so I created rect function in lfortran_intrinsics files.

@virendrakabra14 virendrakabra14 marked this pull request as draft April 3, 2023 09:47
@virendrakabra14 virendrakabra14 marked this pull request as ready for review April 3, 2023 10:07
@virendrakabra14 virendrakabra14 marked this pull request as draft April 3, 2023 10:25
@czgdp1807
Copy link
Collaborator

Windows build fails due to some syntax errors. See, https://github.com/lcompilers/lpython/actions/runs/4595681671/jobs/8116223194?pr=1663

@czgdp1807
Copy link
Collaborator

czgdp1807 commented Apr 3, 2023

I tried using (LPython) math functions in cmath, but the import failed with this message

Module __main__ dependencies must contain math because a function present in it is getting called in __main__

I wasn't sure on where to add this dependency, so I created rect function in lfortran_intrinsics files.

Can you share the exact LPython command you executed?

@czgdp1807
Copy link
Collaborator

@virendrakabra14 I pushed some changes, let's see if they work with Windows CI or not.

@virendrakabra14
Copy link
Contributor Author

virendrakabra14 commented Apr 3, 2023

@virendrakabra14 I pushed some changes, let's see if they work with Windows CI or not.

@czgdp1807 Alright.

I had also modified lfortran_intrinsics.c to resolve the Windows issue - double complex, double_complex_t aren't identified.

LFORTRAN_API double_complex_t _lfortran_rect(double r, double phi)
{
    double re = r*cos(phi);
    double im = r*sin(phi);
    #ifdef _MSC_VER
        _Dcomplex c = _DCOMPLEX_(re, im);
    #else
        double complex c = CMPLX(re, im);
    #endif
    return c;
}

I am guessing that would also work.

@czgdp1807
Copy link
Collaborator

I think we didn't need to go into C to implement rect. Using, _lfortran_dcos and _lfortran_dsin in cmath.py completes the implementation. Not sure what added advantage C implementation provides.

@virendrakabra14
Copy link
Contributor Author

I tried using (LPython) math functions in cmath, but the import failed with this message

Module __main__ dependencies must contain math because a function present in it is getting called in __main__

I wasn't sure on where to add this dependency, so I created rect function in lfortran_intrinsics files.

Can you share the exact LPython command you executed?

I was using import math in cmath.py and using sin, cos functions. Test file test_cmath.py was same as the current one. Then

lpython ./integration_tests/test_cmath.py

gave that error - which I think is due to importing math in cmath.

@czgdp1807
Copy link
Collaborator

czgdp1807 commented Apr 3, 2023

Also, eventually we might implement all these intrinsics using IntrinsicFunction infrastructure and provide direct ASR implementations for their functions. So if calling into C can be avoided then it should be. In the long run, functions like, _lfortran_dsin, _lfortran_dcos can also be done via ASR directly (by using some approximation algorithms to produce outputs for sin and cos calls).

@czgdp1807 czgdp1807 marked this pull request as ready for review April 3, 2023 15:10
@certik certik merged commit 3317fec into lcompilers:main Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants