Exemple #1
0
    BOOST_FORCEINLINE result_type operator()(Expr& e) const
    {
      BOOST_ASSERT_MSG((isscalar( boost::proto::child_c<0>(e))&&issquare(boost::proto::child_c<1>(e)))||
                       (isscalar( boost::proto::child_c<1>(e))&&issquare(boost::proto::child_c<0>(e))),
                       "mpower needs a square matrix expression and a scalar or a scalar and a square matrix expression");

      return nt2::utility::max_extent(nt2::extent(boost::proto::child_c<0>(e)),  nt2::extent(boost::proto::child_c<1>(e)));
    }
Exemple #2
0
 schur_result ( Input& xpr
                , char jobvs/* = 'V'*/
                , char sort /* = 'N'*/
                , char sense/* = 'N'*/)
   : jobvs_(jobvs)
   , sort_(sort)
   , sense_(sense)
   , a_(xpr)
   , aa_(xpr)
   , n_(nt2::height(xpr))
   , lda_(a_.leading_size())
 {
   BOOST_ASSERT_MSG(issquare(aa_), "Error using schur. Matrix must be square.");
   jobvs_ = (sense_ == 'E' || sense_ == 'B') ? 'V':jobvs_;
   sort_ = (sense_ == 'E') ? 'S' : sort_;
   ldvs_ = (jobvs_ == 'V') ? n_ : 1;
   w_.resize(nt2::of_size(n_, 1));
   vs_.resize(of_size(ldvs_, ldvs_));
   ldvs_ = vs_.leading_size();
   nt2::details::geesx(&jobvs_, &sort_, &nt2::details::selectall , &sense_, &n_,
                       aa_.raw(), &lda_, &sdim_, w_.raw(),
                       vs_.raw(), &ldvs_,
                       &rconde_, &rcondv_,
                       &info_, wrk_);
 }
Exemple #3
0
 balance_result ( Input& xpr, char job/* = 'B'*/)
     : job_(job)
     , a_(xpr)
     , aa_(xpr)
     , ipi_(of_size(0, 0))
     , n_( nt2::height(a_)  )
     , lda_( a_.leading_size() )
     , t_(of_size(n_, n_))
     , invt_(of_size(0, 0))
     , ilo_(0)
     , ihi_(0)
     , scale_(of_size(1, n_))
     , info_(0)
 {
     BOOST_ASSERT_MSG(issquare(aa_),
                      "matrix to balance must be square");
     nt2::details::gebal(&job_, &n_, aa_.raw(), &lda_,
                         &ilo_, &ihi_, scale_.raw(),
                         &info_);
     t_ = nt2::eye(n_, n_, meta::as_<type_t>());
     nt2_la_int ldt = t_.leading_size();
     char side =  'R';
     nt2::details::gebak(&job_, &side, &n_,
                         &ilo_, &ihi_, scale_.raw(),
                         &n_, t_.raw(), &ldt, &info_);
 }
Exemple #4
0
void eu066(char *ans) {
  const int N = 1000;
  int d_of_max = 0;
  mpz_t x, max;

  mpz_init(x);
  mpz_init(max);
  mpz_set_ui(max, 0);

  for (int d = 1; d < N; d++) {
    if (issquare(d)) continue;

    minx(d, x);

    if (mpz_cmp(x, max) > 0) {
      mpz_set(max, x);
      d_of_max = d;
    }
  }

  mpz_clear(x);
  mpz_clear(max);

  sprintf(ans, "%d", d_of_max);
}
Exemple #5
0
    BOOST_FORCEINLINE result_type operator()(Expr& e) const
    {
      BOOST_ASSERT_MSG((issquare(boost::proto::child_c<0>(e))),
                       "impower needs a square matrix expression and a scalar integer");

      return nt2::extent(boost::proto::child_c<0>(e));
    }
Exemple #6
0
/**
 * @brief         Eigenvalue decomposition
 * 
 * Usage:
 * @code{.cpp}
 *   Matrix<cxfl> m = rand<cxfl> (10,10), ev;
 *   Matrix<float> lv, rv;
 *   boost::tuple<Matrix<float>,Matrix<cxfl>,Matrix<float>> ler
 *   ler = eig2 (m);
 *   lv = boost::get<0>(ler)
 *   ev = boost::get<1>(ler);
 *   rv = boost::get<2>(ler)
 * @endcode
 * where m is the complex decomposed matrix, lv and rv are the left hand and right 
 * hand side eigen vectors and ev is the eigenvalue vector.
 *
 * @see           LAPACK driver xGEEV
 *
 * @param  m      Matrix for decomposition
 * @param  jobvl  Compute left vectors ('N'/'V')
 * @param  jobvr  Compute right vectors ('N'/'V')
 * @return        Eigenvectors and values
 */
