Example #1
0
static int LU1(ATL_CINT M, ATL_CINT N, ATL_CINT j, TYPE *A, ATL_CINT lda,
               int *ipiv)
/*
 * Performs an LU factorization on jth column.  N is the full width of
 * column panel, A is ptr to beginning of panel.
 * RETURNS: 0 on success, non-zero if no non-zero pivot exists
 */
{
   #ifdef TCPLX
      ATL_CINT lda2 = lda+lda;
      TYPE invs[2];
      const TYPE none[2] = {ATL_rnone, ATL_rzero};
   #else
      #define lda2 lda
      #define none ATL_rnone
   #endif
   TYPE *Ac = A + j*lda2;  /* active column */
   TYPE pivval=Ac[j];
   ATL_INT ip;

   ipiv[j] = ip = j + cblas_iamax(M-j, Ac+(j SHIFT), 1);
   #ifdef TCPLX
      pivval = Mabs(Ac[ip+ip]) + Mabs(Ac[ip+ip+1]);
   #else
      pivval = Ac[ip];
   #endif
   if (pivval != ATL_rzero)
   {
      if (ip != j)
         cblas_swap(N, A+(j SHIFT), lda, A+(ip SHIFT), lda);
      #ifdef TCPLX
         if (pivval >= ATL_laSAFMIN)
         {
            TYPE invs[2];
            Mjoin(PATL,cplxinvert)(1, Ac+j+j, 1, invs, 1);
            cblas_scal(M-j-1, invs, Ac+j+j+2, 1);
         }
         else
            Mjoin(PATL,cplxdivide)(M-j-1, Ac+j+j, Ac+j+j+2, 1, Ac+j+j+2, 1);
      #else
         if (Mabs(pivval) >= ATL_laSAFMIN)
            cblas_scal(M-j-1, ATL_rone/pivval, Ac+j+1, 1);
         else
         {
            ATL_INT i;
            for (i=j+1; i < M; i++)
               Ac[j] /= pivval;
         }
      #endif
      return(0);
   }
   return(1);
}
Example #2
0
/*
 *             Automatically Tuned Linear Algebra Software v3.10.2
 *                    (C) Copyright 1999 R. Clint Whaley
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *   1. Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *   2. Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions, and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *   3. The name of the ATLAS group or the names of its contributers may
 *      not be used to endorse or promote products derived from this
 *      software without specific written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */
