Debian Codegraph @

tests/example-project/src/pypackage/wrap_cpp_ext_module.pyx

raw
1 # distutils: language = c++
2
3 cdef extern from "../clib/sqrcpp.cpp":
4 T vsqr[T](T a)
5
6
7 def sqr(a):
8 """
9 >>> sqr(2)
10 4
11 >>> '%.3g' % round(sqr(2.2), 2)
12 '4.84'
13 >>> sqr("asd")
14 Traceback (most recent call last):
15 ...
16 TypeError: Expected int or float type input.
17 """
18 if isinstance(a, (int, )):
19 return vsqr(<int>a)
20
21 elif isinstance(a, (float, )):
22 return vsqr(<double>a)
23
24 else:
25 raise TypeError("Expected int or float type input.")