
P1: JYS
c03 JWBK378-Fletcher May 1, 2009 19:52 Printer: Yet to come
Extending Python from C++ 19
An example of the use of the epsilon function is again provided by a ppf.math unit
test:
class bisect tests(unittest.TestCase):
def test1(self):
tol = 5*ppf.math.epsilon()
left, right, num
its = \
ppf.math.bisect(lambda x: x*x + 2.0*x - 1.0
, -3, -2
, lambda x, y: math.fabs(x-y) < tol, 100)
Further examples of the use of these special functions can be found in the next chapter.
3.3 NUMPY ARRAYS
Despite the efforts of the preceding section regarding reflection of C++ Boost.MultiArray
types into Python, in practice, when working in Python, the authors have found the facilities
of NumPy arrays to be far more convenient (NumPy was mentioned briefly in section 1.2).
Specifically, their notational conveniences and the large body of functionality provided by the
NumPy library motivates their use in Python beyond the argument of C++ interoperability.
Indeed, when working in C++, a library dedicated to scientific manipulation of arrays such as
Blitz++
2
wins the authors’ favour for such work over ‘lower-level’ container types like native
C arrays or Boost.MultiArray types. But now to the crux of the matter. If we haven’t made this
point earlier then we’ll make it for the first time now. One of the great strengths of Python is
the ability to drop into C or C++ code ‘when performance counts’. That is, the ability to factor ...