Ejemplo n.º 1
0
 static void compute(A0& out,const C& c, const R& r)
 {
   size_t p = numel(r);
   size_t m = numel(c);
   BOOST_AUTO_TPL(idx, nt2::_(ptrdiff_t(p), ptrdiff_t(-1), ptrdiff_t(2)));
   BOOST_AUTO_TPL(ridx, nt2::colvect(r(idx)));
   BOOST_AUTO_TPL(x, catv(ridx, c)); //build vector of user data
   BOOST_AUTO_TPL(v1, nt2::fliplr(nt2::cif(m, p, meta::as_<ptrdiff_t>())));
   BOOST_AUTO_TPL(v2, nt2::ric(m, p, meta::as_<ptrdiff_t>()));
   out(nt2::_) = x(v1+v2);
 }
Ejemplo n.º 2
0
    template < class Q1, class R1>  BOOST_FORCEINLINE
    void do_it(A0& a0, const char& orient, Q1 & q1,  R1 & r1) const
    {
      BOOST_AUTO_TPL(q,  boost::proto::child_c<0>(a0));
      BOOST_AUTO_TPL(r,  boost::proto::child_c<1>(a0));
      size_t j =         boost::proto::child_c<2>(a0);
      BOOST_AUTO_TPL(x,  boost::proto::child_c<3>(a0));
      table<value_t, nt2::of_size_<2, 2> >  g;
      size_t n = size(r, 2);
      size_t m = size(r, 1);
      if (orient == 'c')
      {
        // Make room and insert x before j-th column.
        r1.resize(nt2::of_size(m, n+1));
        q1 = q;
        r1(nt2::_,nt2::_(1, j-1))  = r(nt2::_,nt2::_(1, j-1));
        r1(nt2::_,nt2::_(j+1, n+1)) = r(nt2::_,nt2::_(j, n));
        r1(nt2::_,j) = nt2::mtimes(nt2::ct(q), x);
        ++n;
        //  now r has nonzeros below the diagonal in the j-th column,
        //  and "extra" zeros on the diagonal in later columns.
        //     r = [x x x x x         [x x x x x
        //          0 x x x x    g     0 x x x x
        //          0 0 + x x   --->   0 0 * * *
        //          0 0 + 0 x          0 0 0 * *
        //          0 0 + 0 0]         0 0 0 0 *]
        //  use givens rotations to zero the +'s, one at a time, from bottom to top.
        //
        //  q is treated to (the transpose of) the same rotations.
        //     q = [x x x x x    g'   [x x * * *
        //          x x x x x   --->   x x * * *
        //          x x x x x          x x * * *
        //          x x x x x          x x * * *
        //          x x x x x]         x x * * *]
         for(size_t k = m-1; k >= j; --k)
         {
           BOOST_AUTO_TPL(p, nt2::cons(k, k+1));
           nt2::tie(g,r1(p,j)) = nt2::planerot(r1(p,j));
           if (k < n)
           {
             r1(p,nt2::_(k+1, n)) = nt2::mtimes(g, r1(p,nt2::_(k+1, n)));
           }
           q1(nt2::_,p) = nt2::mtimes(q1(nt2::_,p), nt2::ct(g));
         }

      }
      else
      {
        r1 = catv(x, r);
        q1 = catv(cath(nt2::One<value_t>(), nt2::zeros(1,m,meta::as_<value_t>())),
                  cath(nt2::zeros(m,1,meta::as_<value_t>()),q));
        //  now r is upper hessenberg.
        //     r = [x x x x         [* * * *
        //          + x x x    g       * * *
        //            + x x   --->       * *
        //              + x                *
        //                +          0 0 0 0
        //          0 0 0 0          0 0 0 0
        //          0 0 0 0]         0 0 0 0]
        //  use givens rotations to zero the +'s, one at a time, from top to bottom.
        //
        //  q is treated to (the transpose of) the same rotations and then a row
        //  permutation, p, to shuffle row 1 down to row j.
        //     q = [1 | 0 0 0 0 0         [# # # # # #         [* * * * * *
        //          --|----------          -----------          -----------
        //          0 | x x x x x    g'    * * * * * *    p     * * * * * *
        //          0 | x x x x x   --->   * * * * * *   --->   # # # # # #
        //          0 | x x x x x          * * * * * *          * * * * * *
        //          0 | x x x x x          * * * * * *          * * * * * *
        //          0 | x x x x x]         * * * * * *]         * * * * * *]

        for(size_t i = 1; i <= nt2::min(m,n); ++i)
        {
          BOOST_AUTO_TPL(p, nt2::cons(i, i+1));
          nt2::tie(g,r1(p,i)) = nt2::planerot(r1(p,i));
          r1(p,nt2::_(i+1, n)) = nt2::mtimes(g, r1(p,nt2::_(i+1, n)));
          q1(nt2::_,p) = nt2::mtimes(q1(nt2::_,p), nt2::ct(g));
        }
        // this permutes row 1 of q*r to row j of q(p,:)*r
        if (j != 1)
        {
          BOOST_AUTO_TPL(p, nt2::cath(nt2::cath(nt2::_(size_t(2), j), size_t(1)), nt2::_(j+1, m+1)));
          table<value_t> qq = q1(p,nt2::_);
          q1 = qq;
        }


      }
    }
Ejemplo n.º 3
0
int executecmd(char *linea)
{
	char *cmd;
	char *arg1;
	char *arg2;
	char *search=" ";

	// Separa el comando y los dos posibles argumentos
	cmd=strtok(linea," ");
	arg1=strtok(NULL," ");
	arg2=strtok(NULL," ");


	// No hay comando
	if(cmd==NULL)
		return(1);

	// comando "exit"
	if(strcmp(cmd,"exit")==0)
		return(0);

	// comando "copy"
	if(strcmp(cmd,"copy")==0)
	{
		if(arg1==NULL && arg2==NULL)
		{
			fprintf(stderr,"Error en los argumentos\n");
			return(1);
		}
		if(!isinvd(arg1) && !isinvd(arg2))
			copyuu(&arg1[2],&arg2[2]);

		else if(!isinvd(arg1) && isinvd(arg2))
			copyuv(&arg1[2],arg2);

		else if(isinvd(arg1) && !isinvd(arg2))
			copyvu(arg1,&arg2[2]);

		else if(isinvd(arg1) && isinvd(arg2))
			copyvv(arg1,arg2);
			
		
	}

	// comando "cat"
	if(strcmp(cmd,"cat")==0)
	{
		if(isinvd(arg1))
			catv(arg1);
		else
			catu(&arg1[2]);
	}

	// comando dir
	if(strcmp(cmd,"dir")==0)
	{
		if(arg1==NULL)
			dirv();
		else if(!isinvd(arg1))
			diru(&arg1[2]);
	}
}