.. _onemkl_blas_syr2k:

syr2k
=====

Performs a symmetric rank-2k update.

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

The ``syr2k`` routines perform a rank-2k update of an ``n`` x ``n``
symmetric matrix ``C`` by general matrices ``A`` and ``B``. The operation is defined as:

If ``trans`` = ``transpose::nontrans``, 

.. math::

      C \leftarrow alpha*(A*B^T + B*A^T) + beta*C

where ``A`` is ``n`` x ``k`` and ``B`` is ``k`` x ``n``.

If ``trans`` = ``transpose::trans``, 

.. math::

      C \leftarrow alpha*(A^T*B + B^T*A) + beta*C

where ``A`` is ``k`` x ``n`` and ``B`` is ``n`` x ``k``.

In both cases:

- ``alpha`` and ``beta`` are scalars

- ``C`` is symmetric matrix, ``A`` and ``B`` are general matrices

- The inner dimension of both matrix multiplications is ``k``

``syr2k`` supports the following precisions:

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

   * -  T
   * -  ``float``
   * -  ``double``
   * -  ``std::complex<float>``
   * -  ``std::complex<double>``


syr2k (Buffer Version)
**********************

Syntax
------

.. code-block:: cpp

   namespace oneapi::mkl::blas::column_major {
       void syr2k(sycl::queue &queue,
                  oneapi::mkl::uplo upper_lower,
                  oneapi::mkl::transpose trans,
                  std::int64_t n,
                  std::int64_t k,
                  T alpha,
                  sycl::buffer<T,1> &a,
                  std::int64_t lda,
                  sycl::buffer<T,1> &b,
                  std::int64_t ldb,
                  T beta,
                  sycl::buffer<T,1> &c,
                  std::int64_t ldc)
   }

.. code-block:: cpp

   namespace oneapi::mkl::blas::row_major {
       void syr2k(sycl::queue &queue,
                  oneapi::mkl::uplo upper_lower,
                  oneapi::mkl::transpose trans,
                  std::int64_t n,
                  std::int64_t k,
                  T alpha,
                  sycl::buffer<T,1> &a,
                  std::int64_t lda,
                  sycl::buffer<T,1> &b,
                  std::int64_t ldb,
                  T beta,
                  sycl::buffer<T,1> &c,
                  std::int64_t ldc)
   }

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

queue
   The queue where the routine should be executed.

upper_lower
   Specifies whether matrix ``C`` is upper or lower triangular. See :ref:`data-types` for more details.

trans
   Specifies the transposition operation applied as described above. 
   Conjugation is never performed even if ``trans`` = ``transpose::conjtrans``.

n
   Number of rows and columns of matrix ``C``. Must be at least zero.

k
   Inner dimension of matrix multiplications. Must be at least zero.

alpha
   Complex scaling factor for the rank-2k update.

a
   Buffer holding input matrix ``A``. See :ref:`matrix-storage` for more details.

   .. list-table::
      :header-rows: 1
     
      * -
        - ``trans`` = ``transpose::nontrans``
        - ``trans`` = ``transpose::trans`` or ``trans`` = ``transpose::conjtrans``
      * - Column major
        - ``A`` is ``n`` x ``k`` matrix. Size of array ``a`` must be at least ``lda`` * ``k``
        - ``A`` is ``k`` x ``n`` matrix. Size of array ``a`` must be at least ``lda`` * ``n``
      * - Row major
        - ``A`` is ``n`` x ``k`` matrix. Size of array ``a`` must be at least ``lda`` * ``n``
        - ``A`` is ``k`` x ``n`` matrix. Size of array ``a`` must be at least ``lda`` * ``k``

lda
   Leading dimension of matrix ``A``. Must be positive. 

   .. list-table::
      :header-rows: 1
  
      * -
        - ``trans`` = ``transpose::nontrans``
        - ``trans`` = ``transpose::trans`` or ``trans`` = ``transpose::conjtrans``
      * - Column major
        - Must be at least ``n``
        - Must be at least ``k``
      * - Row major
        - Must be at least ``k``
        - Must be at least ``n``

b
   Buffer holding input matrix ``B``. See :ref:`matrix-storage` for more details.

   .. list-table::
      :header-rows: 1
     
      * -
        - ``trans`` = ``transpose::nontrans``
        - ``trans`` = ``transpose::trans`` or ``trans`` = ``transpose::conjtrans``
      * - Column major
        - ``B`` is ``k`` x ``n`` matrix. Size of array ``b`` must be at least ``ldb`` * ``n``
        - ``B`` is ``n`` x ``k`` matrix. Size of array ``b`` must be at least ``ldb`` * ``k``
      * - Row major
        - ``B`` is ``k`` x ``n`` matrix. Size of array ``b`` must be at least ``ldb`` * ``k``
        - ``B`` is ``n`` x ``k`` matrix. Size of array ``b`` must be at least ``ldb`` * ``n``

ldb
   Leading dimension of matrix ``B``. Must be positive. 

   .. list-table::
      :header-rows: 1
  
      * -
        - ``trans`` = ``transpose::nontrans``
        - ``trans`` = ``transpose::trans`` or ``trans`` = ``transpose::conjtrans``
      * - Column major
        - Must be at least ``k``
        - Must be at least ``n``
      * - Row major
        - Must be at least ``n``
        - Must be at least ``k``

