-
Notifications
You must be signed in to change notification settings - Fork 80
Support for GNU Scientific Library #986
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -846,6 +846,36 @@ | |
| yield ("08_c_math", "#include <math.h>") | ||
|
|
||
|
|
||
| class GSLCallable(ScalarCallable): | ||
| @override | ||
| def with_types(self, | ||
| arg_id_to_dtype: Mapping[int | str, LoopyType], | ||
| clbl_inf_ctx: CallablesInferenceContext, | ||
| ) -> tuple[Self, CallablesInferenceContext]: | ||
| name = self.name | ||
|
|
||
| for id in arg_id_to_dtype: | ||
| if not isinstance(id, int): | ||
| raise LoopyError(f"'{name}' can take only positional arguments") | ||
|
Comment on lines
+857
to
+859
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you do this as a list comprehension, you may not have to cast below. |
||
|
|
||
| arg_num_to_dtype = {cast("int", id): t for id, t in arg_id_to_dtype.items()} | ||
| arg_num_to_dtype[-1] = arg_num_to_dtype[max(arg_num_to_dtype)] | ||
|
|
||
| name_in_target = f"gsl_sf_{name}" | ||
| return (self.copy(name_in_target=name_in_target, | ||
| arg_id_to_dtype=constantdict(arg_num_to_dtype)), | ||
| clbl_inf_ctx) | ||
|
Comment on lines
+861
to
+867
|
||
|
|
||
| def generate_preambles(self, target): | ||
|
Check warning on line 869 in loopy/target/c/__init__.py
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add the missing annotations (here and below)? (bpr will also complain I think.) |
||
| # Base GSL math header | ||
| yield ("40_c_gsl_math", "#include <gsl/gsl_math.h>") | ||
|
|
||
| # Function-specific headers for GSL special functions | ||
| if self.name == "hyperg_2F1": | ||
| # gsl_sf_hyperg_2F1 is declared in <gsl/gsl_sf_hyperg.h> | ||
| yield ("41_c_gsl_sf_hyperg", "#include <gsl/gsl_sf_hyperg.h>") | ||
|
|
||
|
|
||
| def get_c_callables(): | ||
| """ | ||
| Returns an instance of :class:`InKernelCallable` if the function | ||
|
|
@@ -866,6 +896,14 @@ | |
| func_ids = ["bessel_jn", "bessel_yn"] | ||
| return {id_: GNULibcCallable(id_) for id_ in func_ids} | ||
|
|
||
|
|
||
| def get_gsl_callables(): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add this to the documentation somewhere. |
||
| # Support special functions from | ||
| # https://www.gnu.org/software/gsl/doc/html/specfunc.html | ||
| func_ids = ["hyperg_2F1"] | ||
| return {id_: GSLCallable(id_) for id_ in func_ids} | ||
|
Comment on lines
+900
to
+904
|
||
|
|
||
|
|
||
| # }}} | ||
|
|
||
|
|
||
|
|
@@ -1612,6 +1650,7 @@ | |
| def known_callables(self): | ||
| callables = super().known_callables | ||
| callables.update(get_gnu_libc_callables()) | ||
| callables.update(get_gsl_callables()) | ||
|
Check warning on line 1653 in loopy/target/c/__init__.py
|
||
|
Comment on lines
1652
to
+1653
|
||
| return callables | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to test this? (Not saying we should, just raising the possibility.)