Accelerated UFuncs
==================

Variants of some Numpy UFuncs that use Intel's Vector Math Library (VML) are
found in the ``accelerate.mkl`` package in the ``ufuncs`` object. In comparison
to Numpy's built-in UFuncs, Accelerated UFuncs have the following properties:

*Performance*
  Because Accelerated UFuncs call functions from VML, which is a library
  optimised for high performance using multiple threads and SIMD instructions,
  performance may be increased when calling Accelerated UFuncs in comparison to
  calling Numpy UFuncs. The performance increase will only be obtained for
  contiguous arguments. For non-contiguous arguments, performance comparable to
  Numpy's will be observed.
*Accuracy*
  - Accelerated UFuncs produce similar results to their Numpy equivalents for
    the range of finite values, up to a given relative tolerance.
  - The tolerance varies between functions and data types, and is specified for
    each combination in the following section.
  - For the range of infinite and NaN values, the majority of results computed
    by Accelerated UFuncs will be equal to those computed by their Numpy
    counterparts. However, this is not guaranteed; for example, an input for
    which the Numpy UFunc produces a result of ``x + inf*j``, the equivalent
    Accelerated UFunc may produce a result of ``y + inf*j``, where ``x != y``.
  - Towards the edge of the domain of a data type (e.g. near ``3.4e+38`` for
    ``float`` and ``1.79e+308`` for ``double`` and values of similar magnitude
    at the negative end of the domain) some Accelerated UFuncs may produce
    results which differ from Numpy UFuncs, or may raise ``FloatingPointError``
    or ``ZeroDivisionError`` exceptions. These functions are marked `domain
    edge warning` in the `Accuracy` column of the tables in the following
    sections.
  - Some numpy implementations of functions that operate in the complex domain
    have branch cuts which differ from those in MKL, where this has been
    identified in testing these functions are marked `branch cut warning` in
    the `Accuracy` column of the tables in the following sections. This warning
    may also be present in the case of implementations which contain incorrect
    branch cuts.
  - Denormal input values may be treated as zero by Accelerated UFuncs, and
    denormal output values may be flushed to zero.
  - The accuracy reported is approximate and related to the least accurate
    value encountered when testing with contiguous input arguments.
    Non-contiguous arguments are more directly exposed to system math library
    implementations and so their accuracy is not commented on.
*Exception handling*
  For the range of finite values, exceptions will not be raised by Accelerated
  UFuncs, just as they would not by Numpy. For the infinite and NaN ranges,
  Accelerated UFuncs may raise ``FloatingPointError`` or ``ZeroDivisionError``
  exceptions in cases when Numpy would not, and vice-versa.

Supported functions are described in the following sections.

Arithmetic Functions
--------------------

+------------------------+---------+------------------------------------------+
| Function               | Type    | Accuracy                                 |
+========================+=========+==========================================+
| ``add(x, y)``          | ``f4``  | ``rtol=1.0e-7``                          |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.0e-15``                         |
|                        +---------+------------------------------------------+
|                        | ``c8``  | ``rtol=1.0e-7``                          |
|                        +---------+------------------------------------------+
|                        | ``c16`` | ``rtol=1.0e-15``                         |
+------------------------+---------+------------------------------------------+
| ``subtract(x, y)``     | ``f4``  | ``rtol=1.e-7``                           |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``                          |
|                        +---------+------------------------------------------+
|                        | ``c8``  | ``rtol=1.e-7``                           |
|                        +---------+------------------------------------------+
|                        | ``c16`` | ``rtol=1.e-15``                          |
+------------------------+---------+------------------------------------------+
| ``square(x)``          | ``f4``  | ``rtol=1.e-7``                           |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``                          |
+------------------------+---------+------------------------------------------+
| ``multiply(x, y)``     | ``f4``  | ``rtol=1.e-7``                           |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``                          |
|                        +---------+------------------------------------------+
|                        | ``c8``  | ``rtol=1.e-6``                           |
|                        +---------+------------------------------------------+
|                        | ``c16`` | ``rtol=1.e-15``                          |
+------------------------+---------+------------------------------------------+
| ``absolute(x)``        | ``f4``  | ``rtol=1.e-6``                           |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``                          |
+------------------------+---------+------------------------------------------+


Power and Root Functions
------------------------

