Skip to content

Commit ddd0c9f

Browse files
committed
perf: always noexcept c methods
1 parent 594ca66 commit ddd0c9f

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

.github/workflows/tests.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ jobs:
6262
# Thanks https://stackoverflow.com/a/60942437
6363
- name: Get month to use as cache key.
6464
id: month
65-
run: echo "month==$(date +'%m')" >> $GITHUB_OUTPUT
65+
run: echo "month=$(date +'%m')" >> $GITHUB_OUTPUT
6666
- name: Deal with auto-generated code cache
6767
uses: actions/cache@v4
6868
with:
6969
path: |
7070
~/.compyle
71-
key: ${{ runner.os }}-py${{ matrix.python-version }}-${{ steps.month.outputs.month }}
71+
key: ${{ runner.os }}-${{ steps.month.outputs.month }}-${{ matrix.python-version }}
7272
- name: Run tests
7373
run: |
7474
coverage erase

compyle/cython_generator.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -448,10 +448,10 @@ def _get_c_method_spec(self, name, returns, args):
448448
c_arg_def = ', '.join(c_args)
449449
if self._config.use_openmp:
450450
ignore = ['reduce', 'converged']
451-
gil = " noexcept nogil" if name not in ignore else ""
451+
gil = " nogil" if name not in ignore else ""
452452
else:
453453
gil = ""
454-
cdefn = 'cdef inline {ret} {name}({arg_def}){gil}:'.format(
454+
cdefn = 'cdef inline {ret} {name}({arg_def}) noexcept{gil}:'.format(
455455
ret=c_ret, name=name, arg_def=c_arg_def, gil=gil
456456
)
457457

compyle/tests/test_cython_generator.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def test_function_with_annotation(self):
442442

443443
# Then
444444
expect = dedent('''
445-
cdef inline float annotated_f(int i, float* y):
445+
cdef inline float annotated_f(int i, float* y) noexcept:
446446
cdef unsigned int x[64]
447447
return y[i]
448448
''')
@@ -457,7 +457,7 @@ def test_python3_annotation(self):
457457
# When
458458
cg.parse(py3_f)
459459
expect = dedent('''
460-
cdef inline int py3_f(int x):
460+
cdef inline int py3_f(int x) noexcept:
461461
cdef int y
462462
y = x + 1
463463
return x*y
@@ -476,7 +476,7 @@ def __init__(self, **kwargs):
476476
for key, value in kwargs.items():
477477
setattr(self, key, value)
478478
479-
cdef inline void func(self, long d_idx, double* d_x):
479+
cdef inline void func(self, long d_idx, double* d_x) noexcept:
480480
cdef double tmp
481481
tmp = abs(self.rho*self.c)*sin(pi*self.c)
482482
d_x[d_idx] = d_x[d_idx]*tmp
@@ -517,7 +517,7 @@ def __init__(self, **kwargs):
517517
for key, value in kwargs.items():
518518
setattr(self, key, value)
519519
520-
cdef inline void func(self, long d_idx, double* d_x):
520+
cdef inline void func(self, long d_idx, double* d_x) noexcept:
521521
cdef double tmp
522522
tmp = abs(self.rho*self.c)*sin(pi*self.c)
523523
d_x[d_idx] = d_x[d_idx]*tmp
@@ -537,7 +537,7 @@ def __init__(self, **kwargs):
537537
for key, value in kwargs.items():
538538
setattr(self, key, value)
539539
540-
cdef inline double func(self, long d_idx, double* d_x):
540+
cdef inline double func(self, long d_idx, double* d_x) noexcept:
541541
return d_x[d_idx]
542542
543543
cpdef double py_func(self, long d_idx, double[:] d_x):
@@ -547,7 +547,7 @@ def __init__(self, **kwargs):
547547

548548
cg.parse(func_with_return)
549549
expect = dedent("""
550-
cdef inline double func_with_return(long d_idx, double* d_x, double x):
550+
cdef inline double func_with_return(long d_idx, double* d_x, double x) noexcept:
551551
x += 1
552552
return d_x[d_idx] + x
553553
@@ -568,7 +568,7 @@ def __init__(self, **kwargs):
568568
for key, value in kwargs.items():
569569
setattr(self, key, value)
570570
571-
cdef inline double func(self, long d_idx, double* d_x):
571+
cdef inline double func(self, long d_idx, double* d_x) noexcept:
572572
return d_x[d_idx]
573573
""")
574574
self.assert_code_equal(cg.get_code().strip(), expect.strip())
@@ -582,7 +582,7 @@ def __init__(self, **kwargs):
582582
for key, value in kwargs.items():
583583
setattr(self, key, value)
584584
585-
cdef inline void func(self, long d_idx, double* d_x):
585+
cdef inline void func(self, long d_idx, double* d_x) noexcept:
586586
cdef double mat[2][2]
587587
mat[0][0] = d_x[d_idx]
588588
cdef float vec[3], vec1[3]
@@ -599,7 +599,7 @@ def __init__(self, **kwargs):
599599
for key, value in kwargs.items():
600600
setattr(self, key, value)
601601
602-
cdef inline void func(self, long d_idx, double* d_x):
602+
cdef inline void func(self, long d_idx, double* d_x) noexcept:
603603
cdef float val, val1
604604
# val1 = declare('double')
605605
val = d_x[d_idx]
@@ -622,7 +622,7 @@ def __init__(self, **kwargs):
622622
for key, value in kwargs.items():
623623
setattr(self, key, value)
624624
625-
cdef inline void some_func(self, long d_idx, double* d_p, double WIJ, double* DWIJ, ndarray user, long* d_user, int* s_user):
625+
cdef inline void some_func(self, long d_idx, double* d_p, double WIJ, double* DWIJ, ndarray user, long* d_user, int* s_user) noexcept:
626626
d_p[d_idx] = WIJ*DWIJ[0]
627627
""")
628628
self.assert_code_equal(cg.get_code().strip(), expect.strip())
@@ -631,15 +631,15 @@ def test_wrap_function(self):
631631
cg = CythonGenerator()
632632
cg.parse(func_with_return)
633633
expect = dedent("""
634-
cdef inline double func_with_return(long d_idx, double* d_x, double x):
634+
cdef inline double func_with_return(long d_idx, double* d_x, double x) noexcept:
635635
x += 1
636636
return d_x[d_idx] + x
637637
""")
638638
self.assert_code_equal(cg.get_code().strip(), expect.strip())
639639

640640
cg.parse(simple_func)
641641
expect = dedent("""
642-
cdef inline void simple_func(long d_idx, double* d_x, double x):
642+
cdef inline void simple_func(long d_idx, double* d_x, double x) noexcept:
643643
d_x[d_idx] += x
644644
""")
645645
self.assert_code_equal(cg.get_code().strip(), expect.strip())

0 commit comments

Comments
 (0)