|
4 | 4 | As SciPy is not always available, we treat them separately.
|
5 | 5 | """
|
6 | 6 |
|
7 |
| -import os |
8 | 7 | from functools import reduce
|
| 8 | +from pathlib import Path |
9 | 9 | from textwrap import dedent
|
10 | 10 |
|
11 | 11 | import numpy as np
|
|
47 | 47 | from pytensor.scalar.loop import ScalarLoop
|
48 | 48 |
|
49 | 49 |
|
| 50 | +C_CODE_PATH = Path(__file__).parent / "c_code" |
| 51 | + |
| 52 | + |
50 | 53 | class Erf(UnaryScalarOp):
|
51 | 54 | nfunc_spec = ("scipy.special.erf", 1, 1)
|
52 | 55 |
|
@@ -154,19 +157,12 @@ def L_op(self, inputs, outputs, grads):
|
154 | 157 |
|
155 | 158 | def c_header_dirs(self, **kwargs):
|
156 | 159 | # Using the Faddeeva.hh (c++) header for Faddeevva.cc
|
157 |
| - res = [ |
158 |
| - *super().c_header_dirs(**kwargs), |
159 |
| - os.path.join(os.path.dirname(__file__), "c_code"), |
160 |
| - ] |
| 160 | + res = [*super().c_header_dirs(**kwargs), C_CODE_PATH] |
161 | 161 | return res
|
162 | 162 |
|
163 | 163 | def c_support_code(self, **kwargs):
|
164 | 164 | # Using Faddeeva.cc source file from: http://ab-initio.mit.edu/wiki/index.php/Faddeeva_Package
|
165 |
| - with open( |
166 |
| - os.path.join(os.path.dirname(__file__), "c_code", "Faddeeva.cc") |
167 |
| - ) as f: |
168 |
| - raw = f.read() |
169 |
| - return raw |
| 165 | + return (C_CODE_PATH / "Faddeeva.cc").read_text(encoding="utf-8") |
170 | 166 |
|
171 | 167 | def c_code(self, node, name, inp, out, sub):
|
172 | 168 | (x,) = inp
|
@@ -612,9 +608,7 @@ def impl(self, x, k):
|
612 | 608 | return Chi2SF.st_impl(x, k)
|
613 | 609 |
|
614 | 610 | def c_support_code(self, **kwargs):
|
615 |
| - with open(os.path.join(os.path.dirname(__file__), "c_code", "gamma.c")) as f: |
616 |
| - raw = f.read() |
617 |
| - return raw |
| 611 | + return (C_CODE_PATH / "gamma.c").read_text(encoding="utf-8") |
618 | 612 |
|
619 | 613 | def c_code(self, node, name, inp, out, sub):
|
620 | 614 | x, k = inp
|
@@ -665,9 +659,7 @@ def grad(self, inputs, grads):
|
665 | 659 | ]
|
666 | 660 |
|
667 | 661 | def c_support_code(self, **kwargs):
|
668 |
| - with open(os.path.join(os.path.dirname(__file__), "c_code", "gamma.c")) as f: |
669 |
| - raw = f.read() |
670 |
| - return raw |
| 662 | + return (C_CODE_PATH / "gamma.c").read_text(encoding="utf-8") |
671 | 663 |
|
672 | 664 | def c_code(self, node, name, inp, out, sub):
|
673 | 665 | k, x = inp
|
@@ -718,9 +710,7 @@ def grad(self, inputs, grads):
|
718 | 710 | ]
|
719 | 711 |
|
720 | 712 | def c_support_code(self, **kwargs):
|
721 |
| - with open(os.path.join(os.path.dirname(__file__), "c_code", "gamma.c")) as f: |
722 |
| - raw = f.read() |
723 |
| - return raw |
| 713 | + return (C_CODE_PATH / "gamma.c").read_text(encoding="utf-8") |
724 | 714 |
|
725 | 715 | def c_code(self, node, name, inp, out, sub):
|
726 | 716 | k, x = inp
|
@@ -1031,9 +1021,7 @@ def impl(self, k, x):
|
1031 | 1021 | return GammaU.st_impl(k, x)
|
1032 | 1022 |
|
1033 | 1023 | def c_support_code(self, **kwargs):
|
1034 |
| - with open(os.path.join(os.path.dirname(__file__), "c_code", "gamma.c")) as f: |
1035 |
| - raw = f.read() |
1036 |
| - return raw |
| 1024 | + return (C_CODE_PATH / "gamma.c").read_text(encoding="utf-8") |
1037 | 1025 |
|
1038 | 1026 | def c_code(self, node, name, inp, out, sub):
|
1039 | 1027 | k, x = inp
|
@@ -1069,9 +1057,7 @@ def impl(self, k, x):
|
1069 | 1057 | return GammaL.st_impl(k, x)
|
1070 | 1058 |
|
1071 | 1059 | def c_support_code(self, **kwargs):
|
1072 |
| - with open(os.path.join(os.path.dirname(__file__), "c_code", "gamma.c")) as f: |
1073 |
| - raw = f.read() |
1074 |
| - return raw |
| 1060 | + return (C_CODE_PATH / "gamma.c").read_text(encoding="utf-8") |
1075 | 1061 |
|
1076 | 1062 | def c_code(self, node, name, inp, out, sub):
|
1077 | 1063 | k, x = inp
|
|
0 commit comments