Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix fortran char array #196

Merged
merged 3 commits into from
Jun 11, 2024

Conversation

inoelloc
Copy link
Contributor

@inoelloc inoelloc commented Jun 4, 2024

This commit addresses problems with Fortran character arrays passed to Python. The first was that the length of the character string was too short (20). The second was that only 1D arrays were managed and if the length of the character string is equal to the limit then the values in the array are not split correctly.

The max length has been increased from 20 to 128 and the associated decorator to handle character arrays has been modified to managed any nD arrays and max character length.

A few tests have been added, but they don't allow you to check all the decorators correctly. It would be necessary to create a Fortran file specific to the test case.

This commit addresses problems with Fortran character arrays passed to Python. The first was that the length of the character string
was too short (20). The second was that only 1D arrays were managed and if the length of the character string is equal to the limit
then the values in the array are not splited correctly.

The max length has been increased from 20 to 128 and the associated decorator to handle character arrays has been modified to managed
any nD arrays and max character length.

A few tests have been added, but they don't allow you to check all the decorators correctly. It would be necessary to create a
Fortran file specific to the test case.
@inoelloc inoelloc added the bug Something isn't working label Jun 4, 2024
@inoelloc inoelloc added this to the Release v1.0.1 milestone Jun 4, 2024
@inoelloc inoelloc requested a review from asjeb June 4, 2024 09:33
Can't unpack tuple indices directly in arrays
@inoelloc inoelloc linked an issue Jun 4, 2024 that may be closed by this pull request
setup.descriptor_name = descriptor_name
assert np.array_equal(setup.descriptor_name, descriptor_name), "char_array.ndarray_nd_value"

with pytest.raises(ValueError, match="could not broadcast"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

When a ValueError could happen ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When a ValueError could happen ?

>>> setup, mesh = smash.factory.load_dataset('cance')
>>> model = smash.Model(setup, mesh)
>>> model.setup.nd
2
>>> model.setup.descriptor_name = ["Riri", "Fifi", "Loulou"]
ValueError: could not broadcast input array from shape (3,) into (2,)

Copy link
Collaborator

@asjeb asjeb left a comment

Choose a reason for hiding this comment

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

Maybe add a check when the size lchar > 128 ?
--> ok :
arr[slc] = item line 77 of _f90wrap_decorator.py

@inoelloc
Copy link
Contributor Author

Maybe add a check when the size lchar > 128 ?

I will !

@asjeb asjeb merged commit f165a4e into DassHydro:maintenance/1.0.x Jun 11, 2024
11 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: Increase the max number of characters for gauge code
2 participants