text: /**
   *
   * @file core_dttmlq.c
   *
   *  PLASMA core_blas kernel
   *  PLASMA is a software package provided by Univ. of Tennessee,
   *  Univ. of California Berkeley and Univ. of Colorado Denver
   *
   * @version 2.6.0
   * @author Hatem Ltaief
   * @author Mathieu Faverge
   * @author Dulceneia Becker
   * @date 2010-11-15
   * @generated d Tue Jan  7 11:44:45 2014
   *
   **/
  #include "common.h"
  
  /***************************************************************************//**
   *
   * @ingroup CORE_double
   *
   *  CORE_dttmlq overwrites the general complex M1-by-N1 tile A1 and
   *  M2-by-N2 tile A2 (N1 == N2) with
   *
   *                        SIDE = 'L'        SIDE = 'R'
   *    TRANS = 'N':         Q * | A1 |       | A1 | * Q
   *                             | A2 |       | A2 |
   *
   *    TRANS = 'C':      Q**T * | A1 |       | A1 | * Q**T
   *                             | A2 |       | A2 |
   *
   *  where Q is a complex unitary matrix defined as the product of k
   *  elementary reflectors
   *
   *    Q = H(1) H(2) . . . H(k)
   *
   *  as returned by CORE_dttqrt.
   *
   *******************************************************************************
   *
   * @param[in] side
   *         @arg PlasmaLeft  : apply Q or Q**T from the Left;
   *         @arg PlasmaRight : apply Q or Q**T from the Right.
   *
   * @param[in] trans
   *         @arg PlasmaNoTrans   :  No transpose, apply Q;
   *         @arg PlasmaTrans :  ConjTranspose, apply Q**T.
   *
   * @param[in] M1
   *         The number of rows of the tile A1. M1 >= 0.
   *
   * @param[in] N1
   *         The number of columns of the tile A1. N1 >= 0.
   *
   * @param[in] M2
   *         The number of rows of the tile A2. M2 >= 0.
   *
   * @param[in] N2
   *         The number of columns of the tile A2. N2 >= 0.
   *
   * @param[in] K
   *         The number of elementary reflectors whose product defines
   *         the matrix Q.
   *
   * @param[in] IB
   *         The inner-blocking size.  IB >= 0.
   *
   * @param[in,out] A1
   *         On entry, the M1-by-N1 tile A1.
   *         On exit, A1 is overwritten by the application of Q.
   *
   * @param[in] LDA1
   *         The leading dimension of the array A1. LDA1 >= max(1,M1).
   *
   * @param[in,out] A2
   *         On entry, the M2-by-N2 tile A2.
   *         On exit, A2 is overwritten by the application of Q.
   *
   * @param[in] LDA2
   *         The leading dimension of the tile A2. LDA2 >= max(1,M2).
   *
   * @param[in] V
   *         The i-th row must contain the vector which defines the
   *         elementary reflector H(i), for i = 1,2,...,k, as returned by
   *         CORE_DTTQRT in the first k rows of its array argument V.
   *
   * @param[in] LDV
   *         The leading dimension of the array V. LDV >= max(1,K).
   *
   * @param[out] T
   *         The IB-by-N1 triangular factor T of the block reflector.
   *         T is upper triangular by block (economic storage);
   *         The rest of the array is not referenced.
   *
   * @param[in] LDT
   *         The leading dimension of the array T. LDT >= IB.
   *
   * @param[out] WORK
   *         Workspace array of size LDWORK-by-N1.
   *
   * @param[in] LDWORK
   *         The dimension of the array WORK. LDWORK >= max(1,IB).
   *
   *******************************************************************************
   *
   * @return
   *          \retval PLASMA_SUCCESS successful exit
   *          \retval <0 if -i, the i-th argument had an illegal value
   *
   ******************************************************************************/
  #if defined(PLASMA_HAVE_WEAK)
  #pragma weak CORE_dttmlq = PCORE_dttmlq
  #define CORE_dttmlq PCORE_dttmlq
  #endif
  int CORE_dttmlq(PLASMA_enum side, PLASMA_enum trans,
                  int M1, int N1, int M2, int N2, int K, int IB,
                  double *A1, int LDA1,
                  double *A2, int LDA2,
                  const double *V, int LDV,
                  const double *T, int LDT,
                  double *WORK, int LDWORK)
  {
      int i, i1, i3, l;
      int NQ, NW;
      int kb;
      int ic = 0;
      int jc = 0;
      int mi1 = M1;
      int mi2 = M2;
      int ni1 = N1;
      int ni2 = N2;
  
      /* Check input arguments */
      if ((side != PlasmaLeft) && (side != PlasmaRight)) {
          coreblas_error(1, "Illegal value of side");
          return -1;
      }
  
      /* NQ is the order of Q */
      if (side == PlasmaLeft) {
          NQ = N2;
          NW = IB;
      }
      else {
          NQ = M2;
          NW = N1;
      }
  
      if ((trans != PlasmaNoTrans) && (trans != PlasmaTrans)) {
          coreblas_error(2, "Illegal value of trans");
          return -2;
      }
      if (M1 < 0) {
          coreblas_error(3, "Illegal value of M1");
          return -3;
      }
      if (N1 < 0) {
          coreblas_error(4, "Illegal value of N1");
          return -4;
      }
      if ((M2 < 0) ||
          ( (side == PlasmaRight) && (M1 != M2) ) ) {
          coreblas_error(5, "Illegal value of M2");
          return -5;
      }
      if ((N2 < 0) ||
          ( (side == PlasmaLeft) && (N1 != N2) ) ) {
          coreblas_error(6, "Illegal value of N2");
          return -6;
      }
      if ((K < 0) ||
          ( (side == PlasmaLeft)  && (K > M1) ) ||
          ( (side == PlasmaRight) && (K > N1) ) ) {
          coreblas_error(7, "Illegal value of K");
          return -7;
      }
      if (IB < 0) {
          coreblas_error(8, "Illegal value of IB");
          return -8;
      }
      if (LDA1 < max(1,M1)){
          coreblas_error(10, "Illegal value of LDA1");
          return -10;
      }
      if (LDA2 < max(1,M2)){
          coreblas_error(12, "Illegal value of LDA2");
          return -12;
      }
      if (LDV < max(1,NQ)){
          coreblas_error(14, "Illegal value of LDV");
          return -14;
      }
      if (LDT < max(1,IB)){
          coreblas_error(16, "Illegal value of LDT");
          return -16;
      }
      if (LDWORK < max(1,NW)){
          coreblas_error(18, "Illegal value of LDWORK");
          return -18;
      }
  
      /* Quick return */
      if ((M1 == 0) || (N1 == 0) || (M2 == 0) || (N2 == 0) || (K == 0) || (IB == 0))
          return PLASMA_SUCCESS;
  
      if (((side == PlasmaLeft) && (trans == PlasmaNoTrans))
          || ((side == PlasmaRight) && (trans != PlasmaNoTrans))) {
          i1 = 0;
          i3 = IB;
      }
      else {
          i1 = ( ( K-1 ) / IB )*IB;
          i3 = -IB;
      }
  
      /* Transpose */
      if (trans == PlasmaNoTrans) {
          trans = PlasmaTrans;
      }
      else {
          trans = PlasmaNoTrans;
      }
  
      for (i = i1; (i > -1) && (i < K); i+=i3) {
          kb = min(IB, K-i);
  
          if (side == PlasmaLeft) {
              mi1 = kb; // M1 - i;
              mi2 = min(i+kb, M2);
              l   = min(kb, max(0, M2-i));
              ic  = i;
          }
          else {
              ni1 = kb;
              ni2 = min(i+kb, N2);
              l   = min(kb, max(0, N2-i));
              jc  = i;
          }
  
          /*
           * Apply H or H' (NOTE: CORE_dparfb used to be CORE_dttrfb)
           */
          CORE_dparfb(
              side, trans, PlasmaForward, PlasmaRowwise,
              mi1, ni1, mi2, ni2, kb, l,
              &A1[LDA1*jc+ic], LDA1,
              A2, LDA2,
              &V[i], LDV,
              &T[LDT*i], LDT,
              WORK, LDWORK);
      }
      return PLASMA_SUCCESS;
  }
  