template <class T, class S> inline boost::tuple< Matrix<T>, Matrix<S>, Matrix<T> >
eig2 (const Matrix<T>& m, char jobvl = 'N', char jobvr = 'N') {
    
	typedef typename LapackTraits<T>::RType T2;
	T t;
    
	boost::tuple< Matrix<T>, Matrix<S>, Matrix<T> > ret;


    assert (jobvl == 'N' || jobvl =='V');
	assert (jobvr == 'N' || jobvr =='V');
    assert (issquare(m));
    
	int    N     =  size(m, 0);
	int    lda   =  N;
	int    ldvl  = (jobvl == 'V') ? N : 1;
	int    ldvr  = (jobvr == 'V') ? N : 1;
	int    info  =  0;
	int    lwork = -1;
    
    // Appropriately resize the output
	boost::get<1>(ret) = Matrix<S>(N,1);
    
	if (jobvl == 'V') boost::get<0>(ret) = Matrix<T>(N,N);
    if (jobvr == 'V') boost::get<2>(ret) = Matrix<T>(N,N);
    
    Matrix<S>& ev = boost::get<1>(ret);
    Matrix<T> &lv = boost::get<0>(ret), &rv = boost::get<2>(ret);


    // Workspace for real numbers
    container<T2> rwork = (is_complex(t)) ?
    	container<T2>(2*N) : container<T2>(1);

    // Workspace for complex numbers
	container<T>  work = container<T>(1);
	
	// Need copy. Lapack destroys A on output.
	Matrix<T> a = m;
    
	// Work space query
	LapackTraits<T>::geev (jobvl, jobvr, N, &a[0], lda, &ev[0], &lv[0], ldvl, &rv[0], ldvr, &work[0], lwork, &rwork[0], info);
    
	// Initialize work space
	lwork = (int) TypeTraits<T>::Real (work[0]);
    work.resize(lwork);
    
	// Actual Eigenvalue computation
	LapackTraits<T>::geev (jobvl, jobvr, N, &a[0], lda, &ev[0], &lv[0], ldvl, &rv[0], ldvr, &work[0], lwork, &rwork[0], info);

	if (info > 0) {
		printf ("\nERROR - XGEEV: the QR algorithm failed to compute all the\n eigenvalues, and no eigenvectors have " \
                "been computed;\n elements %d+1:N of ev contain eigenvalues which\n have converged.\n\n", info) ;
	} else if (info < 0)
		printf ("\nERROR - XGEEV: the %d-th argument had an illegal value.\n\n", -info);
    
	return ret;
	
}
Exemple #7
0
int main()
{
    unsigned n;
    printf("Enter a number:\n");
    scanf(" %u%*c", &n);
    printf("The number is %sperfect square.\n", issquare(n)?"":"not ");
    return 0;
}
Exemple #8
0
 cholesky_result ( char uplo, Input& xpr )
                 : values_(xpr)
                 , height_( nt2::height(xpr) )
                 , leading_( values_.leading_size() )
                 , info_(0)
                 , uplo_(uplo)
 {
   BOOST_ASSERT_MSG(issquare(values_), "matrix must be square");
   nt2::details::potrf ( &uplo_, &height_
                       , values_.raw(), &leading_, &info_
                       );
 }
Exemple #9
0
int main(int argc, char *argv[]) {
	int n, aux, t, i;

	scanf("%d", &n);
	t = 0;
	for (i = 0; i < n; ++i) {
		scanf("%d", &aux);
		if (issquare(aux))
			t += aux;
	}

	printf("%d\n", t);

	return 0;
}
Exemple #10
0
/**
 * @brief                Invert quadratic well conditioned matrix
 *
 * Usage:
 * @code{.cpp}
 *   Matrix<cxfl> m = rand<cxfl> (10,10);
 *  
 *   m = inv (m);
 * @endcode
 *
 * @see                  Lapack xGETRF/xGETRI
 * 
 * @param  m             Matrix
 * @return               Inverse
 */
template <class T> inline Matrix<T> 
inv (const Matrix<T>& m) {
    
	// 2D 
    assert(issquare(m));
	
	int N = (int) size (m,0);	
	Matrix<T> res = m;

	int  info = 0;
	container<int> ipiv = container<int>(N);
	
	// LU Factorisation -------------------
	LapackTraits<T>::getrf (N, N, &res[0], N, &ipiv[0], info);
	
	if (info < 0)
		printf ("\nERROR - DPOTRI: the %i-th argument had an illegal value.\n\n", -info);
	else if (info > 1)
		printf ("\nERROR - DPOTRI: the (%i,%i) element of the factor U or L is\n zero, and the inverse could not be " \
                "computed.\n\n", info, info);
	
	int lwork = -1; 
	container<T> work = container<T>(1);
	
	// Workspace determination ------------
	LapackTraits<T>::getri (N, &res[0], N, &ipiv[0], &work[0], lwork, info);
    
	// Work memory allocation -------------
	lwork = (int) TypeTraits<T>::Real (work[0]);
    work.resize(lwork);
	
	// Inversion --------------------------
	LapackTraits<T>::getri (N, &res[0], N, &ipiv[0], &work[0], lwork, info);

	if (info < 0)
		printf ("\nERROR - XGETRI: The %i-th argument had an illegal value.\n\n", -info);
	else if (info > 0)
		printf ("\nERROR - XGETRI: The leading minor of order %i is not\n positive definite, and the factorization could " \
                "not be\n completed.", info);
	
	return res;
	
} 
Exemple #11
0
 BOOST_FORCEINLINE result_type operator()(Expr& e) const
 {
   BOOST_ASSERT_MSG( issquare(boost::proto::child_c<1>(e)),
                     "funm needs a functor and scalar or a ");
   return nt2::extent(boost::proto::child_c<1>(e));
 }
Exemple #12
0
int			ft_isvalid(const char *tab, int len)
{
	if (!issquare(tab, len) || !hasfour(tab) || !ischar(tab) || !doestouch(tab))
		return (0);
	return (1);
}
Exemple #13
0
 BOOST_FORCEINLINE result_type operator()(Expr& e) const
 {
   BOOST_ASSERT_MSG(issquare(boost::proto::child_c<0>(e)),
                    "logm needs a square matrix or a scalar");
   return nt2::extent(boost::proto::child_c<0>(e));
 }