Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_UQ_PCE.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef SACADO_UQ_PCE_HPP
11 #define SACADO_UQ_PCE_HPP
12 
13 #include "Stokhos_ConfigDefs.h"
14 
15 #ifdef HAVE_STOKHOS_SACADO
16 
17 #include "Kokkos_Macros.hpp"
18 
19 #include "Sacado_Traits.hpp"
20 #include "Sacado_mpl_apply.hpp"
21 #include "Stokhos_Is_Constant.hpp"
22 
24 
25 #include <cmath>
26 #include <algorithm> // for std::min and std::max
27 #include <ostream> // for std::ostream
28 #include <initializer_list>
29 
30 namespace Sacado {
31 
32  // Forward declaration
33  template <typename Storage>
34  KOKKOS_INLINE_FUNCTION
36 
38  namespace UQ {
39 
41 
45  template <typename Storage >
46  class PCE {
47 
48  template <class> friend class PCE;
49 
50  public:
51 
53  typedef Storage storage_type;
54 
55  typedef typename storage_type::value_type value_type;
58  typedef typename storage_type::pointer pointer;
59  typedef typename storage_type::volatile_pointer volatile_pointer;
60  typedef typename storage_type::const_pointer const_pointer;
61  typedef typename storage_type::const_volatile_pointer const_volatile_pointer;
62  typedef typename storage_type::reference reference;
63  typedef typename storage_type::volatile_reference volatile_reference;
64  typedef typename storage_type::const_reference const_reference;
65  typedef typename storage_type::const_volatile_reference const_volatile_reference;
66 
68  typedef typename ScalarType<value_type>::type scalar_type;
69 
71  //typedef Stokhos::OrthogPolyBasis<ordinal_type,value_type> basis_type;
72 
76 
78  template <typename S>
79  struct apply {
80  typedef PCE<S> type;
81  };
82 
84 
87  KOKKOS_DEFAULTED_FUNCTION
88  PCE() = default;
89 
91 
94  KOKKOS_INLINE_FUNCTION
95  PCE(const value_type& x) : cijk_(), s_(1, x) {}
96 
98 
101  template <typename M>
102  KOKKOS_INLINE_FUNCTION
104  cijk_(cijkVal), s_(cijk_.dimension()) {}
105 
107 
110  template <typename M>
111  KOKKOS_INLINE_FUNCTION
113  ordinal_type sz) : cijk_(cijkVal), s_(sz) {}
114 
116 
120  template <typename M>
121  KOKKOS_INLINE_FUNCTION
123  ordinal_type sz, pointer v, bool owned) :
124  cijk_(cijkVal), s_(sz,v,owned) {}
125 
127  KOKKOS_INLINE_FUNCTION
128  PCE(const PCE& x) : cijk_(x.cijk_), s_(1,x.fastAccessCoeff(0)) {
129  if (x.size() > 1 && !is_constant(x))
130  s_ = x.s_;
131  }
132 
134  KOKKOS_INLINE_FUNCTION
135  PCE(const volatile PCE& x) :
136  cijk_(const_cast<const my_cijk_type&>(x.cijk_)),
137  s_(1,value_type(x.fastAccessCoeff(0))) {
138  if (x.size() > 1 && !is_constant(x))
139  s_ = x.s_;
140  }
141 
143 
146  PCE(std::initializer_list<value_type> l) :
147  cijk_(), s_(l.size(), l.begin()) {}
148 
150  KOKKOS_DEFAULTED_FUNCTION
151  ~PCE() = default;
152 
154  KOKKOS_INLINE_FUNCTION
155  void init(const_reference v) { s_.init(v); }
156 
158  KOKKOS_INLINE_FUNCTION
159  void init(const_reference v) volatile { s_.init(v); }
160 
162  KOKKOS_INLINE_FUNCTION
163  void init(const_pointer v) { s_.init(v); }
164 
166  KOKKOS_INLINE_FUNCTION
167  void init(const_pointer v) volatile { s_.init(v); }
168 
170  template <typename S>
171  KOKKOS_INLINE_FUNCTION
172  void init(const PCE<S>& v) { s_.init(v.coeff()); }
173 
175  template <typename S>
176  KOKKOS_INLINE_FUNCTION
177  void init(const PCE<S>& v) volatile { s_.init(v.coeff()); }
178 
180  KOKKOS_INLINE_FUNCTION
181  void load(pointer v) { s_.load(v); }
182 
184  KOKKOS_INLINE_FUNCTION
185  void load(pointer v) volatile { s_.load(v); }
186 
188  template <typename S>
189  KOKKOS_INLINE_FUNCTION
190  void load(PCE<S>& v) { s_.load(v.coeff()); }
191 
193  template <typename S>
194  KOKKOS_INLINE_FUNCTION
195  void load(PCE<S>& v) volatile { s_.load(v.coeff()); }
196 
198 
201  template <typename M>
202  KOKKOS_INLINE_FUNCTION
204  cijk_ = cijkVal;
205  s_.resize(cijk_.dimension());
206  }
207 
209 
212  template <typename M>
213  KOKKOS_INLINE_FUNCTION
214  void reset(const Stokhos::CrsProductTensor<value_type, execution_space, M>& cijkVal) volatile {
215  cijk_ = cijkVal;
216  s_.resize(cijk_.dimension());
217  }
218 
220 
223  template <typename M>
224  KOKKOS_INLINE_FUNCTION
226  cijk_ = cijkVal;
227  s_.resize(sz);
228  }
229 
231 
234  template <typename M>
235  KOKKOS_INLINE_FUNCTION
236  void reset(const Stokhos::CrsProductTensor<value_type, execution_space, M>& cijkVal, ordinal_type sz) volatile {
237  cijk_ = cijkVal;
238  s_.resize(sz);
239  }
240 
242 
251  KOKKOS_INLINE_FUNCTION
252  void copyForWrite() { }
253 
254  /*
256  KOKKOS_INLINE_FUNCTION
257  value_type evaluate(const Teuchos::Array<value_type>& point) const;
258 
260  KOKKOS_INLINE_FUNCTION
261  value_type evaluate(const Teuchos::Array<value_type>& point,
262  const Teuchos::Array<value_type>& bvals) const;
263  */
264 
266  KOKKOS_INLINE_FUNCTION
267  value_type mean() const { return this->fastAccessCoeff(0); }
268 
270  KOKKOS_INLINE_FUNCTION
271  value_type standard_deviation() const;
272 
274  KOKKOS_INLINE_FUNCTION
275  value_type two_norm() const {
276  return std::sqrt(this->two_norm_squared());
277  }
278 
280  KOKKOS_INLINE_FUNCTION
281  value_type two_norm_squared() const;
282 
284  KOKKOS_INLINE_FUNCTION
285  value_type inner_product(const PCE& x) const;
286 
288  KOKKOS_INLINE_FUNCTION
289  bool isEqualTo(const PCE& x) const;
290 
292  KOKKOS_INLINE_FUNCTION
293  bool isEqualTo(const PCE& x) const volatile;
294 
299 
301  KOKKOS_INLINE_FUNCTION
302  PCE<Storage>& operator=(const value_type val);
303 
305  KOKKOS_INLINE_FUNCTION
306  /*volatile*/ PCE<Storage>& operator=(const value_type val) volatile;
307 
309  KOKKOS_INLINE_FUNCTION
310  PCE<Storage>& operator=(const PCE<Storage>& x);
311 
313  KOKKOS_INLINE_FUNCTION
314  PCE<Storage>& operator=(const volatile PCE<Storage>& x);
315 
317  KOKKOS_INLINE_FUNCTION
318  /*volatile*/ PCE<Storage>& operator=(const PCE<Storage>& x) volatile;
319 
321  KOKKOS_INLINE_FUNCTION
322  /*volatile*/ PCE<Storage>& operator=(const volatile PCE<Storage>& x) volatile;
323 
325  template <typename S>
326  KOKKOS_INLINE_FUNCTION
327  PCE<Storage>& operator=(const PCE<S>& x) {
328  // Don't copy cijk as it may be on a different device
329  const ordinal_type sz_new = x.size();
330  s_.resize(sz_new);
331  for (ordinal_type i=0; i<sz_new; i++)
332  s_[i] = x.s_[i];
333 
334  // For DyamicStorage as a view (is_owned=false), we need to set
335  // the trailing entries when assigning a constant vector (because
336  // the copy constructor in this case doesn't reset the size of this)
337  const ordinal_type sz = s_.size();
338  if (sz > sz_new)
339  for (ordinal_type i=sz_new; i<sz; i++)
340  s_[i] = value_type(0);
341 
342  return *this;
343  }
344 
346 
349  PCE& operator=(std::initializer_list<value_type> l) {
350  const ordinal_type lsz = l.size();
351  if (lsz != s_.size())
352  s_.resize(lsz);
353  s_.init(l.begin(), lsz);
354  return *this;
355  }
356 
358 
361  /*volatile*/ PCE&
362  operator=(std::initializer_list<value_type> l) volatile {
363  const ordinal_type lsz = l.size();
364  if (lsz != s_.size())
365  s_.resize(lsz);
366  s_.init(l.begin(), lsz);
367  return const_cast<PCE&>(*this);
368  }
369 
371 
376 
377  /*
379  KOKKOS_INLINE_FUNCTION
380  Teuchos::RCP<const basis_type> basis() const { return s_.basis(); }
381  */
382 
384  KOKKOS_INLINE_FUNCTION
385  my_cijk_type cijk() const { return cijk_; }
386 
388  KOKKOS_INLINE_FUNCTION
389  my_cijk_type cijk() const volatile {
390  return const_cast<const my_cijk_type&>(cijk_);
391  }
392 
394 
399 
401  KOKKOS_INLINE_FUNCTION
402  const_volatile_reference val() const volatile { return s_[0]; }
403 
405  KOKKOS_INLINE_FUNCTION
406  const_reference val() const { return s_[0]; }
407 
409  KOKKOS_INLINE_FUNCTION
410  volatile_reference val() volatile { return s_[0]; }
411 
413  KOKKOS_INLINE_FUNCTION
414  reference val() { return s_[0]; }
415 
417 
422 
424  KOKKOS_INLINE_FUNCTION
425  ordinal_type size() const { return s_.size();}
426 
428  KOKKOS_INLINE_FUNCTION
429  ordinal_type size() const volatile { return s_.size();}
430 
432  KOKKOS_INLINE_FUNCTION
433  bool hasFastAccess(ordinal_type sz) const { return s_.size()>=sz;}
434 
436  KOKKOS_INLINE_FUNCTION
437  bool hasFastAccess(ordinal_type sz) const volatile {
438  return s_.size()>=sz;
439  }
440 
442  KOKKOS_INLINE_FUNCTION
443  const_pointer coeff() const { return s_.coeff();}
444 
446  KOKKOS_INLINE_FUNCTION
447  const_volatile_pointer coeff() const volatile { return s_.coeff();}
448 
450  KOKKOS_INLINE_FUNCTION
451  volatile_pointer coeff() volatile { return s_.coeff();}
452 
454  KOKKOS_INLINE_FUNCTION
455  pointer coeff() { return s_.coeff();}
456 
458  KOKKOS_INLINE_FUNCTION
459  value_type coeff(ordinal_type i) const {
460  value_type tmp= i<s_.size() ? s_[i]:value_type(0.); return tmp;}
461 
463  KOKKOS_INLINE_FUNCTION
464  value_type coeff(ordinal_type i) const volatile {
465  value_type tmp= i<s_.size() ? s_[i]:value_type(0.); return tmp;}
466 
468  KOKKOS_INLINE_FUNCTION
469  const_volatile_reference fastAccessCoeff(ordinal_type i) const volatile {
470  return s_[i];}
471 
473  KOKKOS_INLINE_FUNCTION
474  const_reference fastAccessCoeff(ordinal_type i) const {
475  return s_[i];}
476 
478  KOKKOS_INLINE_FUNCTION
479  volatile_reference fastAccessCoeff(ordinal_type i) volatile {
480  return s_[i];}
481 
483  KOKKOS_INLINE_FUNCTION
484  reference fastAccessCoeff(ordinal_type i) {
485  return s_[i];}
486 
487  /*
489  KOKKOS_INLINE_FUNCTION
490  reference term(ordinal_type dimension, ordinal_type order) {
491  return s_.term(dimension, order); }
492 
494  KOKKOS_INLINE_FUNCTION
495  const_reference term(ordinal_type dimension, ordinal_type order) const {
496  return s_.term(dimension, order); }
497 
499  KOKKOS_INLINE_FUNCTION
500  Teuchos::Array<ordinal_type> order(ordinal_type term) const {
501  return s_.order(term); }
502  */
503 
505  KOKKOS_INLINE_FUNCTION
506  pointer begin() { return s_.coeff(); }
507 
509  KOKKOS_INLINE_FUNCTION
510  const_pointer begin() const { return s_.coeff(); }
511 
513  KOKKOS_INLINE_FUNCTION
514  volatile_pointer begin() volatile { return s_.coeff(); }
515 
517  KOKKOS_INLINE_FUNCTION
518  const_volatile_pointer begin() const volatile { return s_.coeff(); }
519 
521  KOKKOS_INLINE_FUNCTION
522  const_pointer cbegin() const { return s_.coeff(); }
523 
525  KOKKOS_INLINE_FUNCTION
526  const_volatile_pointer cbegin() const volatile { return s_.coeff(); }
527 
529  KOKKOS_INLINE_FUNCTION
530  pointer end() { return s_.coeff() + s_.size(); }
531 
533  KOKKOS_INLINE_FUNCTION
534  const_pointer end() const { return s_.coeff() + s_.size(); }
535 
537  KOKKOS_INLINE_FUNCTION
538  volatile_pointer end() volatile { return s_.coeff() + s_.size(); }
539 
541  KOKKOS_INLINE_FUNCTION
542  const_volatile_pointer end() const volatile { return s_.coeff() + s_.size(); }
543 
545  KOKKOS_INLINE_FUNCTION
546  const_pointer cend() const { return s_.coeff()+ s_.size(); }
547 
549  KOKKOS_INLINE_FUNCTION
550  const_volatile_pointer cend() const volatile { return s_.coeff()+ s_.size(); }
551 
553 
558 
560  KOKKOS_INLINE_FUNCTION
561  PCE operator + () const { return *this; }
562 
564  KOKKOS_INLINE_FUNCTION
565  PCE operator + () const volatile { return *this; }
566 
568  KOKKOS_INLINE_FUNCTION
569  PCE operator - () const;
570 
572  KOKKOS_INLINE_FUNCTION
573  PCE operator - () const volatile;
574 
576  KOKKOS_INLINE_FUNCTION
577  PCE& operator += (const value_type x) {
578  s_[0] += x;
579  return *this;
580  }
581 
583  KOKKOS_INLINE_FUNCTION
584  /*volatile*/ PCE& operator += (const value_type x) volatile {
585  s_[0] += x;
586  return const_cast<PCE&>(*this);
587  }
588 
590  KOKKOS_INLINE_FUNCTION
591  PCE& operator -= (const value_type x) {
592  s_[0] -= x;
593  return *this;
594  }
595 
597  KOKKOS_INLINE_FUNCTION
598  /*volatile*/ PCE& operator -= (const value_type x) volatile {
599  s_[0] -= x;
600  return const_cast<PCE&>(*this);
601  }
602 
604  KOKKOS_INLINE_FUNCTION
605  PCE& operator *= (const value_type x);
606 
608  KOKKOS_INLINE_FUNCTION
609  /*volatile*/ PCE& operator *= (const value_type x) volatile;
610 
612  KOKKOS_INLINE_FUNCTION
613  PCE& operator /= (const value_type x);
614 
616  KOKKOS_INLINE_FUNCTION
617  /*volatile*/ PCE& operator /= (const value_type x) volatile;
618 
620  KOKKOS_INLINE_FUNCTION
621  PCE& operator += (const PCE& x);
622 
624  KOKKOS_INLINE_FUNCTION
625  PCE& operator += (const volatile PCE& x) {
626  return *this += const_cast<const PCE&>(x);
627  }
628 
630  KOKKOS_INLINE_FUNCTION
631  /*volatile*/ PCE& operator += (const PCE& x) volatile {
632  return const_cast<PCE&>(*this) += x;
633  }
634 
636  KOKKOS_INLINE_FUNCTION
637  /*volatile*/ PCE& operator += (const volatile PCE& x) volatile {
638  return const_cast<PCE&>(*this) += const_cast<const PCE&>(x);
639  }
640 
642  KOKKOS_INLINE_FUNCTION
643  PCE& operator -= (const PCE& x);
644 
646  KOKKOS_INLINE_FUNCTION
647  PCE& operator -= (const volatile PCE& x) {
648  return *this -= const_cast<const PCE&>(x);
649  }
650 
652  KOKKOS_INLINE_FUNCTION
653  /*volatile*/ PCE& operator -= (const PCE& x) volatile {
654  return const_cast<PCE&>(*this) -= x;
655  }
656 
658  KOKKOS_INLINE_FUNCTION
659  /*volatile*/ PCE& operator -= (const volatile PCE& x) volatile {
660  return const_cast<PCE&>(*this) -= const_cast<const PCE&>(x);
661  }
662 
664  KOKKOS_INLINE_FUNCTION
665  PCE& operator *= (const PCE& x);
666 
668  KOKKOS_INLINE_FUNCTION
669  PCE& operator *= (const volatile PCE& x) {
670  return *this *= const_cast<const PCE&>(x);
671  }
672 
674  KOKKOS_INLINE_FUNCTION
675  /*volatile*/ PCE& operator *= (const PCE& x) volatile {
676  return const_cast<PCE&>(*this) *= x;
677  }
678 
680  KOKKOS_INLINE_FUNCTION
681  /*volatile*/ PCE& operator *= (const volatile PCE& x) volatile {
682  return const_cast<PCE&>(*this) *= const_cast<const PCE&>(x);
683  }
684 
686  KOKKOS_INLINE_FUNCTION
687  PCE& operator /= (const PCE& x);
688 
690  KOKKOS_INLINE_FUNCTION
691  PCE& operator /= (const volatile PCE& x) {
692  return *this /= const_cast<const PCE&>(x);
693  }
694 
696  KOKKOS_INLINE_FUNCTION
697  /*volatile*/ PCE& operator /= (const PCE& x) volatile {
698  return const_cast<PCE&>(*this) /= x;
699  }
700 
702  KOKKOS_INLINE_FUNCTION
703  /*volatile*/ PCE& operator /= (const volatile PCE& x) volatile {
704  return const_cast<PCE&>(*this) /= const_cast<const PCE&>(x);
705  }
706 
708  KOKKOS_INLINE_FUNCTION
709  PCE& operator++() {
710  ++(s_[0]);
711  return *this;
712  }
713 
715  KOKKOS_INLINE_FUNCTION
716  volatile PCE& operator++() volatile {
717  ++(s_[0]);
718  return *this;
719  }
720 
722  KOKKOS_INLINE_FUNCTION
723  PCE operator++(int) {
724  PCE tmp(*this);
725  ++(*this);
726  return tmp;
727  }
728 
730  KOKKOS_INLINE_FUNCTION
731  PCE operator++(int) volatile {
732  PCE tmp(*this);
733  ++(*this);
734  return tmp;
735  }
736 
738  KOKKOS_INLINE_FUNCTION
739  PCE& operator--() {
740  --(s_[0]);
741  return *this;
742  }
743 
745  KOKKOS_INLINE_FUNCTION
746  volatile PCE& operator--() volatile {
747  --(s_[0]);
748  return *this;
749  }
750 
752  KOKKOS_INLINE_FUNCTION
753  PCE operator--(int) {
754  PCE tmp(*this);
755  --(*this);
756  return tmp;
757  }
758 
760  KOKKOS_INLINE_FUNCTION
761  PCE operator--(int) volatile {
762  PCE tmp(*this);
763  --(*this);
764  return tmp;
765  }
766 
767 
768 
770 
771  protected:
772 
773  typedef typename my_cijk_type::size_type cijk_size_type;
774 
776  my_cijk_type cijk_;
777 
778  Storage s_;
779 
780  private:
781 
782  //PCE division using CG with diagonal preconditioning
783 // KOKKOS_INLINE_FUNCTION
784 // void CG_divide(const PCE& a, const PCE& b, PCE& c);
785 
786 
787  }; // class PCE
788 
789  template <typename Storage>
790  KOKKOS_INLINE_FUNCTION
791  void CG_divide(const PCE<Storage>& a, const PCE<Storage>& b, PCE<Storage>& c);
792 
793  // Operations
794  template <typename Storage>
795  KOKKOS_INLINE_FUNCTION
796  PCE<Storage>
797  operator+(const PCE<Storage>& a, const PCE<Storage>& b);
798 
799  template <typename Storage>
800  KOKKOS_INLINE_FUNCTION
801  PCE<Storage>
802  operator+(const volatile PCE<Storage>& a, const PCE<Storage>& b) {
803  return const_cast<const PCE<Storage>&>(a) + b;
804  }
805 
806  template <typename Storage>
807  KOKKOS_INLINE_FUNCTION
808  PCE<Storage>
809  operator+(const PCE<Storage>& a, const volatile PCE<Storage>& b) {
810  return a + const_cast<const PCE<Storage>&>(b);
811  }
812 
813  template <typename Storage>
814  KOKKOS_INLINE_FUNCTION
815  PCE<Storage>
816  operator+(const volatile PCE<Storage>& a, const volatile PCE<Storage>& b) {
817  return const_cast<const PCE<Storage>&>(a) +
818  const_cast<const PCE<Storage>&>(b);
819  }
820 
821  template <typename Storage>
822  KOKKOS_INLINE_FUNCTION
823  PCE<Storage>
824  operator+(const typename PCE<Storage>::value_type& a,
825  const PCE<Storage>& b);
826 
827  template <typename Storage>
828  KOKKOS_INLINE_FUNCTION
829  PCE<Storage>
830  operator+(const PCE<Storage>& a,
831  const typename PCE<Storage>::value_type& b);
832 
833  template <typename Storage>
834  KOKKOS_INLINE_FUNCTION
835  PCE<Storage>
836  operator-(const PCE<Storage>& a, const PCE<Storage>& b);
837 
838  template <typename Storage> PCE<Storage>
839  KOKKOS_INLINE_FUNCTION
840  operator-(const typename PCE<Storage>::value_type& a,
841  const PCE<Storage>& b);
842 
843  template <typename Storage>
844  KOKKOS_INLINE_FUNCTION
845  PCE<Storage>
846  operator-(const PCE<Storage>& a,
847  const typename PCE<Storage>::value_type& b);
848 
849  template <typename Storage>
850  KOKKOS_INLINE_FUNCTION
851  PCE<Storage>
852  operator*(const PCE<Storage>& a, const PCE<Storage>& b);
853 
854  template <typename Storage>
855  KOKKOS_INLINE_FUNCTION
856  PCE<Storage>
857  operator*(const typename PCE<Storage>::value_type& a,
858  const PCE<Storage>& b);
859 
860  template <typename Storage> PCE<Storage>
861  KOKKOS_INLINE_FUNCTION
862  operator*(const PCE<Storage>& a,
863  const typename PCE<Storage>::value_type& b);
864 
865  template <typename Storage>
866  KOKKOS_INLINE_FUNCTION
867  PCE<Storage>
868  operator/(const PCE<Storage>& a, const PCE<Storage>& b);
869 
870  template <typename Storage>
871  KOKKOS_INLINE_FUNCTION
872  PCE<Storage>
873  operator/(const typename PCE<Storage>::value_type& a,
874  const PCE<Storage>& b);
875 
876  template <typename Storage>
877  KOKKOS_INLINE_FUNCTION
878  PCE<Storage>
879  operator/(const PCE<Storage>& a,
880  const typename PCE<Storage>::value_type& b);
881 
882  template <typename Storage>
883  KOKKOS_INLINE_FUNCTION
884  PCE<Storage>
885  exp(const PCE<Storage>& a);
886 
887  template <typename Storage>
888  KOKKOS_INLINE_FUNCTION
889  PCE<Storage>
890  log(const PCE<Storage>& a);
891 
892  template <typename Storage>
893  KOKKOS_INLINE_FUNCTION
894  void
895  log(PCE<Storage>& c, const PCE<Storage>& a);
896 
897  template <typename Storage>
898  KOKKOS_INLINE_FUNCTION
899  PCE<Storage>
900  log10(const PCE<Storage>& a);
901 
902  template <typename Storage>
903  KOKKOS_INLINE_FUNCTION
904  PCE<Storage>
905  sqrt(const PCE<Storage>& a);
906 
907  template <typename Storage>
908  KOKKOS_INLINE_FUNCTION
909  PCE<Storage>
910  cbrt(const PCE<Storage>& a);
911 
912  template <typename Storage>
913  KOKKOS_INLINE_FUNCTION
914  PCE<Storage>
915  pow(const PCE<Storage>& a, const PCE<Storage>& b);
916 
917  template <typename Storage>
918  KOKKOS_INLINE_FUNCTION
919  PCE<Storage>
920  pow(const typename PCE<Storage>::value_type& a, const PCE<Storage>& b);
921 
922  template <typename Storage> PCE<Storage>
923  KOKKOS_INLINE_FUNCTION
924  pow(const PCE<Storage>& a,
925  const typename PCE<Storage>::value_type& b);
926 
927  template <typename Storage>
928  KOKKOS_INLINE_FUNCTION
929  PCE<Storage>
930  cos(const PCE<Storage>& a);
931 
932  template <typename Storage>
933  KOKKOS_INLINE_FUNCTION
934  PCE<Storage>
935  sin(const PCE<Storage>& a);
936 
937  template <typename Storage>
938  KOKKOS_INLINE_FUNCTION
939  PCE<Storage>
940  tan(const PCE<Storage>& a);
941 
942  template <typename Storage>
943  KOKKOS_INLINE_FUNCTION
944  PCE<Storage>
945  cosh(const PCE<Storage>& a);
946 
947  template <typename Storage>
948  KOKKOS_INLINE_FUNCTION
949  PCE<Storage>
950  sinh(const PCE<Storage>& a);
951 
952  template <typename Storage>
953  KOKKOS_INLINE_FUNCTION
954  PCE<Storage>
955  tanh(const PCE<Storage>& a);
956 
957  template <typename Storage>
958  KOKKOS_INLINE_FUNCTION
959  PCE<Storage>
960  acos(const PCE<Storage>& a);
961 
962  template <typename Storage>
963  KOKKOS_INLINE_FUNCTION
964  PCE<Storage>
965  asin(const PCE<Storage>& a);
966 
967  template <typename Storage>
968  KOKKOS_INLINE_FUNCTION
969  PCE<Storage>
970  atan(const PCE<Storage>& a);
971 
972  template <typename Storage>
973  KOKKOS_INLINE_FUNCTION
974  PCE<Storage>
975  atan2(const PCE<Storage>& a, const PCE<Storage>& b);
976 
977  template <typename Storage>
978  KOKKOS_INLINE_FUNCTION
979  PCE<Storage>
980  atan2(const typename PCE<Storage>::value_type& a,
981  const PCE<Storage>& b);
982 
983  template <typename Storage>
984  KOKKOS_INLINE_FUNCTION
985  PCE<Storage>
986  atan2(const PCE<Storage>& a,
987  const typename PCE<Storage>::value_type& b);
988 
989  template <typename Storage>
990  KOKKOS_INLINE_FUNCTION
991  PCE<Storage>
992  acosh(const PCE<Storage>& a);
993 
994  template <typename Storage>
995  KOKKOS_INLINE_FUNCTION
996  PCE<Storage>
997  asinh(const PCE<Storage>& a);
998 
999  template <typename Storage>
1000  KOKKOS_INLINE_FUNCTION
1001  PCE<Storage>
1002  atanh(const PCE<Storage>& a);
1003 
1004  template <typename Storage>
1005  KOKKOS_INLINE_FUNCTION
1006  PCE<Storage>
1007  abs(const PCE<Storage>& a);
1008 
1009  template <typename Storage>
1010  KOKKOS_INLINE_FUNCTION
1011  PCE<Storage>
1012  fabs(const PCE<Storage>& a);
1013 
1014  template <typename Storage>
1015  KOKKOS_INLINE_FUNCTION
1016  PCE<Storage>
1017  ceil(const PCE<Storage>& a);
1018 
1019  // template <typename Storage>
1020  // KOKKOS_INLINE_FUNCTION
1021  // PCE<Storage>
1022  // max(const PCE<Storage>& a, const PCE<Storage>& b);
1023 
1024  template <typename Storage>
1025  KOKKOS_INLINE_FUNCTION
1026  PCE<Storage>
1027  max(const typename PCE<Storage>::value_type& a,
1028  const PCE<Storage>& b);
1029 
1030  template <typename Storage>
1031  KOKKOS_INLINE_FUNCTION
1032  PCE<Storage>
1033  max(const PCE<Storage>& a,
1034  const typename PCE<Storage>::value_type& b);
1035 
1036  // template <typename Storage>
1037  // KOKKOS_INLINE_FUNCTION
1038  // PCE<Storage>
1039  // min(const PCE<Storage>& a, const PCE<Storage>& b);
1040 
1041  template <typename Storage>
1042  KOKKOS_INLINE_FUNCTION
1043  PCE<Storage>
1044  min(const typename PCE<Storage>::value_type& a,
1045  const PCE<Storage>& b);
1046 
1047  template <typename Storage>
1048  KOKKOS_INLINE_FUNCTION
1049  PCE<Storage>
1050  min(const PCE<Storage>& a,
1051  const typename PCE<Storage>::value_type& b);
1052 
1053  template <typename Storage>
1054  KOKKOS_INLINE_FUNCTION
1055  bool
1056  operator==(const PCE<Storage>& a, const PCE<Storage>& b);
1057 
1058  template <typename Storage>
1059  KOKKOS_INLINE_FUNCTION
1060  bool
1061  operator==(const typename PCE<Storage>::value_type& a,
1062  const PCE<Storage>& b);
1063 
1064  template <typename Storage>
1065  KOKKOS_INLINE_FUNCTION
1066  bool
1067  operator==(const PCE<Storage>& a,
1068  const typename PCE<Storage>::value_type& b);
1069 
1070  template <typename Storage>
1071  KOKKOS_INLINE_FUNCTION
1072  bool
1073  operator!=(const PCE<Storage>& a, const PCE<Storage>& b);
1074 
1075  template <typename Storage>
1076  KOKKOS_INLINE_FUNCTION
1077  bool
1078  operator!=(const typename PCE<Storage>::value_type& a,
1079  const PCE<Storage>& b);
1080 
1081  template <typename Storage>
1082  KOKKOS_INLINE_FUNCTION
1083  bool
1084  operator!=(const PCE<Storage>& a,
1085  const typename PCE<Storage>::value_type& b);
1086 
1087  template <typename Storage>
1088  KOKKOS_INLINE_FUNCTION
1089  bool
1090  operator<=(const PCE<Storage>& a,
1091  const PCE<Storage>& b);
1092 
1093  template <typename Storage>
1094  KOKKOS_INLINE_FUNCTION
1095  bool
1097  const PCE<Storage>& b);
1098 
1099  template <typename Storage>
1100  KOKKOS_INLINE_FUNCTION
1101  bool
1102  operator<=(const PCE<Storage>& a,
1103  const typename PCE<Storage>::value_type& b);
1104 
1105  template <typename Storage>
1106  KOKKOS_INLINE_FUNCTION
1107  bool
1108  operator>=(const PCE<Storage>& a, const PCE<Storage>& b);
1109 
1110  template <typename Storage>
1111  KOKKOS_INLINE_FUNCTION
1112  bool
1113  operator>=(const typename PCE<Storage>::value_type& a,
1114  const PCE<Storage>& b);
1115 
1116  template <typename Storage>
1117  KOKKOS_INLINE_FUNCTION
1118  bool
1119  operator>=(const PCE<Storage>& a,
1120  const typename PCE<Storage>::value_type& b);
1121 
1122  template <typename Storage>
1123  KOKKOS_INLINE_FUNCTION
1124  bool
1125  operator<(const PCE<Storage>& a, const PCE<Storage>& b);
1126 
1127  template <typename Storage>
1128  KOKKOS_INLINE_FUNCTION
1129  bool
1131  const PCE<Storage>& b);
1132 
1133  template <typename Storage>
1134  KOKKOS_INLINE_FUNCTION
1135  bool
1136  operator<(const PCE<Storage>& a,
1137  const typename PCE<Storage>::value_type& b);
1138 
1139  template <typename Storage>
1140  KOKKOS_INLINE_FUNCTION
1141  bool
1142  operator>(const PCE<Storage>& a, const PCE<Storage>& b);
1143 
1144  template <typename Storage>
1145  KOKKOS_INLINE_FUNCTION
1146  bool
1147  operator>(const typename PCE<Storage>::value_type& a,
1148  const PCE<Storage>& b);
1149 
1150  template <typename Storage>
1151  KOKKOS_INLINE_FUNCTION
1152  bool
1153  operator>(const PCE<Storage>& a,
1154  const typename PCE<Storage>::value_type& b);
1155 
1156  template <typename Storage>
1157  std::ostream&
1158  operator << (std::ostream& os, const PCE<Storage>& a);
1159 
1160  template <typename Storage>
1161  std::istream&
1162  operator >> (std::istream& os, PCE<Storage>& a);
1163 
1165  struct PCEPartition {
1166  unsigned begin ;
1167  unsigned end ;
1168 
1169  template< typename iType0 , typename iType1 >
1170  KOKKOS_INLINE_FUNCTION
1171  PCEPartition( const iType0 & i0 , const iType1 & i1 ) :
1172  begin(i0), end(i1) {}
1173  };
1174 
1175 /* template <typename Storage>
1176  KOKKOS_INLINE_FUNCTION
1177  void
1178  PCE<Storage>::
1179  CG_divide(const PCE<Storage>& a, const PCE<Storage>& b, PCE<Storage>& c) {
1180 // typedef typename PCE<Storage>::ordinal_type ordinal_type;
1181 // typedef typename PCE<Storage>::value_type value_type;
1182 
1183  const ordinal_type size = c.size();
1184  //Needed scalars
1185  value_type alpha, beta, rTz, rTz_old, resid;
1186 
1187  //Needed temporary PCEs
1188  PCE<Storage> r(a.cijk(),size);
1189  PCE<Storage> p(a.cijk(),size);
1190  PCE<Storage> bp(a.cijk(),size);
1191  PCE<Storage> z(a.cijk(),size);
1192 
1193  //compute residual = a - b*c
1194  r = a - b*c;
1195  z = r/b.coeff(0);
1196  p = z;
1197  resid = r.two_norm();
1198  //Compute <r,z>=rTz (L2 inner product)
1199  rTz = r.inner_product(z);
1200  ordinal_type k = 0;
1201  value_type tol = 1e-6;
1202  while ( resid > tol && k < 100){
1203  //Compute b*p
1204  bp = b*p;
1205 
1206  //Compute alpha = <r,z>/<p,b*p>
1207  alpha = rTz/p.inner_product(bp);
1208 
1209  //Check alpha is positive!
1210  //Update the solution c = c + alpha*p
1211  c = c + alpha*p;
1212  rTz_old = rTz;
1213 
1214  //Compute the new residual r = r - alpha*b*p
1215  r = r - alpha*bp;
1216  resid = r.two_norm();
1217 
1218  //Compute beta = rTz_new/ rTz_old and new p
1219  z = r/b.coeff(0);
1220  rTz = r.inner_product(z);
1221  beta = rTz/rTz_old;
1222  p = z + beta*p;
1223  k++;
1224  }
1225 // return c;
1226  }
1227 */
1228 
1229  template <typename S>
1230  void memcpy(PCE<S>* dst, const PCE<S>* src, const size_t sz) {
1231  const size_t n = sz / sizeof(PCE<S>);
1232  for (size_t i=0; i<n; ++i)
1233  dst[i] = src[i];
1234  }
1235 
1236  } // namespace PCE
1237 
1239  template <typename T> struct is_uq_pce {
1240  static const bool value = false;
1241  };
1242  template <typename S> struct is_uq_pce< UQ::PCE<S> > {
1243  static const bool value = true;
1244  };
1245  template <typename T> struct is_uq_pce< const T > {
1246  static const bool value = is_uq_pce<T>::value;
1247  };
1248  template <typename T> struct is_uq_pce< T* > {
1249  static const bool value = is_uq_pce<T>::value;
1250  };
1251  template <typename T> struct is_uq_pce< T[] > {
1252  static const bool value = is_uq_pce<T>::value;
1253  };
1254  template <typename T, unsigned N> struct is_uq_pce< T[N] > {
1255  static const bool value = is_uq_pce<T>::value;
1256  };
1257 
1258  // Utility function to see if a PCE is really a constant
1259  template <typename Storage>
1260  KOKKOS_INLINE_FUNCTION
1261  bool is_constant(const Sacado::UQ::PCE<Storage>& x)
1262  {
1263  typedef typename Storage::ordinal_type ordinal_type;
1264  typedef typename Storage::value_type value_type;
1265 
1266  // All size-1 expansions are constants
1267  const ordinal_type sz = x.size();
1268  if (sz == 1) return true;
1269 
1270  // Maybe use a tolerance????
1271  const value_type zero = 0;
1272  for (ordinal_type i=1; i<sz; ++i)
1273  if (x.fastAccessCoeff(i) != zero) return false;
1274 
1275  return true;
1276  }
1277 
1278 } // namespace Sacado
1279 
1280 #include "Sacado_UQ_PCE_Traits.hpp"
1281 #include "Sacado_UQ_PCE_Imp.hpp"
1282 
1283 #include "Kokkos_NumericTraits.hpp"
1284 
1285 namespace Kokkos {
1286 
1287 template <typename Storage>
1288 struct reduction_identity< Sacado::UQ::PCE<Storage> > {
1289  typedef Sacado::UQ::PCE<Storage> pce;
1290  typedef typename Storage::value_type scalar;
1291  typedef reduction_identity<scalar> RIS;
1292  KOKKOS_FORCEINLINE_FUNCTION constexpr static pce sum() {
1293  return pce(RIS::sum());
1294  }
1295  KOKKOS_FORCEINLINE_FUNCTION constexpr static pce prod() {
1296  return pce(RIS::prod());
1297  }
1298  KOKKOS_FORCEINLINE_FUNCTION constexpr static pce max() {
1299  return pce(RIS::max());
1300  }
1301  KOKKOS_FORCEINLINE_FUNCTION constexpr static pce min() {
1302  return pce(RIS::min());
1303  }
1304 };
1305 
1306 namespace Impl {
1307  template <typename Storage>
1308  struct promote<Sacado::UQ::PCE<Storage>,false> {
1309  using type = typename Sacado::UQ::PCE<Storage>;
1310  };
1311 }
1312 
1313 }
1314 
1315 #endif // HAVE_STOKHOS_SACADO
1316 
1317 #endif // SACADO_PCE_ORTHOGPOLY_HPP
KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > fabs(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > tan(const PCE< Storage > &a)
Stokhos::StandardStorage< int, double > storage_type
KOKKOS_INLINE_FUNCTION PCE< Storage > sinh(const PCE< Storage > &a)
atanh(expr.val())
KOKKOS_INLINE_FUNCTION PCE< Storage > pow(const PCE< Storage > &a, const PCE< Storage > &b)
Kokkos::DefaultExecutionSpace execution_space
KOKKOS_INLINE_FUNCTION void CG_divide(const PCE< Storage > &a, const PCE< Storage > &b, PCE< Storage > &c)
KOKKOS_INLINE_FUNCTION PCE< Storage > tanh(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > cbrt(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION bool operator!=(const PCE< Storage > &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION PCE< Storage > acos(const PCE< Storage > &a)
atan2(expr1.val(), expr2.val())
KOKKOS_INLINE_FUNCTION PCE< Storage > min(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
Sparse product tensor with replicated entries to provide subsets with a given coordinate.
asinh(expr.val())
KOKKOS_INLINE_FUNCTION bool operator>(const PCE< Storage > &a, const PCE< Storage > &b)
std::istream & operator>>(std::istream &is, PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > operator/(const PCE< Storage > &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION PCE< Storage > ceil(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > operator-(const PCE< Storage > &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION bool operator>=(const PCE< Storage > &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION PCE< Storage > max(const typename PCE< Storage >::value_type &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION PCE< Storage > cosh(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION bool is_constant(const T &x)
KOKKOS_INLINE_FUNCTION bool operator==(const PCE< Storage > &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION PCE< Storage > abs(const PCE< Storage > &a)
expr1 expr1 expr1 expr2 expr1 expr1 c expr2 expr1 c fastAccessCoeff(j)-expr2.val(j)
KOKKOS_INLINE_FUNCTION PCE< Storage > atan(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > exp(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< view_type >::value, typename CijkType< view_type >::type >::type cijk(const view_type &view)
expr val()
acosh(expr.val())
KOKKOS_INLINE_FUNCTION PCE< Storage > sin(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > operator+(const PCE< Storage > &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION PCE< Storage > operator*(const PCE< Storage > &a, const PCE< Storage > &b)
KOKKOS_INLINE_FUNCTION PCE< Storage > log(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > log10(const PCE< Storage > &a)
int n
KOKKOS_INLINE_FUNCTION PCE< Storage > asin(const PCE< Storage > &a)
KOKKOS_INLINE_FUNCTION PCE< Storage > cos(const PCE< Storage > &a)
std::enable_if< Kokkos::is_view_uq_pce< Kokkos::View< RD, RP...> >::value &&Kokkos::is_view_uq_pce< Kokkos::View< XD, XP...> >::value >::type sum(const Kokkos::View< RD, RP...> &r, const Kokkos::View< XD, XP...> &x)