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 support for char as a type annotation #1806

Draft
wants to merge 4 commits into
base: devel
Choose a base branch
from

Conversation

AjaySDwivedi1
Copy link

Add the char annotation and created a test. Not sure if I created the test correctly.

@pyccel-bot
Copy link

pyccel-bot bot commented Mar 20, 2024

Hello! Welcome to Pyccel! Thank you very much for your contribution ❤️.

I am the GitHub bot. I will help guide you through the different stages necessary to validate a review in Pyccel. If you haven't yet seen our developer docs make sure you check them out here. Amongst other things they describe the review process that we have just started. You can also get in touch with our other developers on our Pyccel Discord Server.

To begin with I will give you a short checklist to make sure your pull request is complete. Please tick items off when you have completed them or determined that they are not necessary for this pull request. If you want me to run any specific tests to check out corner cases that you can't easily check on your computer, you can request this using the command /bot run X. Use the command /bot show tests to see a full list of the tests I can run. Once you have finished preparing your pull request and are ready to request reviews just take your PR out of draft, or let me know with the command /bot mark as ready. I will then run the full suite of tests to check that everything is as neat as you think before asking other contributors for reviews. Tests will not run automatically before this point to avoid wasting resources. You can get a full list of commands that I understand using /bot commands.

Please begin by requesting your checklist using the command /bot checklist

@github-actions github-actions bot marked this pull request as draft March 20, 2024 22:43
@pyccel-bot
Copy link

pyccel-bot bot commented Mar 20, 2024

@yguclu, @EmilyBourne, @bauom, please can you check if I can trust this user. If you are happy, let me know with /bot trust user

#------------------------------------------------------------------------------
def test_char:
if __name__ == '__main__':
string = np.empty((2, 5), dtype='c')
Copy link
Member

Choose a reason for hiding this comment

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

You will need to make changes in pyccel.ast.numpyext or pyccel.ast.numpytypes so that 'c' is recognised.

@AjaySDwivedi1
Copy link
Author

Okay I think I did the right test. I used the test_bool function as a reference.

#------------------------------------------------------------------------------
def test_char(language):
types = str
pyccel_test("scripts/c_arrays.py", language = language, output_dtype = types)
Copy link
Member

Choose a reason for hiding this comment

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

Did you forget to commit the file scripts/c_arrays.py ?

Copy link
Author

Choose a reason for hiding this comment

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

I did not because it already existed and I didn’t make any chances to it.

Copy link
Member

Choose a reason for hiding this comment

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

Ah you are right sorry. It is already tested here:

def test_c_arrays(language):
types = [int]*15 + [float]*5 + [int]*25 + [float]* 20 * 5 + \
[complex] * 3 * 10 + [complex] * 5 + [float] * 10 + [float] * 6 + \
[float] * 2 * 3 + [complex] * 3 * 10 + [float] * 2 * 3 + [int] * 3
pyccel_test("scripts/c_arrays.py", language=language, output_dtype=types)

In that case it seems that you have not finished adding a test as nothing new is tested.

Copy link
Author

Choose a reason for hiding this comment

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

Ok, sounds good! Do I need to do anything else for you to approve my PR?

Copy link
Member

Choose a reason for hiding this comment

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

You need to:

  • add a test/multiple tests that tests the things that the PR is supposed to implement (so a test which translates a file with a char type annotation)
  • Ensure all the tests pass (e.g. the Codacy static analysis is currently failing)
  • Interact with the bot to get and complete your checklist
  • Get the example to work. Your fix is not sufficient to make the following code work:
if __name__ == '__main__':
        string = np.empty((2, 5), dtype='c')
        string[0] = "HELLO"
        string[1] = "WORLD"
        for i in range(5):
            print(string[0,i], end='')

The issue you are trying to fix specifically mentions this test: pyccel/tests/internal/scripts/lapack/ex1.py and asks that the header file describing the LAPACK library be updated to use char instead of str where appropriate.

Copy link
Author

Choose a reason for hiding this comment

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

Oh sorry I misread the previous message.

Copy link
Author

Choose a reason for hiding this comment

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

Ah you are right sorry. It is already tested here:

def test_c_arrays(language):
types = [int]*15 + [float]*5 + [int]*25 + [float]* 20 * 5 + \
[complex] * 3 * 10 + [complex] * 5 + [float] * 10 + [float] * 6 + \
[float] * 2 * 3 + [complex] * 3 * 10 + [float] * 2 * 3 + [int] * 3
pyccel_test("scripts/c_arrays.py", language=language, output_dtype=types)

In that case it seems that you have not finished adding a test as nothing new is tested.

I am little confused on creating test functions. What test functions test type annotation? I've looked at all the functions and none of them were helping, but maybe I just missed them.

Copy link
Member

Choose a reason for hiding this comment

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

Most of the functions that explicitly test type annotations are in the epyccel folder but any tests that translate files containing type annotations also test them. E.g. test_funcs tests:
https://github.com/pyccel/pyccel/blob/b39fe9a411736a833d980674b7f6380278febf0f/tests/pyccel/scripts/funcs.py
which contains type annotations

Copy link
Member

Choose a reason for hiding this comment

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

Pyccel is a translator so as long as the thing you are interested in appears in the file being translated you are testing it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants