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

Clearer use of ndarray_type_registry #17

Open
EmilyBourne opened this issue Apr 20, 2023 · 1 comment
Open

Clearer use of ndarray_type_registry #17

EmilyBourne opened this issue Apr 20, 2023 · 1 comment
Labels
internals Pyccel's internal behavior, does not affect user experience invalid This doesn't seem right

Comments

@EmilyBourne
Copy link
Member

Currently we have a ndarray_type_registry which is used for both N-D arrays and Cuda arrays. In order to use the same object for Cuda arrays we have code such as the following:

dtype = self.find_in_ndarray_type_registry(self._print(rhs.dtype), rhs.precision)
dtype = dtype[3:]
code_init += 'array_fill_{0}(({1}){2}, {3});\n'.format(dtype, declare_dtype, self._print(rhs.fill_value), self._print(lhs))

This code could be clearer as it is not clear where the [3:] comes from unless we are familiar with find_in_ndarray_type_registry. It is also not very future proof as it will be very hard to find statements like this should the prefix ever change length. Furthermore if the ndarray_type_registry is used for cuda types too then its docstring should be updated to make it clear that it affects more than just ndarrays.

To clear this up I recommend changing the function to find_in_array_type_registry
Code can then do:

dtype = self.find_in_array_type_registry(self._print(rhs.dtype), rhs.precision)
code_init += 'array_fill_{0}(({1}){2}, {3});\n'.format(dtype, declare_dtype, self._print(rhs.fill_value), self._print(lhs))

While array code would instead do:

dtype = 'nd_'+self.find_in_array_type_registry(self._print(rhs.dtype), rhs.precision)

Alternatively to avoid code duplication, we could also keep self.find_in_ndarray_type_registry:

def find_in_ndarray_type_registry(dtype, precision):
    type_name = self.find_in_array_type_registry(dtype, precision)
    return f'nd_{type_name}'
@EmilyBourne EmilyBourne added the internals Pyccel's internal behavior, does not affect user experience label Apr 20, 2023
@EmilyBourne EmilyBourne added the invalid This doesn't seem right label Jun 12, 2024
@EmilyBourne
Copy link
Member Author

Related to old branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internals Pyccel's internal behavior, does not affect user experience invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

1 participant