+------------------------+---------+------------------------------------------+
| Function               | Type    | Accuracy                                 |
+========================+=========+==========================================+
| ``reciprocal(x)``      | ``f4``  | ``rtol=1.e-7``                           |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``                          |
+------------------------+---------+------------------------------------------+
| ``true_divide(x, y)``  | ``f4``  | ``rtol=1.e-7``                           |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``                          |
|                        +---------+------------------------------------------+
|                        | ``c8``  | ``rtol=1.e-6``                           |
|                        +---------+------------------------------------------+
|                        | ``c16`` | ``rtol=1.e-15``                          |
+------------------------+---------+------------------------------------------+
| ``sqrt(x, y)``         | ``f4``  | ``rtol=1.e-6``                           |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``                          |
|                        +---------+------------------------------------------+
|                        | ``c8``  | ``rtol=1.e-6``, domain edge warning      |
|                        +---------+------------------------------------------+
|                        | ``c16`` | ``rtol=1.e-15``, domain edge warning     |
+------------------------+---------+------------------------------------------+
| ``power(x, y)``        | ``f4``  | ``rtol=1.e-7``                           |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``                          |
+------------------------+---------+------------------------------------------+
| ``hypot(x, y)``        | ``f4``  | ``rtol=1.e-6``                           |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``                          |
+------------------------+---------+------------------------------------------+


Exponential and Logarithmic Functions
-------------------------------------

+------------------------+---------+------------------------------------------+
| Function               | Type    | Accuracy                                 |
+========================+=========+==========================================+
| ``exp(x)``             | ``f4``  | ``rtol=1.e-6``                           |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``                          |
|                        +---------+------------------------------------------+
|                        | ``c8``  | ``rtol=1.e-6``, domain edge warning      |
|                        +---------+------------------------------------------+
|                        | ``c16`` | ``rtol=1.e-15``, domain edge warning     |
+------------------------+---------+------------------------------------------+
| ``expm1(x)``           | ``f4``  | ``rtol=1.e-6``                           |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``                          |
+------------------------+---------+------------------------------------------+
| ``log(x)``             | ``f4``  | ``rtol=1.e-6``                           |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``                          |
|                        +---------+------------------------------------------+
|                        | ``c8``  | ``rtol=1.e-5``                           |
|                        +---------+------------------------------------------+
|                        | ``c16`` | ``rtol=1.e-13``                          |
+------------------------+---------+------------------------------------------+
| ``log10(x)``           | ``f4``  | ``rtol=1.e-6``                           |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``                          |
|                        +---------+------------------------------------------+
|                        | ``c8``  | ``rtol=1.e-5``, domain edge warning      |
|                        +---------+------------------------------------------+
|                        | ``c16`` | ``rtol=1.e-13``, domain edge warning     |
+------------------------+---------+------------------------------------------+
| ``log1p(x)``           | ``f4``  | ``rtol=1.e-6``                           |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``                          |
+------------------------+---------+------------------------------------------+


Trigonometric Functions
-----------------------

