.. _sub:

sub
===


Computes the element-wise subtraction of vector ``b`` from vector ``a``.


.. contents::
    :local:
    :depth: 1

Description
***********

The ``sub(a, b)`` function performs element by element subtraction of
vector ``a`` and vector ``b``.

.. list-table::
   :header-rows: 1

   * -  Argument 1
     -  Argument 2
     -  Result
     -  Error Code
   * -  +0
     -  +0
     -  +0
     -  Β 
   * -  +0
     -  -0
     -  +0
     -  Β 
   * -  -0
     -  +0
     -  +0
     -  Β 
   * -  -0
     -  -0
     -  -0
     -  Β 
   * -  +\ :math:`\infty`
     -  +\ :math:`\infty`
     -  QNAN
     -  Β 
   * -  +\ :math:`\infty`
     -  -\ :math:`\infty`
     -  +\ :math:`\infty`
     -  Β 
   * -  -\ :math:`\infty`
     -  +\ :math:`\infty`
     -  -\ :math:`\infty`
     -  Β 
   * -  -\ :math:`\infty`
     -  -\ :math:`\infty`
     -  QNAN
     -  Β 
   * -  SNAN
     -  any value
     -  QNAN
     -  Β 
   * -  any value
     -  SNAN
     -  QNAN
     -  Β 


Specifications for special values of the complex functions are
defined according to the following formula:

``sub(x1+i*y1,x2+i*y2) = (x1-x2) + i*(y1-y2)``

Overflow in a complex function occurs (supported in the HA/LA
accuracy modes only) when all RE(x), RE(y), IM(x), IM(y) arguments
are finite numbers, but the real or imaginary part of the computed
result is so large that it does not fit the target precision. In this
case, the function returns \ :math:`\infty` in that part of the result, and sets the
VM Error Status to ``status::overflow`` (overriding any possible
``status::accuracy_warning`` status).


API
***


Syntax
------

**Buffer API**


.. code-block:: cpp

   namespace oneapi::mkl::vm {

   sycl::event sub(sycl::queue & exec_queue,
         std::int64_t n,
         sycl::buffer<T> & a,
         sycl::buffer<T> & b,
         sycl::buffer<T> & y,
         oneapi::mkl::vm::mode mode = oneapi::mkl::vm::mode::not_defined,
         oneapi::mkl::vm::error_handler<T> errhandler = {});

   }



.. code-block:: cpp

   namespace oneapi::mkl::vm {

   sycl::event sub(sycl::queue & exec_queue,
         sycl::buffer<T> & a,
         oneapi::mkl::slice sa,
         sycl::buffer<T> & b,
         oneapi::mkl::slice sb,
         sycl::buffer<T> & y,
         oneapi::mkl::slice sy,
         oneapi::mkl::vm::mode mode = oneapi::mkl::vm::mode::not_defined,
         oneapi::mkl::vm::error_handler<T> errhandler = {});

   }

**USM API**

.. code-block:: cpp

   namespace oneapi::mkl::vm {

   sycl::event sub(sycl::queue & exec_queue,
         std::int64_t n,
         T const * a,
         T const * b,
         T * y,
         std::vector<cl::sycl::event> const & depends = {},
         oneapi::mkl::vm::mode mode = oneapi::mkl::vm::mode::not_defined,
         oneapi::mkl::vm::error_handler<T> errhandler = {});

   }

.. code-block:: cpp

   namespace oneapi::mkl::vm {

   sycl::event sub(sycl::queue & exec_queue,
         T const * a,
         oneapi::mkl::slice sa,
         T const * b,
         oneapi::mkl::slice sb,
         T * y,
         oneapi::mkl::slice sy,
         std::vector<cl::sycl::event> const & depends = {},
         oneapi::mkl::vm::mode mode = oneapi::mkl::vm::mode::not_defined,
         oneapi::mkl::vm::error_handler<T> errhandler = {});

   }


``sub`` supports the following precisions and devices:


.. list-table::
      :header-rows: 1

      * -  T
        -  Devices supported
      * -  ``float``
        -  Host, CPU, and GPU
      * -  ``double``
        -  Host, CPU, and GPU
      * -  ``std::complex<float>``
        -  Host, CPU, and GPU
      * -  ``std::complex<double>``
        -  Host, CPU, and GPU


Input Parameters
----------------

**Buffer API**


exec_queue
   The queue where the routine should be executed.


n
   Specifies the number of elements to be calculated.


a
   The buffer containing the 1st input vector.


sa
   Slice selector for ``a``. See :ref:`data-types` for a description of the |O-MKL| slice type.


b
   The buffer containing the 2nd input vector.


sb
   Slice selector for ``b``. See :ref:`data-types` for a description of the |O-MKL| slice type.


sy
   Slice selector for ``y``. See :ref:`data-types` for a description of the |O-MKL| slice type.


mode
   Overrides the global VM mode setting for this function call. See :ref:`set_mode` function for possible values and their description. This is an optional parameter. The default value is ``mode::not_defined``.


errhandler
   Sets local error handling mode for this function call. See the :ref:`create_error_handler` function for arguments and their descriptions. This is an optional parameter. The local error handler is disabled by default.


**USM API**


exec_queue
   The queue where the routine should be executed.


n
   Specifies the number of elements to be calculated.


a
   Pointer to the 1st input vector.


sa
   Slice selector for ``a``. See :ref:`data-types` for a description of the |O-MKL| slice type.


b
   Pointer to the 2nd input vector.


sb
   Slice selector for ``b``. See :ref:`data-types` for a description of the |O-MKL| slice type.


sy
   Slice selector for ``y``. See :ref:`data-types` for a description of the |O-MKL| slice type.


depends
   Vector of dependent events (to wait for input data to be ready). This is an optional parameter. The default is an empty vector.


mode
   Overrides the global VM mode setting for this function call. See the :ref:`set_mode` function for possible values and their description. This is an optional parameter. The default value is ``mode::not_defined``.


errhandler
   Sets local error handling mode for this function call. See the :ref:`create_error_handler` function for arguments and their descriptions. This is an optional parameter. The local error handler is disabled by default.


Output Parameters
-----------------

**Buffer API**


y
   The buffer containing the output vector.


return value (event)
   Computation end event.


**USM API**


y
   Pointer to the output vector.


return value (event)
   Computation end event.


Examples
********

An example of how to use ``sub`` can be found in the |O-MKL|
installation directory, under:


.. code-block::

   examples/dpcpp/vml/source/vsub.cpp