Intrepid2
Intrepid2_DataTools.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Intrepid2 Package
4 //
5 // Copyright 2007 NTESS and the Intrepid2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef Intrepid2_DataTools_h
11 #define Intrepid2_DataTools_h
12 
13 #include "Intrepid2_Data.hpp"
14 
20 namespace Intrepid2 {
21 
22 class DataTools
23 {
24 public:
30  template<class Scalar, class DeviceType>
31  static void multiplyByCPWeights(Data<Scalar,DeviceType> &resultMatrixData, const Data<Scalar,DeviceType> &matrixDataIn, const Data<Scalar,DeviceType> &scalarDataIn)
32  {
33  const ordinal_type rank = scalarDataIn.rank();
34  const ordinal_type matrixRank = matrixDataIn.rank();
35  auto extents = scalarDataIn.getExtents();
36  auto variationTypes = scalarDataIn.getVariationTypes();
37  for (int r=rank; r<matrixRank; r++)
38  {
39  extents[r] = matrixDataIn.extent_int(r);
40  variationTypes[r] = CONSTANT;
41  }
42 
43  auto scalarDataInExtended = scalarDataIn.shallowCopy(matrixRank, extents, variationTypes);
44  resultMatrixData.storeInPlaceProduct(matrixDataIn,scalarDataInExtended);
45  }
46 
52  template<class Scalar, class DeviceType>
54  {
55  const ordinal_type rank = scalarDataIn.rank();
56  const ordinal_type matrixRank = matrixDataIn.rank();
57  auto extents = scalarDataIn.getExtents();
58  auto variationTypes = scalarDataIn.getVariationTypes();
59  for (int r=rank; r<matrixRank; r++)
60  {
61  extents[r] = matrixDataIn.extent_int(r);
62  variationTypes[r] = CONSTANT;
63  }
64 
65  auto scalarDataInExtended = scalarDataIn.shallowCopy(matrixRank, extents, variationTypes);
66 
67  auto result = Data<Scalar,DeviceType>::allocateInPlaceCombinationResult(scalarDataInExtended, matrixDataIn);
68 
69  result.storeInPlaceProduct(matrixDataIn,scalarDataInExtended);
70  return result;
71  }
72 
76  template<class Scalar, class DeviceType>
78  {
79  // A direct construction of the transpose could be more efficient, but here we take advantage of existing
80  // implementations within the Data class supporting matrix-matrix multiplication. We construct an identity
81  // matrix, and left-multiply this by the transpose of the input matrix.
82  const ordinal_type rank = matrixDataIn.rank();
83  auto extents = matrixDataIn.getExtents();
84  auto variationTypes = matrixDataIn.getVariationTypes();
85  const auto D1 = extents[rank-2];
86 
87  extents[rank-2] = D1;
88  extents[rank-1] = D1;
89  variationTypes[rank-2] = BLOCK_PLUS_DIAGONAL;
90  variationTypes[rank-1] = BLOCK_PLUS_DIAGONAL;
91 
92  Kokkos::View<Scalar*,DeviceType> identityUnderlyingView("Intrepid2::DataTools::transposeMatrix() - identity view",D1);
93  Kokkos::deep_copy(identityUnderlyingView, 1.0);
94  Data<Scalar,DeviceType> identityData(identityUnderlyingView,extents,variationTypes);
95 
96  auto result = Data<Scalar,DeviceType>::allocateMatMatResult(true, matrixDataIn, false, identityData);
97  result.storeMatMat(true, matrixDataIn, false, identityData);
98 
99  return result;
100  }
101 };
102 }
103 
104 #endif /* Intrepid2_DataTools_h */
static void multiplyByCPWeights(Data< Scalar, DeviceType > &resultMatrixData, const Data< Scalar, DeviceType > &matrixDataIn, const Data< Scalar, DeviceType > &scalarDataIn)
static Data< Scalar, DeviceType > multiplyByCPWeights(const Data< Scalar, DeviceType > &matrixDataIn, const Data< Scalar, DeviceType > &scalarDataIn)
static Data< DataScalar, DeviceType > allocateInPlaceCombinationResult(const Data< DataScalar, DeviceType > &A, const Data< DataScalar, DeviceType > &B)
Defines the Data class, a wrapper around a Kokkos::View that allows data that is constant or repeatin...
KOKKOS_INLINE_FUNCTION Kokkos::Array< int, 7 > getExtents() const
Returns an array containing the logical extents in each dimension.
KOKKOS_INLINE_FUNCTION const Kokkos::Array< DataVariationType, 7 > & getVariationTypes() const
Returns an array with the variation types in each logical dimension.
Data shallowCopy(const int rank, const Kokkos::Array< int, 7 > &extents, const Kokkos::Array< DataVariationType, 7 > &variationTypes) const
Creates a new Data object with the same underlying view, but with the specified logical rank...
static Data< Scalar, DeviceType > transposeMatrix(const Data< Scalar, DeviceType > &matrixDataIn)
void storeInPlaceProduct(const Data< DataScalar, DeviceType > &A, const Data< DataScalar, DeviceType > &B)
stores the in-place (entrywise) product, A .* B, into this container.
KOKKOS_INLINE_FUNCTION unsigned rank() const
Returns the logical rank of the Data container.
KOKKOS_INLINE_FUNCTION int extent_int(const int &r) const
Returns the logical extent in the specified dimension.
static Data< DataScalar, DeviceType > allocateMatMatResult(const bool transposeA, const Data< DataScalar, DeviceType > &A_MatData, const bool transposeB, const Data< DataScalar, DeviceType > &B_MatData)