.. _nonexact: The ddg.nonexact module ======================= The module :py:mod:`ddg.nonexact` contains tools to manage and use global defaults for tolerances used in nonexact computations. Here's how to write your own nonexact functions and classes: The general concept is quite simple: We write small functions for elementary nonexact computations that will use the global tolerances if the ``atol`` or ``rtol`` given to them is ``None``. A very simple example is :py:func:`ddg.nonexact.isclose`, which just wraps :py:func:`numpy.isclose`: .. literalinclude:: ../../../../ddg/nonexact.py :language: python :pyobject: isclose The :py:mod:`ddg.nonexact` module contains other functions like :py:func:`ddg.nonexact.isclose`, check its contents to see if it has what you need. Otherwise, you might have to add a function in the style of :py:func:`ddg.nonexact.isclose`. When you write a function with ``atol`` and ``rtol`` arguments, proceed as you normally would, but use these functions where you would normally use numpy functions or explicit computations. Your function can now handle ``None`` as a value of ``atol`` and ``rtol``. Here is a simple example of a finished nonexact function: .. literalinclude:: ../../../../ddg/math/symmetric_matrices.py :language: python :pyobject: is_symmetric When you're writing a class, give it attributes ``atol`` and ``rtol`` that can contain a ``float`` or ``None``. You can then use our nonexact functions inside methods and pass ``self.atol`` and ``self.rtol`` to them. Here is an example of a noneaxct method (of :py:class:`ddg.geometry.quadrics.Quadric`). .. literalinclude:: ../../../../ddg/geometry/quadrics.py :language: python :pyobject: Quadric.conjugate