#ifdef TCPLX
static int ATL_potrf2(const int N, TYPE *A, const int lda)
{
   int j, k;
   static const TYPE one[2] = {ATL_rone, ATL_rzero};
   static const TYPE none[2] = {ATL_rnone, ATL_rzero};
   const size_t lda2 = lda+lda;
   TYPE Ajj, *Ac=A, *An=A+lda2;

   for (k=j=0; j != N; j++, k += 2)
   {
      Ajj = Ac[k] - llt_dot(k, Ac, 1, Ac, 1);
      Ac[k+1] = ATL_rzero;
      if (Ajj > ATL_rzero)
      {
         Ac[k] = Ajj = sqrt(Ajj);
         if (j != N-1)
         {
            llt_scal(j, ATL_rnone, Ac+1, 2);
            cblas_gemv(CblasColMajor, CblasTrans, j, N-j-1, none,
                       An, lda, Ac, 1, one, An+k, lda);
            llt_scal(j, ATL_rnone, Ac+1, 2);
            llt_rscal(N-j-1, ATL_rone/Ajj, An+k, lda);
            Ac = An;
            An += lda2;
         }
      }
      else
      {
         Ac[k] = Ajj;
         return(j+1);
      }
   }
   return(0);
}
#else  /* real version */
static int ATL_potrf2(const int N, TYPE *A, const int lda)
{
   int j;
   TYPE Ajj, *Ac=A, *An=A+lda;

   for (j=0; j != N; j++)
   {
      Ajj = Ac[j] - cblas_dot(j, Ac, 1, Ac, 1);
      if (Ajj > ATL_rzero)
      {
         Ac[j] = Ajj = sqrt(Ajj);
         if (j != N-1)
         {
            cblas_gemv(CblasColMajor, CblasTrans, j, N-j-1, ATL_rnone,
                       An, lda, Ac, 1, ATL_rone, An+j, lda);
            cblas_scal(N-j-1, ATL_rone/Ajj, An+j, lda);
            Ac = An;
            An += lda;
         }
      }
      else
      {
         Ac[j] = Ajj;
         return(j+1);
      }
   }
   return(0);
}
Example #3
0
static int L2LU(const int M, const int N, TYPE *A, const int lda, int *ipiv)
/*
 * Complex Level 2 based left-looking LU
 */
{
   TYPE *Ac=A;
   TYPE t0, tmp[2];
   const TYPE one[2] = {ATL_rone, ATL_rzero}, none[2] = {ATL_rnone, ATL_rzero};
   const int MN=Mmin(M,N), MN_1=MN-1, lda2=lda+lda;
   int ip, ip2, j, j2, jn, jn2, iret=0;

   for (j=0, j2=0, jn=1, jn2=2; j != MN; j=jn++, j2 += 2, jn2 += 2)
   {
      ipiv[j] = ip = j + cblas_iamax(M-j, Ac+j2, 1);
      ip2 = ip + ip;
      if (Ac[ip2] != ATL_rzero || Ac[ip2+1] != ATL_rzero)
      {
         Mjoin(PATL,cplxinvert)(1, Ac+ip2, 1, tmp, 1);
         cblas_swap(N, A+j2, lda, A+ip2, lda);
         cblas_scal(M-jn, tmp, Ac+jn2, 1);
         if (j != MN_1)
         {
            Ac += lda2;
            cblas_trsv(CblasColMajor, CblasLower, CblasNoTrans, CblasUnit, jn,
                       A, lda, Ac, 1);
            cblas_gemv(CblasColMajor, CblasNoTrans, M-jn, jn, none,
                       A+jn2, lda, Ac, 1, one, Ac+jn2, 1);
         }
      }
      else if (!iret) iret = jn;
   }
   return(iret);
}
Example #4
0
static int L2LU(const int M, const int N, TYPE *A, const int lda, int *ipiv)
/*
 * Level 2 based left-looking LU
 */
{
   TYPE *Ac=A;
   TYPE t0;
   const int MN=Mmin(M,N), MN_1=MN-1;
   int ip, j, jn, iret=0;

   if (N == 2) return(LU2(M, A, lda, ipiv));
   for (j=0, jn=1; j != MN; j=jn++)
   {
      ipiv[j] = ip = j + cblas_iamax(M-j, Ac+j, 1);
      t0 = Ac[ip];
      if (t0 != ATL_rzero)
      {
         MySwap(N, A+j, lda, ip-j);
         cblas_scal(M-jn, ATL_rone/t0, Ac+jn, 1);
         if (j != MN_1)
         {
            Ac += lda;
            cblas_trsv(CblasColMajor, CblasLower, CblasNoTrans, CblasUnit, jn,
                       A, lda, Ac, 1);
            cblas_gemv(CblasColMajor, CblasNoTrans, M-jn, jn, ATL_rnone,
                       A+jn, lda, Ac, 1, ATL_rone, Ac+jn, 1);
         }
      }
      else if (!iret) iret = jn;
   }
   return(iret);
}
Example #5
0
void ATL_larfg(ATL_CINT N, TYPE *ALPHA, TYPE *X, ATL_CINT INCX, TYPE *TAU)
{

#ifdef TREAL
      TYPE ONE=1.0, ZERO=0.0, BETA, BETAp, RSAFMN, SAFMAX, XNORM;
      int    j, KNT;

      if (N < 1)
      {
         *TAU = ZERO;
         return;
      }

      XNORM = cblas_nrm2(N-1, X, INCX);     /* Get the norm2 .                */

      if (XNORM == ZERO)
      {
/*
 *        H  =  I
 */
         *TAU = ZERO;
      } else
      {
         BETAp = ATL_lapy2((*ALPHA), XNORM);/* Get sqrt(a^2+b^2)              */
         BETA = BETAp;                      /* Assume ALPHA < 0               */
         if ((*ALPHA) > 0) BETA = 0.-BETAp; /* Change if assumed wrong.       */

         if (BETAp < ATL_laSAFMIN)
         {
/*
 *           XNORM, BETA may be inaccurate; scale X and recompute them
 */
            RSAFMN = ONE / ATL_laSAFMIN;    /* Set a maximum                  */
            KNT = 0;

            while (BETAp < ATL_laSAFMIN)
            {
               KNT++;
               cblas_scal(N-1, RSAFMN, X, INCX);
               BETA *= RSAFMN;
               BETAp *= RSAFMN;
               *ALPHA *= RSAFMN;
            }
/*
 *          New BETA is at most 1, at least SAFMIN
 */
            XNORM = cblas_nrm2(N-1, X, INCX);
            BETA = ATL_lapy2((*ALPHA), XNORM);   /* Will always be positive   */
            if ((*ALPHA) > 0) BETA = -BETA; /* -SIGN(BETA, ALPHA)             */
            *TAU = (BETA-(*ALPHA)) / BETA;
            cblas_scal(N-1, ONE/((*ALPHA)-BETA), X, INCX);

/*
 *          If ALPHA is subnormal, it may lose relative accuracy
 */
            *ALPHA = BETA;
            for (j=0; j<KNT; j++)
            {
               (*ALPHA) *= ATL_laSAFMIN;
            }
         } else                             /* General case                   */
         {
            *TAU = (BETA-(*ALPHA)) / BETA;
            cblas_scal(N-1, ONE / ((*ALPHA)-BETA), X, INCX);
            *ALPHA = BETA;
         }
      }
      return;
/*
 *     End of  Real Precision ATL_larfg
 */
#else
/*
 *     Beginning of  Complex  Precision ATL_larfg
 */
      TYPE ONE=1.0, ZERO=0.0, BETA, BETAp, RSAFMN, SAFMAX, XNORM, ALPHI, ALPHR;
      TYPE ONEVAL[2] =  {ATL_rone, ATL_rzero};
      int j, KNT;

      if ( N < 0)
      {
/*
 *        H  =  I
 */
         *(TAU)  = 0.0;
         *(TAU + 1) = 0.0;
         return;
      }

      XNORM = cblas_nrm2(N-1, X, INCX);     /* Get the nrm2                   */

      ALPHR = *( ALPHA) ;
      ALPHI = *( ALPHA + 1) ;

      if ( (XNORM == ZERO) &&  (ALPHI == ZERO)  )
      {
/*
 *        H  =  I
 */
        *(TAU)  = 0.0;
        *(TAU + 1) = 0.0;
      }
      else
      {

         BETAp = ATL_lapy3(ALPHR, ALPHI, XNORM); /* Get sqrt(a^2 + b^2 + c^2) */
         BETA = BETAp;                      /* Assume ALPHA < 0               */
         if ( (*ALPHA) > 0) BETA = 0. - BETAp;   /* Change if assumed wrong   */

         RSAFMN = ONE / ATL_laSAFMIN ;

         if ( BETAp  <  ATL_laSAFMIN )
         {
/*
 *           XNORM, BETA may be inaccurate; scale X and recompute them
 */
            KNT = 0;
            while ( BETAp < ATL_laSAFMIN )
            {
               KNT++;
               #ifdef DCPLX
                  cblas_zdscal(N-1, RSAFMN, X, INCX);
               #else
                  cblas_csscal(N-1, RSAFMN, X, INCX);
               #endif
               BETA *= RSAFMN;
               BETAp *= RSAFMN;
               ALPHI = ALPHI*RSAFMN;
               ALPHR = ALPHR*RSAFMN;
            }

/*
 *           New BETA is at most 1, at least SAFMIN
 */
            XNORM = cblas_nrm2(N-1, X, INCX);
            *(ALPHA) = ALPHR;
            *(ALPHA + 1) = ALPHI;

            BETA = ATL_lapy3(ALPHR, ALPHI,
                                          XNORM);/* Will always be positive   */
            if (ALPHR > 0) BETA = -BETA;    /* -SIGN(BETA, ALPHR)             */
            *(TAU) = ( BETA-ALPHR ) / BETA ;
            *(TAU + 1) =  (-1.0 * ALPHI) / BETA ;
/*          Modify alpha   to alpha - beta,  which is equal to alphar -beta   */
            *(ALPHA) = *(ALPHA) - BETA;
/*          Perform complex division before scaling the X vector              */
            ATL_ladiv( ONEVAL,  ALPHA, ALPHA);   /* ALPHA will have the result*/
            cblas_scal(N-1, ALPHA, X, INCX);
/*
 *           If ALPHA is subnormal, it may lose relative accuracy
 */
            *(ALPHA) = BETA;                /* Real Part of alpha             */
            for (j=0; j<KNT; j++)
            {
               (*ALPHA) *= ATL_laSAFMIN;
            }
            *(ALPHA + 1) = 0.0;             /* Set Imaginary part to Zero     */
        }
        else                                /* BETA > SAFMIN                  */
        {

            *(TAU) = ( BETA-ALPHR ) / BETA ;
            *(TAU + 1) =  (-1.0 * ALPHI) / BETA ;

/*          Modify alpha   to alpha - beta, which is equal to alphar -beta    */
            *(ALPHA) = *(ALPHA) - BETA ;
/*          Perform complex division before scaling the X vector              */
            ATL_ladiv( ONEVAL,  ALPHA, ALPHA);
            cblas_scal(N-1, ALPHA, X, INCX);
            *(ALPHA) = BETA;                /* Real Part of alpha             */
            *(ALPHA + 1) = 0.0;             /* Set Imaginary part to Zero     */
           }
      }
      return;
#endif
}                                           /* END ATL_larfg                  */
Example #6
0
/*
 *             Automatically Tuned Linear Algebra Software v3.11.28
 *                    (C) Copyright 1999 R. Clint Whaley
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *   1. Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *   2. Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions, and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *   3. The name of the ATLAS group or the names of its contributers may
 *      not be used to endorse or promote products derived from this
 *      software without specific written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */
static int ATL_potrf2(const int N, TYPE *A, const int lda)
{
#ifdef TREAL
    TYPE Ajj, *Ac=A;
    const int N_1 = N-1;
    int j;

    for (j=0; j != N_1; j++, Ac += lda)
    {
       Ajj = Ac[j] - cblas_dot(j, A+j, lda, A+j, lda);

       if (Ajj > ATL_rzero)
       {
          Ac[j] = Ajj = sqrt(Ajj);
          cblas_gemv(CblasColMajor, CblasNoTrans, N-j-1, j, ATL_rnone,
                     A+j+1, lda, A+j, lda, ATL_rone, Ac+j+1, 1);
          cblas_scal(N-j-1, ATL_rone/Ajj, Ac+j+1, 1);
       }
       else
       {
          Ac[j] = Ajj;
          return(j+1);
       }
    }
    Ajj = Ac[j] - cblas_dot(j, A+j, lda, A+j, lda);
    if (Ajj > ATL_rzero) Ac[j] = Ajj = sqrt(Ajj);
    else
    {
       Ac[j] = Ajj;
       return(N);
    }
#else
    TYPE Ajj, *Ac=A;
    TYPE one[2] = {ATL_rone, ATL_rzero};
    TYPE none[2] = {ATL_rnone, ATL_rzero};
    const int N_1 = N-1, lda2 = lda<<1;
    int j, j2;

    for (j2=j=0; j != N_1; j++, j2 += 2, Ac += lda2)
    {
       Ajj = Ac[j2];
       cblas_dotc_sub(j, A+j2, lda, A+j2, lda, Ac+j2);
       Ajj -= Ac[j2];

       if (Ajj > ATL_rzero)
       {
          Ac[j2] = Ajj = sqrt(Ajj);
          llt_scal(j, ATL_rnone, A+j2+1, lda2);
          cblas_gemv(CblasColMajor, CblasNoTrans, N-j-1, j, none,
                     A+j2+2, lda, A+j2, lda, one, Ac+j2+2, 1);
          llt_scal(j, ATL_rnone, A+j2+1, lda2);
          llt_scal((N-j-1)<<1, ATL_rone/Ajj, Ac+j2+2, 1);
       }
       else
       {
          Ac[j2] = Ajj;
          return(j+1);
       }
    }
    Ajj = Ac[j2];
    cblas_dotc_sub(j, A+j2, lda, A+j2, lda, Ac+j2);
    Ajj -= Ac[j2];
    if (Ajj > ATL_rzero) Ac[j2] = sqrt(Ajj);
    else
    {
       Ac[j2] = Ajj;
       return(N);
    }
#endif
   return(0);
}
Example #7
0
static int LU2(const int M, TYPE *A, const int lda, int *ipiv)
/*
 * factors 2 cols of LU, applies all updated to 2nd call during ininitial
 * iamax to save time
 */
{
   int ip, iret=0;
   TYPE *A1 = A + lda;
   register TYPE t0, t1, scal0, scal1, amax=ATL_rzero;
   int i, imax=(-1);

   *ipiv = ip = cblas_iamax(M, A, 1);
   t0 = A[ip];
   if (t0 != ATL_rzero)
   {
      if (Mabs(t0) >= ATL_laSAFMIN)
      {
         t1 = A1[ip];
         A[ip] = *A; A1[ip] = *A1;
         *A = t0; *A1 = t1;
         scal0 = ATL_rone / t0; scal1 = -t1;
         for (i=1; i != M; i++)
         {
            t0 = A[i]; t1 = A1[i];
            t0 *= scal0;
            t1 += t0 * scal1;
            A[i] = t0; A1[i] = t1;
            if (t1 < ATL_rzero) t1 = -t1;
            if (t1 > amax) { amax = t1; imax = i; }
         }
      }
      else  /* can't safely invert pivot, so must actually divide */
      {
         t1 = A1[ip];
         A[ip] = *A; A1[ip] = *A1;
         *A = t0; *A1 = t1;
         scal0 = t0; scal1 = -t1;
         for (i=1; i != M; i++)
         {
            t0 = A[i]; t1 = A1[i];
            t0 /= scal0;
            t1 += t0 * scal1;
            A[i] = t0; A1[i] = t1;
            if (t1 < ATL_rzero) t1 = -t1;
            if (t1 > amax) { amax = t1; imax = i; }
         }
      }
      if (amax != ATL_rzero)
      {
         ipiv[1] = imax;
         t0 = A[imax]; t1 = A1[imax];
         A[imax] = A[1]; A1[imax] = A1[1];
         A[1] = t0; A1[1] = t1;
         if (Mabs(t1) >= ATL_laSAFMIN)
            cblas_scal(M-2, ATL_rone/t1, A1+2, 1);
         else
            for (i=2; i < M; i++)
               A1[i] /= t1;
      }
      else
      {
         if (imax != -1) ipiv[1] = imax;
         else ipiv[1] = 1;
         iret = 2;
      }
   }
   else
   {
      imax = 1 + cblas_iamax(M-1, A1+1, 1);
      amax = A1[imax];
      iret=1;
      if (amax != ATL_rzero)
      {
         ipiv[1] = imax;
         t0 = A[imax]; t1 = A1[imax];
         A[imax] = A[1]; A1[imax] = A1[1];
         A[1] = t0; A1[1] = t1;
         if (Mabs(t1) >= ATL_laSAFMIN)
            cblas_scal(M-2, ATL_rone/t1, A1+2, 1);
         else
            for (i=2; i < M; i++)
               A1[i] /= t1;
      }
      else
      {
         if (imax != -1) ipiv[1] = imax;
         else ipiv[1] = 1;
      }
   }
   return(iret);
}
Example #8
0
template <typename IndexType, typename ValueType> void proj_to_lp_cpu(csr_matrix<IndexType, ValueType> &inputSet,
        ValueType * minNormVector, IndexType inSetDim, IndexType vectorDim, ValueType tollerance) {
    ValueType lpShift = (ValueType) 10; //Установим начальное смещение, оно должно быть очень большим
    //переместим наш политоп в соответствии с этим смещением, это будет означать
    //что мы переместили начало координат в эту точку, что соответствует тому что мы отнимим
    //от вектора b из уравнения Ax <=b следующую величину b + t * A * c (с = [1])
    ValueType* vshift = (ValueType *) malloc(inSetDim * sizeof (ValueType));
    ValueType* t_C = (ValueType *) malloc((vectorDim - 1) * sizeof (ValueType));
    for (IndexType i = 0; i < vectorDim - 1; i++) {
        t_C[i] = -lpShift;
    }

    IndexType maxApprIters = 10;
    ValueType *x_s = new_host_array<ValueType > (vectorDim);
    ValueType *delta_x = new_host_array<ValueType > (vectorDim);
    ValueType* v_t = new_host_array<ValueType > (vectorDim); //- 1); //(ValueType *) malloc((vectorDim -1) * sizeof (ValueType));

    IndexType *kvec = new_host_array<IndexType>(2 * inputSet.num_cols + 1 );
    IndexType *kvec_old = new_host_array<IndexType>(2 * inputSet.num_cols + 1 );
    IndexType *basisVecInx = new_host_array<IndexType>(2 * inputSet.num_cols + 1);
    IndexType baselen = 0;

    for (IndexType i = 0; i < 2 * inputSet.num_cols + 1; i++) {
        kvec[i] = 0;
        kvec_old[i] = 0;
    }

    //Начальный x_s это ноль
    cblas_scal(vectorDim, 0.0, x_s, 1);
    for (IndexType apprIt = 0; apprIt < maxApprIters; apprIt++) {
        //Получаем новое B
        cblas_copy(vectorDim - 1, t_C, 1, v_t, 1);
        cblas_axpy(vectorDim - 1, -1.0, x_s, 1, v_t, 1);
        //std::cout << "Vector V_t\n";
        //printMatrixCPU(vectorDim - 1, 1, v_t);
        cblas_copy(vectorDim, x_s, 1, delta_x, 1);
        inputSet.num_rows--;
        spmv_csr_t_serial_host(inputSet, v_t, vshift);
        inputSet.num_rows++;

        //printMatrixCPU(inSetDim, 1, vshift);
        incValsInLstMtxRowVec(inputSet, inputSet.num_rows - 1, vshift);

        std::cout << "Input set on iteration\n";
        //print_csr_matrix(inputSet);
        //getProjectionOnConus(inputSet, minNormVector, inSetDim, vectorDim, tollerance);
        csr_matrix<IndexType, ValueType> inSetCopy = getCsrMtxCopy(inputSet);

        if(apprIt > 0){
            memcpy(kvec_old, kvec, (2 * inputSet.num_cols + 1) * sizeof (IndexType));
        }
        //print_csr_matrix(inSetCopy);
        //projOnFixedSimplex(inSetCopy, minNormVector, kvec, basisVecInx, baselen, tollerance );
        getMinNormElemOutRepr(in_a_csc, minNormVector, 0.0001, kvec,  basisVecInx, baselen, numberOfEqConstr);
        delete_host_matrix(inSetCopy);

        IndexType kvec_razn = 0;
        if(apprIt > 0){
            for (IndexType i = 0; i < 2 * inputSet.num_cols + 1; i++) {
                if(kvec[i] == kvec_old[i] && kvec[i] == 1){
                    kvec_razn++;
                }
            }
        }
        std::cout << "KVEC RAZN is = " << kvec_razn <<"\n";
        std::cout << "baselen is = " << baselen <<"\n";

        cblas_axpy(vectorDim, -1.0, v_t, 1, minNormVector, 1);
        //std::cout << "Min norm vector on iteration\n";
        //printMatrixCPU(vectorDim, 1, minNormVector);

        decValsInLstMtxRowVec(inputSet, inputSet.num_rows - 1, vshift);


        cblas_copy(vectorDim, minNormVector, 1, x_s, 1);

        cblas_axpy(vectorDim, -1.0, x_s, 1, delta_x, 1);
        ValueType z_summ = 0.0;        
        for (IndexType i = 0; i < vectorDim - 1; i++) {
            z_summ += minNormVector[i];
        }
        std::cout << "Summ of elements " << z_summ << " on "<< apprIt <<" iteration\n";
        ValueType dist = cblas_dot(vectorDim - 1, delta_x, 1, delta_x, 1);
        if (dist < tollerance * tollerance) {
            std::cout << "iterations count :" << apprIt << "\n";
            break;
        }       
    }

    //cblas_axpy(vectorDim, -1.0, v_t, 1, minNormVector, 1);
    ValueType dist = cblas_dot(vectorDim - 1, minNormVector, 1, minNormVector, 1);
    std::cout << "Min Vector Lengh = " << sqrt(dist) << "\n";
    ValueType z_summ = 0.0;
    IndexType nonzer_summ = 0;
    for (IndexType i = 0; i < vectorDim - 1; i++) {
        z_summ += minNormVector[i];
        if (minNormVector[i] != 0.0) {
            nonzer_summ++;
        }
    }

    std::cout << "Summ of elements " << z_summ << " \n";
    std::cout << "Count of nonzerros " << nonzer_summ << " \n";
    //printMatrixToFileForOctave(vectorDim, 1, minNormVector);
    ValueType* b_contr = new_host_array<ValueType > (inSetDim);
    inputSet.num_rows--;
    spmv_csr_t_serial_host(inputSet, minNormVector, b_contr);
    inputSet.num_rows++;
    //printMatrixCPU(inSetDim, 1, b_contr);
    IndexType b_begin = inputSet.Ap[vectorDim - 1];
    IndexType b_end = inputSet.Ap[vectorDim];
    IndexType inconsCount = 0;
    for (IndexType i = b_begin; i < b_end; i++) {
        IndexType j = inputSet.Aj[i];
        if (b_contr[j] > inputSet.Ax[i] + tollerance * tollerance) {
            //std::cout << "b_contr " << b_contr[j] << " Ax " << inputSet.Ax[i] << " \n";
            ValueType razn = b_contr[j] -  inputSet.Ax[i];
            //printf("bcontr[%i] %e Ax %e  razn %e\n", j ,b_contr[j], inputSet.Ax[i], razn);
            inconsCount++;
        }
    }
    std::cout << "Inconsistent X count: " << inconsCount << " \n";

}