c
   Buffer holding input/output matrix ``C``. Size of the buffer must be at least
   ``ldc`` * ``n``. See :ref:`matrix-storage` for more details.

ldc
   Leading dimension of matrix ``C``. Must be positive and at least ``n``.

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

c
   Output buffer overwritten by updated ``C`` matrix.


syr2k (USM Version)
**********************

Syntax
------

.. code-block:: cpp

   namespace oneapi::mkl::blas::column_major {
       sycl::event syr2k(sycl::queue &queue,
                         oneapi::mkl::uplo upper_lower,
                         oneapi::mkl::transpose trans,
                         std::int64_t n,
                         std::int64_t k,
                         T alpha,
                         const T* a,
                         std::int64_t lda,
                         const T* b,
                         std::int64_t ldb,
                         T beta,
                         T* c,
                         std::int64_t ldc,
                         const std::vector<sycl::event> &dependencies = {})
   }

.. code-block:: cpp

   namespace oneapi::mkl::blas::row_major {
       sycl::event syr2k(sycl::queue &queue,
                         oneapi::mkl::uplo upper_lower,
                         oneapi::mkl::transpose trans,
                         std::int64_t n,
                         std::int64_t k,
                         T alpha,
                         const T* a,
                         std::int64_t lda,
                         const T* b,
                         std::int64_t ldb,
                         T beta,
                         T* c,
                         std::int64_t ldc,
                         const std::vector<sycl::event> &dependencies = {})
   }

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

queue
   The queue where the routine should be executed.

upper_lower
   Specifies whether matrix ``C`` is upper or lower triangular. See :ref:`data-types` for more details.

trans
   Specifies the transposition operation applied as described above. 
   Conjugation is never performed even if ``trans`` = ``transpose::conjtrans``.

n
   Number of rows and columns of matrix ``C``. Must be at least zero.

k
   Inner dimension of matrix multiplications. Must be at least zero.

alpha
   Complex scaling factor for the rank-2k update.

a
   Pointer to input matrix ``A``. See :ref:`matrix-storage` for more details.

   .. list-table::
      :header-rows: 1
     
      * -
        - ``trans`` = ``transpose::nontrans``
        - ``trans`` = ``transpose::trans`` or ``trans`` = ``transpose::conjtrans``
      * - Column major
        - ``A`` is ``n`` x ``k`` matrix. Size of array ``a`` must be at least ``lda`` * ``k``
        - ``A`` is ``k`` x ``n`` matrix. Size of array ``a`` must be at least ``lda`` * ``n``
      * - Row major
        - ``A`` is ``n`` x ``k`` matrix. Size of array ``a`` must be at least ``lda`` * ``n``
        - ``A`` is ``k`` x ``n`` matrix. Size of array ``a`` must be at least ``lda`` * ``k``

lda
   Leading dimension of matrix ``A``. Must be positive. 

   .. list-table::
      :header-rows: 1
  
      * -
        - ``trans`` = ``transpose::nontrans``
        - ``trans`` = ``transpose::trans`` or ``trans`` = ``transpose::conjtrans``
      * - Column major
        - Must be at least ``n``
        - Must be at least ``k``
      * - Row major
        - Must be at least ``k``
        - Must be at least ``n``

b
   Pointer to input matrix ``B``. See :ref:`matrix-storage` for more details.

   .. list-table::
      :header-rows: 1
     
      * -
        - ``trans`` = ``transpose::nontrans``
        - ``trans`` = ``transpose::trans`` or ``trans`` = ``transpose::conjtrans``
      * - Column major
        - ``B`` is ``k`` x ``n`` matrix. Size of array ``b`` must be at least ``ldb`` * ``n``
        - ``B`` is ``n`` x ``k`` matrix. Size of array ``b`` must be at least ``ldb`` * ``k``
      * - Row major
        - ``B`` is ``k`` x ``n`` matrix. Size of array ``b`` must be at least ``ldb`` * ``k``
        - ``B`` is ``n`` x ``k`` matrix. Size of array ``b`` must be at least ``ldb`` * ``n``

ldb
   Leading dimension of matrix ``B``. Must be positive. 

   .. list-table::
      :header-rows: 1
  
      * -
        - ``trans`` = ``transpose::nontrans``
        - ``trans`` = ``transpose::trans`` or ``trans`` = ``transpose::conjtrans``
      * - Column major
        - Must be at least ``k``
        - Must be at least ``n``
      * - Row major
        - Must be at least ``n``
        - Must be at least ``k``

c
   Pointer to input/output matrix ``C``. Size of the array must be at least
   ``ldc`` * ``n``. See :ref:`matrix-storage` for more details.

ldc
   Leading dimension of matrix ``C``. Must be positive and at least ``n``.

dependencies
   List of events to wait for before starting computation, if any. If
   omitted, defaults to no dependencies.

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

c
   Pointer to output matrix overwritten by updated ``C`` matrix.

Return Values
-------------

Output event to wait on to ensure computation is complete.