Discontinuous Galerkin Library
#include "dg/algorithm.h"
densematrix.h
Go to the documentation of this file.
1#pragma once
2#include <vector>
3#include "predicate.h"
4
5namespace dg
6{
8
15template<class ContainerType>
16struct DenseMatrix
17{
18 using container_type = ContainerType;
19 DenseMatrix() = default;
20 DenseMatrix( const std::vector<const ContainerType*>& columns) :
21 m_matrix( columns), m_num_cols(columns.size()) {}
22 DenseMatrix( const std::vector<const ContainerType*>& columns, unsigned num_cols) :
23 m_matrix( columns), m_num_cols(num_cols) {}
24
25 unsigned num_cols() const{
26 return m_num_cols;
27 }
28 const ContainerType * operator[] ( unsigned idx) const
29 {
30 return m_matrix[idx];
31 }
32 const std::vector<const ContainerType*>& get() const{ return m_matrix;}
33
34 private:
35 const std::vector<const ContainerType*>& m_matrix;
36 unsigned m_num_cols;
37};
38template <class Container>
39struct TensorTraits<DenseMatrix<Container> >
40{
41 using value_type = get_value_type<Container>;
42 using execution_policy = get_execution_policy<Container>;
43 using tensor_category = DenseMatrixTag;
44};
45
47
69template<class ContainerType>
70auto asDenseMatrix( const std::vector<const ContainerType*>& in)
71{
72 return DenseMatrix<ContainerType>(in);
73}
78template<class ContainerType>
79auto asDenseMatrix( const std::vector<const ContainerType*>& in, unsigned size)
80{
81 return DenseMatrix<ContainerType>(in, size);
82}
83
99template<class ContainerType>
100std::vector<const ContainerType*> asPointers( const std::vector<ContainerType>& in)
101{
102 std::vector<const ContainerType*> ptrs( in.size(), nullptr);
103 for( unsigned i=0; i<ptrs.size(); i++)
104 ptrs[i] = &in[i];
105 return ptrs;
106}
107
108} // namespace dg
std::vector< const ContainerType * > asPointers(const std::vector< ContainerType > &in)
Convert a vector of vectors to a vector of pointers.
Definition: densematrix.h:100
auto asDenseMatrix(const std::vector< const ContainerType * > &in)
Lightweight DenseMatrix for dg::blas2::gemv.
Definition: densematrix.h:70
This is the namespace for all functions and classes defined and used by the discontinuous Galerkin li...
NoPolicyTag execution_policy
Definition: tensor_traits.h:34
NotATensorTag tensor_category
Definition: tensor_traits.h:33
void value_type
Definition: tensor_traits.h:32