expression_types.hpp
Go to the documentation of this file.
1/*!
2 * \brief Defines the basic types of CRTP base-classes
3 *
4 * \author O. Krause
5 * \date 2013
6 *
7 *
8 * \par Copyright 1995-2015 Shark Development Team
9 *
10 * <BR><HR>
11 * This file is part of Shark.
12 * <http://image.diku.dk/shark/>
13 *
14 * Shark is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License as published
16 * by the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * Shark is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public License
25 * along with Shark. If not, see <http://www.gnu.org/licenses/>.
26 *
27 */
28#ifndef REMORA_EXPRESSION_TYPE_HPP
29#define REMORA_EXPRESSION_TYPE_HPP
30
31namespace remora{
32
33struct cpu_tag{};
34struct gpu_tag{};
35
36
37/// \brief Base class for Vector Expression models
38///
39/// it does not model the Vector Expression concept but all derived types should.
40/// The class defines a common base type and some common interface for all
41/// statically derived Vector Expression classes.
42/// We implement the casts to the statically derived type.
43template<class V, class Device>
44struct vector_expression {
45 typedef Device device_type;
46 V const& operator()() const {
47 return *static_cast<V const*>(this);
48 }
49
50 V& operator()() {
51 return *static_cast<V*>(this);
52 }
53};
54
55/// \brief Base class for Vector container models
56///
57/// it does not model the Vector concept but all derived types should.
58/// The class defines a common base type and some common interface for all
59/// statically derived Vector classes
60/// We implement the casts to the statically derived type.
61template<class C, class Device>
62struct vector_container:public vector_expression<C, Device> {};
63
64
65/// \brief Base class for Matrix Expression models
66///
67/// it does not model the Matrix Expression concept but all derived types should.
68/// The class defines a common base type and some common interface for all
69/// statically derived Matrix Expression classes
70/// We implement the casts to the statically derived type.
71template<class M, class Device>
72struct matrix_expression{
73 typedef Device device_type;
74
75 M const& operator()() const {
76 return *static_cast<M const*>(this);
77 }
78
79 M& operator()() {
80 return *static_cast<M*>(this);
81 }
82};
83
84/// \brief Base class for expressions of vector sets
85///
86/// The vector set expression type is similar to a matrix type. However it behaves
87/// like a vector of vectors with elements of the vector being vectors. Moreover
88/// all usual vector-space operations can be used . All vectors have the same number of elements
89///
90/// it does not model the Matrix Expression concept but all derived types should.
91/// The class defines a common base type and some common interface for all
92/// statically derived Matrix Expression classes
93/// We implement the casts to the statically derived type.
94template<class E, class Device>
95struct vector_set_expression{
96 typedef Device device_type;
97
98 E const& operator()() const {
99 return *static_cast<E const*>(this);
100 }
101
102 E& operator()() {
103 return *static_cast<E*>(this);
104 }
105};
106
107/// \brief Base class for Matrix container models
108///
109/// it does not model the Matrix concept but all derived types should.
110/// The class defines a common base type and some common interface for all
111/// statically derived Matrix classes
112/// We implement the casts to the statically derived type.
113template<class C, class Device>
114struct matrix_container: public matrix_expression<C, Device> {};
115
116}
117
118#endif