yade.math module

This python module exposes all C++ math functions for Real and Complex types to python. In fact it sort of duplicates import math, import cmath or import mpmath. Also it facilitates migration of old python scripts to high precision calculations.

This module has following purposes:

  1. To reliably test all C++ math functions of arbitrary precision Real and Complex types against mpmath.

  2. To act as a “migration helper” for python scripts which call python mathematical functions that do not work well with mpmath. As an example see math.linspace below and this merge request

  3. To allow writing python math code in a way that mirrors C++ math code in Yade. As a bonus it will be faster than mpmath because mpmath is a purely python library (which was one of the main difficulties when writing lib/high-precision/ToFromPythonConverter.hpp)

  4. To test Eigen NumTraits

  5. To test CGAL NumTraits

If another C++ math function is needed it should be added to following files:

  1. lib/high-precision/MathFunctions.hpp

  2. py/high-precision/_math.cpp

  3. py/tests/testMath.py

  4. py/tests/testMathHelper.py

If another python math function does not work well with mpmath it should be added below, and original calls to this function should call this function instead, e.g. numpy.linspace(…) is replaced with yade.math.linspace(…).

The RealHP<n> higher precision math functions can be accessed in python by using the .HPn module scope. For example:

import yade.math as mth
mth.HP2.sqrt(2) # produces square root of 2 using RealHP<2> precision
mth.sqrt(2)     # without using HPn module scope it defaults to RealHP<1>
class yade._math.HP1
class yade._math.HP2