// @HEADER // ***************************************************************************** // Stokhos Package // // Copyright 2009 NTESS and the Stokhos contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #include "Teuchos_SerialDenseMatrix.hpp" namespace Sacado { namespace UQ { /* template KOKKOS_INLINE_FUNCTION typename PCE::value_type PCE:: evaluate(const Teuchos::Array::value_type>& point) const { return s_.evaluate(point); } template KOKKOS_INLINE_FUNCTION typename PCE::value_type PCE:: evaluate( const Teuchos::Array::value_type>& point, const Teuchos::Array::value_type>& bvals) const { return s_.evaluate(point, bvals); } */ template KOKKOS_INLINE_FUNCTION typename PCE::value_type PCE:: standard_deviation() const { value_type s = 0.0; const ordinal_type sz = this->size(); const_pointer c = this->coeff(); for (ordinal_type i=1; i KOKKOS_INLINE_FUNCTION typename PCE::value_type PCE:: two_norm_squared() const { value_type s = 0.0; const ordinal_type sz = this->size(); const_pointer c = this->coeff(); for (ordinal_type i=0; i KOKKOS_INLINE_FUNCTION typename PCE::value_type PCE:: inner_product(const PCE& x) const { value_type s = 0.0; const ordinal_type sz = this->size(); const ordinal_type xsz = x.size(); const ordinal_type n = sz < xsz ? sz : xsz; const_pointer c = this->coeff(); const_pointer xc = x.coeff(); for (ordinal_type i=0; i KOKKOS_INLINE_FUNCTION bool PCE:: isEqualTo(const PCE& x) const { typedef IsEqual IE; const ordinal_type sz = this->size(); if (x.size() != sz) return false; bool eq = true; for (ordinal_type i=0; icoeff(i)); return eq; } template KOKKOS_INLINE_FUNCTION bool PCE:: isEqualTo(const PCE& x) const volatile { typedef IsEqual IE; const ordinal_type sz = this->size(); if (x.size() != sz) return false; bool eq = true; for (ordinal_type i=0; icoeff(i)); return eq; } template KOKKOS_INLINE_FUNCTION PCE& PCE:: operator=(const typename PCE::value_type v) { s_.init(value_type(0)); s_[0] = v; return *this; } template KOKKOS_INLINE_FUNCTION /*volatile*/ PCE& PCE:: operator=(const typename PCE::value_type v) volatile { s_.init(value_type(0)); s_[0] = v; return const_cast(*this); } template KOKKOS_INLINE_FUNCTION PCE& PCE:: operator=(const PCE& x) { if (this != &x) { if (!s_.is_view()) cijk_ = x.cijk_; if (!s_.is_view() && is_constant(x)) { s_.resize(1); s_[0] = x.s_[0]; } else s_ = x.s_; // For DyamicStorage as a view (is_owned=false), we need to set // the trailing entries when assigning a constant vector (because // the copy constructor in this case doesn't reset the size of this) if (s_.size() > x.s_.size()) for (ordinal_type i=x.s_.size(); i KOKKOS_INLINE_FUNCTION PCE& PCE:: operator=(const volatile PCE& x) { if (this != &x) { if (!s_.is_view()) cijk_ = const_cast(x.cijk_); if (!s_.is_view() && is_constant(x)) { s_.resize(1); s_[0] = x.s_[0]; } else s_ = x.s_; // For DyamicStorage as a view (is_owned=false), we need to set // the trailing entries when assigning a constant vector (because // the copy constructor in this case doesn't reset the size of this) if (s_.size() > x.s_.size()) for (ordinal_type i=x.s_.size(); i KOKKOS_INLINE_FUNCTION /*volatile*/ PCE& PCE:: operator=(const PCE& x) volatile { if (this != &x) { if (!s_.is_view()) const_cast(cijk_) = x.cijk_; if (!s_.is_view() && is_constant(x)) { s_.resize(1); s_[0] = x.s_[0]; } else s_ = x.s_; // For DyamicStorage as a view (is_owned=false), we need to set // the trailing entries when assigning a constant vector (because // the copy constructor in this case doesn't reset the size of this) if (s_.size() > x.s_.size()) for (ordinal_type i=x.s_.size(); i(*this); } template KOKKOS_INLINE_FUNCTION /*volatile*/ PCE& PCE:: operator=(const volatile PCE& x) volatile { if (this != &x) { if (!s_.is_view()) const_cast(cijk_) = const_cast(x.cijk_); if (!s_.is_view() && is_constant(x)) { s_.resize(1); s_[0] = x.s_[0]; } else s_ = x.s_; // For DyamicStorage as a view (is_owned=false), we need to set // the trailing entries when assigning a constant vector (because // the copy constructor in this case doesn't reset the size of this) if (s_.size() > x.s_.size()) for (ordinal_type i=x.s_.size(); i(*this); } template KOKKOS_INLINE_FUNCTION PCE PCE:: operator-() const { const ordinal_type sz = this->size(); PCE x(cijk_, sz); pointer xc = x.coeff(); const_pointer cc = this->coeff(); for (ordinal_type i=0; i KOKKOS_INLINE_FUNCTION PCE PCE:: operator-() const volatile { const ordinal_type sz = this->size(); PCE x(const_cast(cijk_), sz); pointer xc = x.coeff(); const_volatile_pointer cc = this->coeff(); for (ordinal_type i=0; i KOKKOS_INLINE_FUNCTION PCE& PCE:: operator*=(const typename PCE::value_type v) { pointer cc = this->coeff(); const ordinal_type sz = this->size(); for (ordinal_type i=0; i KOKKOS_INLINE_FUNCTION /*volatile*/ PCE& PCE:: operator*=(const typename PCE::value_type v) volatile { volatile_pointer cc = this->coeff(); const ordinal_type sz = this->size(); for (ordinal_type i=0; i(*this); } template KOKKOS_INLINE_FUNCTION PCE& PCE:: operator/=(const typename PCE::value_type v) { pointer cc = this->coeff(); const ordinal_type sz = this->size(); for (ordinal_type i=0; i KOKKOS_INLINE_FUNCTION /*volatile*/ PCE& PCE:: operator/=(const typename PCE::value_type v) volatile { volatile pointer cc = this->coeff(); const ordinal_type sz = this->size(); for (ordinal_type i=0; i(*this); } template KOKKOS_INLINE_FUNCTION PCE& PCE:: operator+=(const PCE& x) { const ordinal_type xsz = x.size(); const ordinal_type sz = this->size(); if (xsz > sz) { this->reset(x.cijk_, xsz); } const_pointer xc = x.coeff(); pointer cc = this->coeff(); for (ordinal_type i=0; i KOKKOS_INLINE_FUNCTION PCE& PCE:: operator-=(const PCE& x) { const ordinal_type xsz = x.size(); const ordinal_type sz = this->size(); if (xsz > sz) { this->reset(x.cijk_, xsz); } const_pointer xc = x.coeff(); pointer cc = this->coeff(); for (ordinal_type i=0; i KOKKOS_INLINE_FUNCTION PCE& PCE:: operator*=(const PCE& x) { const ordinal_type xsz = x.size(); const ordinal_type sz = this->size(); const ordinal_type csz = sz > xsz ? sz : xsz; KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( sz != xsz && sz != 1 && xsz != 1, std::logic_error, "Sacado::UQ::PCE::operator*=(): input sizes do not match"); ) if (cijk_.is_empty() && !x.cijk_.is_empty()) cijk_ = x.cijk_; KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( cijk_.is_empty() && csz != 1, std::logic_error, "Sacado::UQ::PCE::operator*(): empty cijk but expansion size > 1"); ) if (csz > sz) s_.resize(csz); const_pointer xc = x.coeff(); pointer cc = this->coeff(); if (xsz == 1) { const value_type xcz = xc[0]; for (ordinal_type i=0; i y(cijk_, csz); pointer yc = y.coeff(); for (ordinal_type i=0; i KOKKOS_INLINE_FUNCTION PCE& PCE:: operator/=(const PCE& x) { const ordinal_type xsz = x.size(); const ordinal_type sz = this->size(); const ordinal_type csz = sz > xsz ? sz : xsz; KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( sz != xsz && sz != 1 && xsz != 1, std::logic_error, "Sacado::UQ::PCE::operator/=(): input sizes do not match"); ) if (cijk_.is_empty() && !x.cijk_.is_empty()) cijk_ = x.cijk_; if (csz > sz) s_.resize(csz); const_pointer xc = x.coeff(); pointer cc = this->coeff(); KOKKOS_IF_ON_DEVICE( const value_type xcz = xc[0]; for (ordinal_type i=0; i y(cijk_, csz); CG_divide(*this, x, y); s_ = y.s_; } ) return *this; } template KOKKOS_INLINE_FUNCTION PCE operator+(const PCE& a, const PCE& b) { typedef typename PCE::my_cijk_type my_cijk_type; typedef typename PCE::pointer pointer; typedef typename PCE::const_pointer const_pointer; typedef typename PCE::ordinal_type ordinal_type; const ordinal_type asz = a.size(); const ordinal_type bsz = b.size(); const ordinal_type csz = asz > bsz ? asz : bsz; my_cijk_type c_cijk = asz > bsz ? a.cijk() : b.cijk(); PCE c(c_cijk, csz); const_pointer ac = a.coeff(); const_pointer bc = b.coeff(); pointer cc = c.coeff(); if (asz > bsz) { for (ordinal_type i=0; i KOKKOS_INLINE_FUNCTION PCE operator+(const typename PCE::value_type& a, const PCE& b) { typedef typename PCE::pointer pointer; typedef typename PCE::const_pointer const_pointer; typedef typename PCE::ordinal_type ordinal_type; const ordinal_type bsz = b.size(); PCE c(b.cijk(), bsz); const_pointer bc = b.coeff(); pointer cc = c.coeff(); cc[0] = a + bc[0]; for (ordinal_type i=1; i KOKKOS_INLINE_FUNCTION PCE operator+(const PCE& a, const typename PCE::value_type& b) { typedef typename PCE::pointer pointer; typedef typename PCE::const_pointer const_pointer; typedef typename PCE::ordinal_type ordinal_type; const ordinal_type asz = a.size(); PCE c(a.cijk(), asz); const_pointer ac = a.coeff(); pointer cc = c.coeff(); cc[0] = ac[0] + b; for (ordinal_type i=1; i KOKKOS_INLINE_FUNCTION PCE operator-(const PCE& a, const PCE& b) { typedef typename PCE::my_cijk_type my_cijk_type; typedef typename PCE::pointer pointer; typedef typename PCE::const_pointer const_pointer; typedef typename PCE::ordinal_type ordinal_type; const ordinal_type asz = a.size(); const ordinal_type bsz = b.size(); const ordinal_type csz = asz > bsz ? asz : bsz; my_cijk_type c_cijk = asz > bsz ? a.cijk() : b.cijk(); PCE c(c_cijk, csz); const_pointer ac = a.coeff(); const_pointer bc = b.coeff(); pointer cc = c.coeff(); if (asz > bsz) { for (ordinal_type i=0; i KOKKOS_INLINE_FUNCTION PCE operator-(const typename PCE::value_type& a, const PCE& b) { typedef typename PCE::pointer pointer; typedef typename PCE::const_pointer const_pointer; typedef typename PCE::ordinal_type ordinal_type; const ordinal_type bsz = b.size(); PCE c(b.cijk(), bsz); const_pointer bc = b.coeff(); pointer cc = c.coeff(); cc[0] = a - bc[0]; for (ordinal_type i=1; i KOKKOS_INLINE_FUNCTION PCE operator-(const PCE& a, const typename PCE::value_type& b) { typedef typename PCE::pointer pointer; typedef typename PCE::const_pointer const_pointer; typedef typename PCE::ordinal_type ordinal_type; const ordinal_type asz = a.size(); PCE c(a.cijk(), asz); const_pointer ac = a.coeff(); pointer cc = c.coeff(); cc[0] = ac[0] - b; for (ordinal_type i=1; i KOKKOS_INLINE_FUNCTION PCE operator*(const PCE& a, const PCE& b) { typedef typename PCE::my_cijk_type my_cijk_type; typedef typename PCE::pointer pointer; typedef typename PCE::const_pointer const_pointer; typedef typename PCE::ordinal_type ordinal_type; typedef typename PCE::value_type value_type; typedef typename my_cijk_type::size_type cijk_size_type; const ordinal_type asz = a.size(); const ordinal_type bsz = b.size(); const ordinal_type csz = asz > bsz ? asz : bsz; KOKKOS_IF_ON_HOST(( TEUCHOS_TEST_FOR_EXCEPTION( asz != bsz && asz != 1 && bsz != 1, std::logic_error, "Sacado::UQ::PCE::operator*(): input sizes do not match"); )) my_cijk_type c_cijk = a.cijk().is_empty() ? b.cijk() : a.cijk(); KOKKOS_IF_ON_HOST(( TEUCHOS_TEST_FOR_EXCEPTION( c_cijk.is_empty() && csz != 1, std::logic_error, "Sacado::UQ::PCE::operator*(): empty cijk but expansion size > 1"); )) PCE c(c_cijk, csz); const_pointer ac = a.coeff(); const_pointer bc = b.coeff(); pointer cc = c.coeff(); if (asz == 1) { const value_type acz = ac[0]; for (ordinal_type i=0; i KOKKOS_INLINE_FUNCTION PCE operator*(const typename PCE::value_type& a, const PCE& b) { typedef typename PCE::pointer pointer; typedef typename PCE::const_pointer const_pointer; typedef typename PCE::ordinal_type ordinal_type; const ordinal_type bsz = b.size(); PCE c(b.cijk(), bsz); const_pointer bc = b.coeff(); pointer cc = c.coeff(); for (ordinal_type i=0; i KOKKOS_INLINE_FUNCTION PCE operator*(const PCE& a, const typename PCE::value_type& b) { typedef typename PCE::pointer pointer; typedef typename PCE::const_pointer const_pointer; typedef typename PCE::ordinal_type ordinal_type; const ordinal_type asz = a.size(); PCE c(a.cijk(), asz); const_pointer ac = a.coeff(); pointer cc = c.coeff(); for (ordinal_type i=0; i KOKKOS_INLINE_FUNCTION PCE operator/(const PCE& a, const PCE& b) { typedef typename PCE::pointer pointer; typedef typename PCE::const_pointer const_pointer; typedef typename PCE::ordinal_type ordinal_type; typedef typename PCE::value_type value_type; typedef typename PCE::my_cijk_type my_cijk_type; const ordinal_type asz = a.size(); const ordinal_type bsz = b.size(); const ordinal_type csz = asz > bsz ? asz : bsz; KOKKOS_IF_ON_HOST(( TEUCHOS_TEST_FOR_EXCEPTION( asz != bsz && asz != 1 && bsz != 1, std::logic_error, "Sacado::UQ::PCE::operator/(): input sizes do not match"); )) my_cijk_type c_cijk = asz == bsz || asz >1 ? a.cijk() : b.cijk(); PCE c(c_cijk, csz); KOKKOS_IF_ON_HOST(( const_pointer ac = a.coeff(); pointer cc = c.coeff(); value_type bcz = b.fastAccessCoeff(0); for (ordinal_type i=0; i KOKKOS_INLINE_FUNCTION PCE operator/(const typename PCE::value_type& a, const PCE& b) { //Creat a 0-th order PCE for a PCE a_pce(a); return operator/(a_pce,b); } template KOKKOS_INLINE_FUNCTION PCE operator/(const PCE& a, const typename PCE::value_type& b) { typedef typename PCE::pointer pointer; typedef typename PCE::const_pointer const_pointer; typedef typename PCE::ordinal_type ordinal_type; const ordinal_type asz = a.size(); PCE c(a.cijk(), asz); const_pointer ac = a.coeff(); pointer cc = c.coeff(); for (ordinal_type i=0; i KOKKOS_INLINE_FUNCTION PCE exp(const PCE& a) { KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( a.size() != 1, std::logic_error, "Sacado::UQ::PCE::exp(): argument has size != 1"); ) PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = std::exp( a.fastAccessCoeff(0) ); return c; } template KOKKOS_INLINE_FUNCTION PCE log(const PCE& a) { KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( a.size() != 1, std::logic_error, "Sacado::UQ::PCE::log(): argument has size != 1"); ) PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = std::log( a.fastAccessCoeff(0) ); return c; } template KOKKOS_INLINE_FUNCTION PCE log10(const PCE& a) { KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( a.size() != 1, std::logic_error, "Sacado::UQ::PCE::log10(): argument has size != 1"); ) PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = std::log10( a.fastAccessCoeff(0) ); return c; } template KOKKOS_INLINE_FUNCTION PCE sqrt(const PCE& a) { KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( a.size() != 1, std::logic_error, "Sacado::UQ::PCE::sqrt(): argument has size != 1"); ) PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = std::sqrt( a.fastAccessCoeff(0) ); return c; } template KOKKOS_INLINE_FUNCTION PCE cbrt(const PCE& a) { KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( a.size() != 1, std::logic_error, "Sacado::UQ::PCE::cbrt(): argument has size != 1"); ) PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = std::cbrt( a.fastAccessCoeff(0) ); return c; } template KOKKOS_INLINE_FUNCTION PCE pow(const PCE& a, const PCE& b) { KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( a.size() != 1 || b.size() != 1, std::logic_error, "Sacado::UQ::PCE::pow(): arguments have size != 1"); ) PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = std::pow(a.fastAccessCoeff(0), b.fastAccessCoeff(0)); return c; } template KOKKOS_INLINE_FUNCTION PCE pow(const typename PCE::value_type& a, const PCE& b) { KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( b.size() != 1, std::logic_error, "Sacado::UQ::PCE::pow(): arguments have size != 1"); ) PCE c(b.cijk(), 1); c.fastAccessCoeff(0) = std::pow(a, b.fastAccessCoeff(0)); return c; } template KOKKOS_INLINE_FUNCTION PCE pow(const PCE& a, const typename PCE::value_type& b) { KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( a.size() != 1, std::logic_error, "Sacado::UQ::PCE::pow(): arguments have size != 1"); ) PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = std::pow(a.fastAccessCoeff(0), b); return c; } template KOKKOS_INLINE_FUNCTION PCE sin(const PCE& a) { KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( a.size() != 1, std::logic_error, "Sacado::UQ::PCE::sin(): argument has size != 1"); ) PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = std::sin( a.fastAccessCoeff(0) ); return c; } template KOKKOS_INLINE_FUNCTION PCE cos(const PCE& a) { KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( a.size() != 1, std::logic_error, "Sacado::UQ::PCE::cos(): argument has size != 1"); ) PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = std::cos( a.fastAccessCoeff(0) ); return c; } template KOKKOS_INLINE_FUNCTION PCE tan(const PCE& a) { KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( a.size() != 1, std::logic_error, "Sacado::UQ::PCE::tan(): argument has size != 1"); ) PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = std::tan( a.fastAccessCoeff(0) ); return c; } template KOKKOS_INLINE_FUNCTION PCE sinh(const PCE& a) { KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( a.size() != 1, std::logic_error, "Sacado::UQ::PCE::sinh(): argument has size != 1"); ) PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = std::sinh( a.fastAccessCoeff(0) ); return c; } template KOKKOS_INLINE_FUNCTION PCE cosh(const PCE& a) { KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( a.size() != 1, std::logic_error, "Sacado::UQ::PCE::cosh(): argument has size != 1"); ) PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = std::cosh( a.fastAccessCoeff(0) ); return c; } template KOKKOS_INLINE_FUNCTION PCE tanh(const PCE& a) { KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( a.size() != 1, std::logic_error, "Sacado::UQ::PCE::tanh(): argument has size != 1"); ) PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = std::tanh( a.fastAccessCoeff(0) ); return c; } template KOKKOS_INLINE_FUNCTION PCE acos(const PCE& a) { KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( a.size() != 1, std::logic_error, "Sacado::UQ::PCE::acos(): argument has size != 1"); ) PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = std::acos( a.fastAccessCoeff(0) ); return c; } template KOKKOS_INLINE_FUNCTION PCE asin(const PCE& a) { KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( a.size() != 1, std::logic_error, "Sacado::UQ::PCE::asin(): argument has size != 1"); ) PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = std::asin( a.fastAccessCoeff(0) ); return c; } template KOKKOS_INLINE_FUNCTION PCE atan(const PCE& a) { KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( a.size() != 1, std::logic_error, "Sacado::UQ::PCE::atan(): argument has size != 1"); ) PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = std::atan( a.fastAccessCoeff(0) ); return c; } /* template KOKKOS_INLINE_FUNCTION PCE acosh(const PCE& a) { KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( a.size() != 1, std::logic_error, "Sacado::UQ::PCE::acosh(): argument has size != 1"); ) PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = std::acosh( a.fastAccessCoeff(0) ); return c; } template KOKKOS_INLINE_FUNCTION PCE asinh(const PCE& a) { KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( a.size() != 1, std::logic_error, "Sacado::UQ::PCE::asinh(): argument has size != 1"); ) PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = std::asinh( a.fastAccessCoeff(0) ); return c; } template KOKKOS_INLINE_FUNCTION PCE atanh(const PCE& a) { KOKKOS_IF_ON_HOST( TEUCHOS_TEST_FOR_EXCEPTION( a.size() != 1, std::logic_error, "Sacado::UQ::PCE::atanh(): argument has size != 1"); ) PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = std::atanh( a.fastAccessCoeff(0) ); return c; } */ template KOKKOS_INLINE_FUNCTION PCE fabs(const PCE& a) { PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = a.two_norm(); return c; } template KOKKOS_INLINE_FUNCTION PCE abs(const PCE& a) { PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = a.two_norm(); return c; } template KOKKOS_INLINE_FUNCTION PCE ceil(const PCE& a) { PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = std::ceil( a.fastAccessCoeff(0) ); return c; } // template // KOKKOS_INLINE_FUNCTION // PCE // max(const PCE& a, const PCE& b) // { // if (a.two_norm() >= b.two_norm()) // return a; // return b; // } template KOKKOS_INLINE_FUNCTION PCE max(const typename PCE::value_type& a, const PCE& b) { if (a >= b.two_norm()) { PCE c(b.cijk(), 1); c.fastAccessCoeff(0) = a; return c; } return b; } template KOKKOS_INLINE_FUNCTION PCE max(const PCE& a, const typename PCE::value_type& b) { if (a.two_norm() >= b) return a; PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = b; return c; } // template // KOKKOS_INLINE_FUNCTION // PCE // min(const PCE& a, const PCE& b) // { // if (a.two_norm() <= b.two_norm()) // return a; // return b; // } template KOKKOS_INLINE_FUNCTION PCE min(const typename PCE::value_type& a, const PCE& b) { if (a <= b.two_norm()) { PCE c(b.cijk(), 1); c.fastAccessCoeff(0) = a; return c; } return b; } template KOKKOS_INLINE_FUNCTION PCE min(const PCE& a, const typename PCE::value_type& b) { if (a.two_norm() <= b) return a; PCE c(a.cijk(), 1); c.fastAccessCoeff(0) = b; return c; } template KOKKOS_INLINE_FUNCTION bool operator==(const PCE& a, const PCE& b) { typedef typename PCE::ordinal_type ordinal_type; const ordinal_type asz = a.size(); const ordinal_type bsz = b.size(); const ordinal_type n = asz > bsz ? asz : bsz; for (ordinal_type i=0; i KOKKOS_INLINE_FUNCTION bool operator==(const typename PCE::value_type& a, const PCE& b) { typedef typename PCE::ordinal_type ordinal_type; const ordinal_type n = b.size(); if (a != b.coeff(0)) return false; for (ordinal_type i=1; i::value_type(0.0)) return false; return true; } template KOKKOS_INLINE_FUNCTION bool operator==(const PCE& a, const typename PCE::value_type& b) { typedef typename PCE::ordinal_type ordinal_type; const ordinal_type n = a.size(); if (a.coeff(0) != b) return false; for (ordinal_type i=1; i::value_type(0.0)) return false; return true; } template KOKKOS_INLINE_FUNCTION bool operator!=(const PCE& a, const PCE& b) { return !(a == b); } template KOKKOS_INLINE_FUNCTION bool operator!=(const typename PCE::value_type& a, const PCE& b) { return !(a == b); } template KOKKOS_INLINE_FUNCTION bool operator!=(const PCE& a, const typename PCE::value_type& b) { return !(a == b); } template KOKKOS_INLINE_FUNCTION bool operator<=(const PCE& a, const PCE& b) { return a.two_norm() <= b.two_norm(); } template KOKKOS_INLINE_FUNCTION bool operator<=(const typename PCE::value_type& a, const PCE& b) { return a <= b.two_norm(); } template KOKKOS_INLINE_FUNCTION bool operator<=(const PCE& a, const typename PCE::value_type& b) { return a.two_norm() <= b; } template KOKKOS_INLINE_FUNCTION bool operator>=(const PCE& a, const PCE& b) { return a.two_norm() >= b.two_norm(); } template KOKKOS_INLINE_FUNCTION bool operator>=(const typename PCE::value_type& a, const PCE& b) { return a >= b.two_norm(); } template KOKKOS_INLINE_FUNCTION bool operator>=(const PCE& a, const typename PCE::value_type& b) { return a.two_norm() >= b; } template KOKKOS_INLINE_FUNCTION bool operator<(const PCE& a, const PCE& b) { return a.two_norm() < b.two_norm(); } template KOKKOS_INLINE_FUNCTION bool operator<(const typename PCE::value_type& a, const PCE& b) { return a < b.two_norm(); } template KOKKOS_INLINE_FUNCTION bool operator<(const PCE& a, const typename PCE::value_type& b) { return a.two_norm() < b; } template KOKKOS_INLINE_FUNCTION bool operator>(const PCE& a, const PCE& b) { return a.two_norm() > b.two_norm(); } template KOKKOS_INLINE_FUNCTION bool operator>(const typename PCE::value_type& a, const PCE& b) { return a > b.two_norm(); } template KOKKOS_INLINE_FUNCTION bool operator>(const PCE& a, const typename PCE::value_type& b) { return a.two_norm() > b; } template KOKKOS_INLINE_FUNCTION bool toBool(const PCE& x) { typedef typename PCE::ordinal_type ordinal_type; bool is_zero = true; const ordinal_type sz = x.size(); for (ordinal_type i=0; i KOKKOS_INLINE_FUNCTION bool operator && (const PCE& x1, const PCE& x2) { return toBool(x1) && toBool(x2); } template KOKKOS_INLINE_FUNCTION bool operator && (const typename PCE::value_type& a, const PCE& x2) { return a && toBool(x2); } template KOKKOS_INLINE_FUNCTION bool operator && (const PCE& x1, const typename PCE::value_type& b) { return toBool(x1) && b; } template KOKKOS_INLINE_FUNCTION bool operator || (const PCE& x1, const PCE& x2) { return toBool(x1) || toBool(x2); } template KOKKOS_INLINE_FUNCTION bool operator || (const typename PCE::value_type& a, const PCE& x2) { return a || toBool(x2); } template KOKKOS_INLINE_FUNCTION bool operator || (const PCE& x1, const typename PCE::value_type& b) { return toBool(x1) || b; } template std::ostream& operator << (std::ostream& os, const PCE& a) { typedef typename PCE::ordinal_type ordinal_type; os << "[ "; for (ordinal_type i=0; i std::istream& operator >> (std::istream& is, PCE& a) { typedef typename PCE::ordinal_type ordinal_type; // Read in the opening "[" char bracket; is >> bracket; for (ordinal_type i=0; i> a.fastAccessCoeff(i); } // Read in the closing "]" is >> bracket; return is; } template KOKKOS_INLINE_FUNCTION void CG_divide(const PCE& a, const PCE& b, PCE& c) { typedef typename PCE::ordinal_type ordinal_type; typedef typename PCE::value_type value_type; const ordinal_type size = c.size(); //Needed scalars value_type alpha, beta, rTz, rTz_old, resid; //Needed temporary PCEs PCE r(a.cijk(),size); PCE p(a.cijk(),size); PCE bp(a.cijk(),size); PCE z(a.cijk(),size); //compute residual = a - b*c r = a - b*c; z = r/b.coeff(0); p = z; resid = r.two_norm(); //Compute =rTz (L2 inner product) rTz = r.inner_product(z); ordinal_type k = 0; value_type tol = 1e-6; while ( resid > tol && k < 100){ bp = b*p; //Compute alpha = / alpha = rTz/p.inner_product(bp); //Update the solution c = c + alpha*p c = c + alpha*p; rTz_old = rTz; //Compute the new residual r = r - alpha*b*p r = r - alpha*bp; resid = r.two_norm(); //Compute beta = rTz_new/ rTz_old and new p z = r/b.coeff(0); rTz = r.inner_product(z); beta = rTz/rTz_old; p = z + beta*p; k++; } } } // namespace UQ } // namespace Sacado