예제 #1
0
 KOKKOS_INLINE_FUNCTION
 bool toBool(const Expr<ExprT,ExprSpecMPVector>& x) {
   bool is_zero = (x.val() == 0.0);
   for (int i=0; i<x.size(); i++)
     for (int j=0; j<x.val().size(); ++j)
       is_zero = is_zero && (x.dx(i,j) == 0.0);
   return !is_zero;
 }
예제 #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();
}
예제 #4
0
    bool toBool(const Expr<ExprT>& x) {
      bool is_zero = (x.val() == 0.0);
      for (int i=0; i<x.size(); i++)
	is_zero = is_zero && (x.dx(i) == 0.0);
      return !is_zero;
    }