inline Sacado::Fad::Expr< Sacado::Fad::SFadExprTag<T,Num> >::
Expr(const Expr<S>& x) : val_(x.val())
{
#ifdef SACADO_DEBUG
  if (x.size() != Num)
    throw "SFad::SFad() Error:  Attempt to assign with incompatible sizes";
#endif

  for(int i=0; i<Num; ++i) 
    dx_[i] = x.fastAccessDx(i);
}
KOKKOS_INLINE_FUNCTION
Sacado::Fad::Expr< Sacado::Fad::SFadExprTag<T,Num> >::
Expr(const Expr<S>& x) : update_val_(x.updateValue())
{
#if defined(SACADO_DEBUG) && !defined(__CUDA_ARCH__ )
  if (x.size() != Num)
    throw "SFad::SFad() Error:  Attempt to assign with incompatible sizes";
#endif

  for(int i=0; i<Num; ++i)
    dx_[i] = x.fastAccessDx(i);

  if (update_val_)
    this->val() = x.val();
  else
    this->val() = T(0.);
}
inline Sacado::CacheFad::Expr< Sacado::CacheFad::SFadExprTag<T,Num> >::
Expr(const Expr<S>& x) : update_val_(x.updateValue())
{
#ifdef SACADO_DEBUG
  if (x.size() != Num)
    throw "CacheFad::SFad() Error:  Attempt to assign with incompatible sizes";
#endif

  x.cache();

  if (update_val_)
    this->val() = x.val();
  else
    this->val() = T(0.);

  for(int i=0; i<Num; ++i) 
    dx_[i] = x.fastAccessDx(i);
}
inline Sacado::CacheFad::Expr< Sacado::CacheFad::SFadExprTag<T,Num> >& 
Sacado::CacheFad::Expr< Sacado::CacheFad::SFadExprTag<T,Num> >::
operator=(const Expr<S>& x) 
{
#ifdef SACADO_DEBUG
  if (x.size() != Num)
    throw "CacheFad::operator=() Error:  Attempt to assign with incompatible sizes";
#endif

  // Compute value
  T xval = x.val();

  for(int i=0; i<Num; ++i)
    dx_[i] = x.fastAccessDx(i);
  
  val_ = xval;
  
  return *this;
}
Exemple #5
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();
}