1 /*
2 * Copyright (c) 2007, Michael Lehn
3 *
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1) Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * 3) Neither the name of the FLENS development group nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #ifndef FLENS_STORAGE_FULLSTORAGE_CONSTFULLSTORAGEVIEW_H
34 #define FLENS_STORAGE_FULLSTORAGE_CONSTFULLSTORAGEVIEW_H 1
35
36 #include <cxxblas/typedefs.h>
37 #include <flens/typedefs.h>
38 #include <flens/storage/indexoptions.h>
39
40 namespace flens {
41
42 template <typename T, typename I, typename A>
43 class Array;
44
45 template <typename T, typename I, typename A>
46 class ArrayView;
47
48 template <typename T, typename I, typename A>
49 class ConstArrayView;
50
51 template <typename T, StorageOrder Order, typename I, typename A>
52 class FullStorage;
53
54 template <typename T, StorageOrder Order, typename I, typename A>
55 class FullStorageView;
56
57 template <typename T,
58 StorageOrder Order,
59 typename I = IndexOptions<>,
60 typename A = std::allocator<T> >
61 class ConstFullStorageView
62 {
63 public:
64 typedef T ElementType;
65 typedef typename I::IndexType IndexType;
66 typedef A Allocator;
67
68 static const StorageOrder order = Order;
69 static const IndexType defaultIndexBase
70 = I::defaultIndexBase;
71
72 typedef ConstFullStorageView ConstView;
73 typedef FullStorageView<T, Order, I, A> View;
74 typedef FullStorage<T, Order, I, A> NoView;
75
76 typedef flens::ConstArrayView<T, I, A> ConstArrayView;
77 typedef flens::ArrayView<T, I, A> ArrayView;
78 typedef flens::Array<T, I, A> Array;
79
80 ConstFullStorageView(IndexType numRows, IndexType numCols,
81 const ElementType *data,
82 IndexType leadingDimension,
83 IndexType firstRow = I::defaultIndexBase,
84 IndexType firstCol = I::defaultIndexBase,
85 const Allocator &allocator = Allocator());
86
87 template <typename ARRAY>
88 ConstFullStorageView(IndexType numRows, IndexType numCols,
89 ARRAY &array,
90 IndexType leadingDimension,
91 IndexType firstRow = I::defaultIndexBase,
92 IndexType firstCol = I::defaultIndexBase,
93 const Allocator &allocator = Allocator());
94
95 ConstFullStorageView(const ConstFullStorageView &rhs);
96
97 template <typename RHS>
98 ConstFullStorageView(const RHS &rhs);
99
100 ~ConstFullStorageView();
101
102 //-- operators ---------------------------------------------------------
103
104 const ElementType &
105 operator()(IndexType row, IndexType col) const;
106
107 //-- methods -----------------------------------------------------------
108
109 IndexType
110 firstRow() const;
111
112 IndexType
113 lastRow() const;
114
115 IndexType
116 firstCol() const;
117
118 IndexType
119 lastCol() const;
120
121 IndexType
122 numRows() const;
123
124 IndexType
125 numCols() const;
126
127 IndexType
128 leadingDimension() const;
129
130 IndexType
131 strideRow() const;
132
133 IndexType
134 strideCol() const;
135
136 const ElementType *
137 data() const;
138
139 const Allocator &
140 allocator() const;
141
142 void
143 changeIndexBase(IndexType firstRow, IndexType firstCol);
144
145 // view of fullstorage scheme as an array
146 const ConstArrayView
147 arrayView(IndexType firstViewIndex = I::defaultIndexBase) const;
148
149 // view of rectangular part
150 const ConstFullStorageView
151 view(IndexType fromRow, IndexType fromCol,
152 IndexType toRow, IndexType toCol,
153 IndexType firstViewRow = I::defaultIndexBase,
154 IndexType firstViewCol = I::defaultIndexBase) const;
155
156 // view of single row
157 const ConstArrayView
158 viewRow(IndexType row,
159 IndexType firstViewIndex = I::defaultIndexBase) const;
160
161 const ConstArrayView
162 viewRow(IndexType row,
163 IndexType firstCol, IndexType lastCol,
164 IndexType firstViewIndex = I::defaultIndexBase) const;
165
166 // view of single column
167 const ConstArrayView
168 viewCol(IndexType col,
169 IndexType firstViewIndex = I::defaultIndexBase) const;
170
171 const ConstArrayView
172 viewCol(IndexType firstRow, IndexType lastRow,
173 IndexType col,
174 IndexType firstViewIndex = I::defaultIndexBase) const;
175
176 // view of d-th diagonal
177 const ConstArrayView
178 viewDiag(IndexType d,
179 IndexType firstViewIndex = I::defaultIndexBase) const;
180
181 private:
182 const ElementType *_data;
183 Allocator _allocator;
184 IndexType _numRows, _numCols;
185 IndexType _leadingDimension;
186 IndexType _firstRow, _firstCol;
187 };
188
189 } // namespace flens
190
191 #endif // FLENS_STORAGE_FULLSTORAGE_CONSTFULLSTORAGEVIEW_H
2 * Copyright (c) 2007, Michael Lehn
3 *
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1) Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * 3) Neither the name of the FLENS development group nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #ifndef FLENS_STORAGE_FULLSTORAGE_CONSTFULLSTORAGEVIEW_H
34 #define FLENS_STORAGE_FULLSTORAGE_CONSTFULLSTORAGEVIEW_H 1
35
36 #include <cxxblas/typedefs.h>
37 #include <flens/typedefs.h>
38 #include <flens/storage/indexoptions.h>
39
40 namespace flens {
41
42 template <typename T, typename I, typename A>
43 class Array;
44
45 template <typename T, typename I, typename A>
46 class ArrayView;
47
48 template <typename T, typename I, typename A>
49 class ConstArrayView;
50
51 template <typename T, StorageOrder Order, typename I, typename A>
52 class FullStorage;
53
54 template <typename T, StorageOrder Order, typename I, typename A>
55 class FullStorageView;
56
57 template <typename T,
58 StorageOrder Order,
59 typename I = IndexOptions<>,
60 typename A = std::allocator<T> >
61 class ConstFullStorageView
62 {
63 public:
64 typedef T ElementType;
65 typedef typename I::IndexType IndexType;
66 typedef A Allocator;
67
68 static const StorageOrder order = Order;
69 static const IndexType defaultIndexBase
70 = I::defaultIndexBase;
71
72 typedef ConstFullStorageView ConstView;
73 typedef FullStorageView<T, Order, I, A> View;
74 typedef FullStorage<T, Order, I, A> NoView;
75
76 typedef flens::ConstArrayView<T, I, A> ConstArrayView;
77 typedef flens::ArrayView<T, I, A> ArrayView;
78 typedef flens::Array<T, I, A> Array;
79
80 ConstFullStorageView(IndexType numRows, IndexType numCols,
81 const ElementType *data,
82 IndexType leadingDimension,
83 IndexType firstRow = I::defaultIndexBase,
84 IndexType firstCol = I::defaultIndexBase,
85 const Allocator &allocator = Allocator());
86
87 template <typename ARRAY>
88 ConstFullStorageView(IndexType numRows, IndexType numCols,
89 ARRAY &array,
90 IndexType leadingDimension,
91 IndexType firstRow = I::defaultIndexBase,
92 IndexType firstCol = I::defaultIndexBase,
93 const Allocator &allocator = Allocator());
94
95 ConstFullStorageView(const ConstFullStorageView &rhs);
96
97 template <typename RHS>
98 ConstFullStorageView(const RHS &rhs);
99
100 ~ConstFullStorageView();
101
102 //-- operators ---------------------------------------------------------
103
104 const ElementType &
105 operator()(IndexType row, IndexType col) const;
106
107 //-- methods -----------------------------------------------------------
108
109 IndexType
110 firstRow() const;
111
112 IndexType
113 lastRow() const;
114
115 IndexType
116 firstCol() const;
117
118 IndexType
119 lastCol() const;
120
121 IndexType
122 numRows() const;
123
124 IndexType
125 numCols() const;
126
127 IndexType
128 leadingDimension() const;
129
130 IndexType
131 strideRow() const;
132
133 IndexType
134 strideCol() const;
135
136 const ElementType *
137 data() const;
138
139 const Allocator &
140 allocator() const;
141
142 void
143 changeIndexBase(IndexType firstRow, IndexType firstCol);
144
145 // view of fullstorage scheme as an array
146 const ConstArrayView
147 arrayView(IndexType firstViewIndex = I::defaultIndexBase) const;
148
149 // view of rectangular part
150 const ConstFullStorageView
151 view(IndexType fromRow, IndexType fromCol,
152 IndexType toRow, IndexType toCol,
153 IndexType firstViewRow = I::defaultIndexBase,
154 IndexType firstViewCol = I::defaultIndexBase) const;
155
156 // view of single row
157 const ConstArrayView
158 viewRow(IndexType row,
159 IndexType firstViewIndex = I::defaultIndexBase) const;
160
161 const ConstArrayView
162 viewRow(IndexType row,
163 IndexType firstCol, IndexType lastCol,
164 IndexType firstViewIndex = I::defaultIndexBase) const;
165
166 // view of single column
167 const ConstArrayView
168 viewCol(IndexType col,
169 IndexType firstViewIndex = I::defaultIndexBase) const;
170
171 const ConstArrayView
172 viewCol(IndexType firstRow, IndexType lastRow,
173 IndexType col,
174 IndexType firstViewIndex = I::defaultIndexBase) const;
175
176 // view of d-th diagonal
177 const ConstArrayView
178 viewDiag(IndexType d,
179 IndexType firstViewIndex = I::defaultIndexBase) const;
180
181 private:
182 const ElementType *_data;
183 Allocator _allocator;
184 IndexType _numRows, _numCols;
185 IndexType _leadingDimension;
186 IndexType _firstRow, _firstCol;
187 };
188
189 } // namespace flens
190
191 #endif // FLENS_STORAGE_FULLSTORAGE_CONSTFULLSTORAGEVIEW_H