Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Kokkos_MV_MP_Vector.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 KOKKOS_MV_MP_VECTOR_HPP
11 #define KOKKOS_MV_MP_VECTOR_HPP
12 
13 #include "Sacado_MP_Vector.hpp"
17 
18 //----------------------------------------------------------------------------
19 // Specializations of Kokkos Vector/MultiVector math functions
20 //----------------------------------------------------------------------------
21 /*
22 namespace Kokkos {
23 
24 // Rank-1 vector add with Sacado::MP::Vector scalar type, constant a, b
25 template <typename RS, typename RL, typename RD, typename RM,
26  typename XS, typename XL, typename XD, typename XM,
27  typename YS, typename YL, typename YD, typename YM>
28 Kokkos::View< Sacado::MP::Vector<RS>*, RL, RD, RM>
29 V_Add( const Kokkos::View< Sacado::MP::Vector<RS>*, RL, RD, RM >& r,
30  const typename Sacado::MP::Vector<XS>::value_type& av,
31  const Kokkos::View< Sacado::MP::Vector<XS>*, XL, XD, XM >& x,
32  const typename Sacado::MP::Vector<XS>::value_type& bv,
33  const Kokkos::View< Sacado::MP::Vector<YS>*, YL, YD, YM >& y,
34  int n = -1)
35 {
36  typedef Kokkos::View< Sacado::MP::Vector<RS>*, RL, RD, RM > RVector;
37  typedef Kokkos::View< Sacado::MP::Vector<XS>*, XL, XD, XM > XVector;
38  typedef Kokkos::View< Sacado::MP::Vector<YS>*, YL, YD, YM > YVector;
39 
40  typename RVector::flat_array_type r_flat = r;
41  typename XVector::flat_array_type x_flat = x;
42  typename YVector::flat_array_type y_flat = y;
43  if (n != -1) n = n * r.sacado_size();
44 
45  V_Add( r_flat, av, x_flat, bv, y_flat, n );
46 
47  return r;
48 }
49 
50 // Rank-1 vector add with Sacado::MP::Vector scalar type, non-constant a, b
51 template <typename RS, typename RL, typename RD, typename RM,
52  typename XS, typename XL, typename XD, typename XM,
53  typename YS, typename YL, typename YD, typename YM>
54 Kokkos::View< Sacado::MP::Vector<RS>*, RL, RD, RM>
55 V_Add( const Kokkos::View< Sacado::MP::Vector<RS>*, RL, RD, RM >& r,
56  const Sacado::MP::Vector<XS>& av,
57  const Kokkos::View< Sacado::MP::Vector<XS>*, XL, XD, XM >& x,
58  const Sacado::MP::Vector<XS>& bv,
59  const Kokkos::View< Sacado::MP::Vector<YS>*, YL, YD, YM >& y,
60  int n = -1)
61 {
62  if (Sacado::is_constant(av) && Sacado::is_constant(bv)) {
63  return V_Add( r, av.fastAccessCoeff(0), x, bv.fastAccessCoeff(0), y, n );
64  }
65  else {
66  Impl::raise_error("V_Add not implemented for non-constant a or b");
67  }
68  return r;
69 }
70 
71 // Rank-2 vector add with Sacado::MP::Vector scalar type, constant a, b
72 template <typename RS, typename RL, typename RD, typename RM,
73  typename XS, typename XL, typename XD, typename XM,
74  typename YS, typename YL, typename YD, typename YM>
75 Kokkos::View< Sacado::MP::Vector<RS>**, RL, RD, RM>
76 MV_Add( const Kokkos::View< Sacado::MP::Vector<RS>**, RL, RD, RM >& r,
77  const typename Sacado::MP::Vector<XS>::value_type& av,
78  const Kokkos::View< Sacado::MP::Vector<XS>**, XL, XD, XM >& x,
79  const typename Sacado::MP::Vector<XS>::value_type& bv,
80  const Kokkos::View< Sacado::MP::Vector<YS>**, YL, YD, YM >& y,
81  int n = -1)
82 {
83  typedef Kokkos::View< Sacado::MP::Vector<RS>**, RL, RD, RM > RVector;
84  typedef Kokkos::View< Sacado::MP::Vector<XS>**, XL, XD, XM > XVector;
85  typedef Kokkos::View< Sacado::MP::Vector<YS>**, YL, YD, YM > YVector;
86 
87  typename RVector::flat_array_type r_flat = r;
88  typename XVector::flat_array_type x_flat = x;
89  typename YVector::flat_array_type y_flat = y;
90  if (n != -1) n = n * r.sacado_size();
91 
92  MV_Add( r_flat, av, x_flat, bv, y_flat, n );
93 
94  return r;
95 }
96 
97 // Rank-2 vector add with Sacado::MP::Vector scalar type, non-constant a, b
98 template <typename RS, typename RL, typename RD, typename RM,
99  typename XS, typename XL, typename XD, typename XM,
100  typename YS, typename YL, typename YD, typename YM>
101 Kokkos::View< Sacado::MP::Vector<RS>**, RL, RD, RM>
102 MV_Add( const Kokkos::View< Sacado::MP::Vector<RS>**, RL, RD, RM >& r,
103  const Sacado::MP::Vector<XS>& av,
104  const Kokkos::View< Sacado::MP::Vector<XS>**, XL, XD, XM >& x,
105  const Sacado::MP::Vector<XS>& bv,
106  const Kokkos::View< Sacado::MP::Vector<YS>**, YL, YD, YM >& y,
107  int n = -1)
108 {
109  if (Sacado::is_constant(av) && Sacado::is_constant(bv)) {
110  return MV_Add( r, av.fastAccessCoeff(0), x, bv.fastAccessCoeff(0), y, n );
111  }
112  else {
113  Impl::raise_error("MV_Add not implemented for non-constant a or b");
114  }
115  return r;
116 }
117 
118 // Rank-1 dot product
119 template <typename XS, typename XL, typename XD, typename XM,
120  typename YS, typename YL, typename YD, typename YM>
121 typename Details::InnerProductSpaceTraits< Sacado::MP::Vector<XS> >::dot_type
122 V_Dot( const Kokkos::View< Sacado::MP::Vector<XS>*, XL, XD, XM >& x,
123  const Kokkos::View< Sacado::MP::Vector<YS>*, YL, YD, YM >& y,
124  int n = -1 )
125 {
126  typedef Kokkos::View< Sacado::MP::Vector<XS>*, XL, XD, XM > XVector;
127  typedef Kokkos::View< Sacado::MP::Vector<YS>*, YL, YD, YM > YVector;
128 
129  typename XVector::flat_array_type x_flat = x;
130  typename YVector::flat_array_type y_flat = y;
131  if (n != -1) n = n * x.sacado_size();
132 
133  return V_Dot( x_flat, y_flat, n );
134 }
135 
136 // Rank-2 dot product
137 template <typename rVector,
138  typename XS, typename XL, typename XD, typename XM,
139  typename YS, typename YL, typename YD, typename YM>
140 void
141 MV_Dot( const rVector& r,
142  const Kokkos::View< Sacado::MP::Vector<XS>**, XL, XD, XM >& x,
143  const Kokkos::View< Sacado::MP::Vector<YS>**, YL, YD, YM >& y,
144  int n = -1 )
145 {
146  typedef Kokkos::View< Sacado::MP::Vector<XS>**, XL, XD, XM > XVector;
147  typedef Kokkos::View< Sacado::MP::Vector<YS>**, YL, YD, YM > YVector;
148 
149  typename XVector::flat_array_type x_flat = x;
150  typename YVector::flat_array_type y_flat = y;
151  if (n != -1) n = n * x.sacado_size();
152 
153  MV_Dot( r, x_flat, y_flat, n );
154 }
155 
156 } // namespace Kokkos
157 */
158 #endif /* #ifndef KOKKOS_MV_MP_VECTOR_HPP */