diff options
Diffstat (limited to 'docs/examples/tutorial/cdef_classes/wave_function.py')
-rw-r--r-- | docs/examples/tutorial/cdef_classes/wave_function.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/docs/examples/tutorial/cdef_classes/wave_function.py b/docs/examples/tutorial/cdef_classes/wave_function.py new file mode 100644 index 000000000..7ff59a762 --- /dev/null +++ b/docs/examples/tutorial/cdef_classes/wave_function.py @@ -0,0 +1,22 @@ +from cython.cimports.sin_of_square import Function + +@cython.cclass +class WaveFunction(Function): + + # Not available in Python-space: + offset: float + + # Available in Python-space: + freq = cython.declare(cython.double, visibility='public') + + # Available in Python-space, but only for reading: + scale = cython.declare(cython.double, visibility='readonly') + + # Available in Python-space: + @property + def period(self): + return 1.0 / self.freq + + @period.setter + def period(self, value): + self.freq = 1.0 / value |