Exemple #1
0
VectorImpl<T,Storage>::
VectorImpl(const Expr<S>& x) :
  th_(new storage_type(x.size()))
{
  int sz = x.size();
  if (x.hasFastAccess(sz)) {
    for (int i=0; i<sz; i++)
      (*th_)[i] = x.fastAccessCoeff(i);
  }
  else {
    Stokhos_Version();
    for (int i=0; i<sz; i++)
      (*th_)[i] = x.coeff(i);
  }
}
Exemple #2
0
inline Sacado::Fad::GeneralFad<T,Storage>::GeneralFad(const Expr<S>& x) :
  s_(T(0.))
{
  int sz = x.size();

  if (sz != s_.size()) 
    s_.resize(sz);

  if (sz) {
    if (x.hasFastAccess())
      for(int i=0; i<sz; ++i) 
	s_.dx_[i] = x.fastAccessDx(i);
    else
      for(int i=0; i<sz; ++i) 
	s_.dx_[i] = x.dx(i);
  }

  s_.val_ = x.val();
}
inline Sacado::ELRFad::GeneralFad<T,Storage>::GeneralFad(const Expr<S>& x) :
  Storage(T(0.)),
  update_val_(x.updateValue())
{
  int sz = x.size();

  if (sz != this->size()) 
    this->resize(sz);

  if (sz) {

    if (Expr<S>::is_linear) {
      if (x.hasFastAccess())
        for(int i=0; i<sz; ++i)
          this->fastAccessDx(i) = x.fastAccessDx(i);
      else
        for(int i=0; i<sz; ++i)
          this->fastAccessDx(i) = x.dx(i);
    }
    else {

      // Number of arguments
      const int N = Expr<S>::num_args;

      if (x.hasFastAccess()) {
	// Compute partials
	FastLocalAccumOp< Expr<S> > op(x);
  
	// Compute each tangent direction
	for(op.i=0; op.i<sz; ++op.i) {
	  op.t = T(0.);

	  // Automatically unrolled loop that computes
	  // for (int j=0; j<N; j++)
	  //   op.t += op.partials[j] * x.getTangent<j>(i);
	  Sacado::mpl::for_each< mpl::range_c< int, 0, N > > f(op);
	  
	  this->fastAccessDx(op.i) = op.t;
	}
      }
      else {
	// Compute partials
	SlowLocalAccumOp< Expr<S> > op(x);
  
	// Compute each tangent direction
	for(op.i=0; op.i<sz; ++op.i) {
	  op.t = T(0.);

	  // Automatically unrolled loop that computes
	  // for (int j=0; j<N; j++)
	  //   op.t += op.partials[j] * x.getTangent<j>(i);
	  Sacado::mpl::for_each< mpl::range_c< int, 0, N > > f(op);
	  
	  this->fastAccessDx(op.i) = op.t;
	}
      }
 
    }

  }
  
  // Compute value
  if (update_val_)
    this->val() = x.val();
}