+------------------------+---------+------------------------------------------+
| Function               | Type    | Accuracy                                 |
+========================+=========+==========================================+
| ``cos(x)``             | ``f4``  | ``rtol=1.e-6``, domain edge warning      |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``, domain edge warning     |
|                        +---------+------------------------------------------+
|                        | ``c8``  | ``rtol=1.e-6``, domain edge warning      |
|                        +---------+------------------------------------------+
|                        | ``c16`` | ``rtol=1.e-15``, domain edge warning     |
+------------------------+---------+------------------------------------------+
| ``sin(x)``             | ``f4``  | ``rtol=1.e-5``, domain edge warning      |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``, domain edge warning     |
|                        +---------+------------------------------------------+
|                        | ``c8``  | ``rtol=1.e-6``, domain edge warning      |
|                        +---------+------------------------------------------+
|                        | ``c16`` | ``rtol=1.e-15``, domain edge warning     |
+------------------------+---------+------------------------------------------+
| ``tan(x)``             | ``f4``  | ``rtol=1.e-6``, domain edge warning      |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``, domain edge warning     |
|                        +---------+------------------------------------------+
|                        | ``c8``  | ``rtol=5.e-4``, domain edge warning      |
|                        +---------+------------------------------------------+
|                        | ``c16`` | ``rtol=5.e-14``, domain edge warning     |
+------------------------+---------+------------------------------------------+
| ``arccos(x)``          | ``f4``  | ``rtol=1.e-6``, branch cut warning       |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``, branch cut warning      |
|                        +---------+------------------------------------------+
|                        | ``c8``  | ``rtol=1.e-5``, domain edge warning,     |
|                        |         |                 branch cut warning       |
|                        +---------+------------------------------------------+
|                        | ``c16`` | ``rtol=1.e-14``, domain edge warning,    |
|                        |         |                  branch cut warning      |
+------------------------+---------+------------------------------------------+
| ``arcsin(x)``          | ``f4``  | ``rtol=1.e-6``, branch cut warning       |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``, branch cut warning      |
|                        +---------+------------------------------------------+
|                        | ``c8``  | ``rtol=1.e-3``, domain edge warning,     |
|                        |         |                  branch cut warning      |
|                        +---------+------------------------------------------+
|                        | ``c16`` | ``rtol=1.e-12``, domain edge warning,    |
|                        |         |                  branch cut warning      |
+------------------------+---------+------------------------------------------+
| ``arctan(x)``          | ``f4``  | ``rtol=1.e-6``                           |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``                          |
|                        +---------+------------------------------------------+
|                        | ``c8``  | ``rtol=1.e-6``                           |
|                        +---------+------------------------------------------+
|                        | ``c16`` | ``rtol=1.e-15``                          |
+------------------------+---------+------------------------------------------+
| ``arctan2(x)``         | ``f4``  | ``rtol=1.e-6``                           |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``                          |
+------------------------+---------+------------------------------------------+


Hyperbolic Functions
--------------------

+------------------------+---------+------------------------------------------+
| Function               | Type    | Accuracy                                 |
+========================+=========+==========================================+
| ``cosh(x)``            | ``f4``  | ``rtol=1.e-6``, domain edge warning      |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``, domain edge warning     |
|                        +---------+------------------------------------------+
|                        | ``c8``  | ``rtol=1.e-6``, domain edge warning      |
|                        +---------+------------------------------------------+
|                        | ``c16`` | ``rtol=1.e-15``, domain edge warning     |
+------------------------+---------+------------------------------------------+
| ``sinh(x)``            | ``f4``  | ``rtol=1.e-6``, domain edge warning      |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``, domain edge warning     |
|                        +---------+------------------------------------------+
|                        | ``c8``  | ``rtol=1.e-6``, domain edge warning      |
|                        +---------+------------------------------------------+
|                        | ``c16`` | ``rtol=1.e-15``, domain edge warning     |
+------------------------+---------+------------------------------------------+
| ``tanh(x)``            | ``f4``  | ``rtol=1.e-6``, domain edge warning      |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``, domain edge warning     |
|                        +---------+------------------------------------------+
|                        | ``c8``  | ``rtol=1.e-6``, domain edge warning      |
|                        +---------+------------------------------------------+
|                        | ``c16`` | ``rtol=1.e-15``, domain edge warning     |
+------------------------+---------+------------------------------------------+
| ``arccosh(x)``         | ``f4``  | ``rtol=1.e-6``                           |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``                          |
|                        +---------+------------------------------------------+
|                        | ``c8``  | ``rtol=1.e-5``, domain edge warning      |
|                        +---------+------------------------------------------+
|                        | ``c16`` | ``rtol=1.e-14``, domain edge warning     |
+------------------------+---------+------------------------------------------+
| ``arcsinh(x)``         | ``f4``  | ``rtol=1.e-6``                           |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=1.e-15``                          |
|                        +---------+------------------------------------------+
|                        | ``c8``  | ``rtol=5.e-5``, domain edge warning      |
|                        +---------+------------------------------------------+
|                        | ``c16`` | ``rtol=1.e-13``, domain edge warning     |
+------------------------+---------+------------------------------------------+
| ``arctanh(x)``         | ``f4``  | ``rtol=1.e-5``, branch cut warning       |
|                        +---------+------------------------------------------+
|                        | ``f8``  | ``rtol=5.e-11``, branch cut warning      |
|                        +---------+------------------------------------------+
|                        | ``c8``  | ``rtol=1.e-4``, domain edge warning,     |
|                        |         |                 branch cut warning       |
|                        +---------+------------------------------------------+
|                        | ``c16`` | ``rtol=5.e-14``, domain edge warning,    |
|                        |         |                  branch cut warning      |
+------------------------+---------+------------------------------------------+


