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_FULLSTORAGEVIEW_H
34 #define FLENS_STORAGE_FULLSTORAGE_FULLSTORAGEVIEW_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 ConstFullStorageView;
56
57 template <typename T,
58 StorageOrder Order,
59 typename I = IndexOptions<>,
60 typename A = std::allocator<T> >
61 class FullStorageView
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<T, Order, I, A> ConstView;
73 typedef FullStorageView 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 FullStorageView(IndexType numRows, IndexType numCols,
81 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 FullStorageView(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 FullStorageView(const FullStorageView &rhs);
96
97 template <typename RHS>
98 FullStorageView(RHS &rhs);
99
100 ~FullStorageView();
101
102 //-- operators ---------------------------------------------------------
103
104 const ElementType &
105 operator()(IndexType row, IndexType col) const;
106
107 ElementType &
108 operator()(IndexType row, IndexType col);
109
110 //-- methods -----------------------------------------------------------
111
112 IndexType
113 firstRow() const;
114
115 IndexType
116 lastRow() const;
117
118 IndexType
119 firstCol() const;
120
121 IndexType
122 lastCol() const;
123
124 IndexType
125 numRows() const;
126
127 IndexType
128 numCols() const;
129
130 IndexType
131 leadingDimension() const;
132
133 IndexType
134 strideRow() const;
135
136 IndexType
137 strideCol() const;
138
139 const ElementType *
140 data() const;
141
142 ElementType *
143 data();
144
145 const Allocator &
146 allocator() const;
147
148 bool
149 resize(IndexType numRows, IndexType numCols,
150 IndexType firstRow = I::defaultIndexBase,
151 IndexType firstCol = I::defaultIndexBase,
152 const ElementType &value = ElementType());
153
154 template <typename FS>
155 bool
156 resize(const FS &rhs, const ElementType &value = ElementType());
157
158 bool
159 fill(const ElementType &value = ElementType(0));
160
161 bool
162 fill(StorageUpLo upLo,
163 const ElementType &value = ElementType(0));
164
165 void
166 changeIndexBase(IndexType firstRow, IndexType firstCol);
167
168 // view of fullstorage scheme as an array
169 const ConstArrayView
170 arrayView(IndexType firstViewIndex = I::defaultIndexBase) const;
171
172 ArrayView
173 arrayView(IndexType firstViewIndex = I::defaultIndexBase);
174
175 // view of rectangular part
176 const ConstView
177 view(IndexType fromRow, IndexType fromCol,
178 IndexType toRow, IndexType toCol,
179 IndexType firstViewRow = I::defaultIndexBase,
180 IndexType firstViewCol = I::defaultIndexBase) const;
181
182 FullStorageView
183 view(IndexType fromRow, IndexType fromCol,
184 IndexType toRow, IndexType toCol,
185 IndexType firstViewRow = I::defaultIndexBase,
186 IndexType firstViewCol = I::defaultIndexBase);
187
188 // view of single row
189 const ConstArrayView
190 viewRow(IndexType row,
191 IndexType firstViewIndex = I::defaultIndexBase) const;
192
193 ArrayView
194 viewRow(IndexType row,
195 IndexType firstViewIndex = I::defaultIndexBase);
196
197 const ConstArrayView
198 viewRow(IndexType row,
199 IndexType firstCol, IndexType lastCol,
200 IndexType firstViewIndex = I::defaultIndexBase) const;
201
202 ArrayView
203 viewRow(IndexType row,
204 IndexType firstCol, IndexType lastCol,
205 IndexType firstViewIndex = I::defaultIndexBase);
206
207 // view of single column
208 const ConstArrayView
209 viewCol(IndexType col,
210 IndexType firstViewIndex = I::defaultIndexBase) const;
211
212 ArrayView
213 viewCol(IndexType col,
214 IndexType firstViewIndex = I::defaultIndexBase);
215
216 const ConstArrayView
217 viewCol(IndexType firstRow, IndexType lastRow,
218 IndexType col,
219 IndexType firstViewIndex = I::defaultIndexBase) const;
220
221 ArrayView
222 viewCol(IndexType firstRow, IndexType lastRow,
223 IndexType col,
224 IndexType firstViewIndex = I::defaultIndexBase);
225
226 // view of d-th diagonal
227 const ConstArrayView
228 viewDiag(IndexType d,
229 IndexType firstViewIndex = I::defaultIndexBase) const;
230
231 ArrayView
232 viewDiag(IndexType d,
233 IndexType firstViewIndex = I::defaultIndexBase);
234
235 private:
236 ElementType *_data;
237 Allocator _allocator;
238 IndexType _numRows, _numCols;
239 IndexType _leadingDimension;
240 IndexType _firstRow, _firstCol;
241 };
242
243 } // namespace flens
244
245 #endif // FLENS_STORAGE_FULLSTORAGE_FULLSTORAGEVIEW_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_FULLSTORAGEVIEW_H
34 #define FLENS_STORAGE_FULLSTORAGE_FULLSTORAGEVIEW_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 ConstFullStorageView;
56
57 template <typename T,
58 StorageOrder Order,
59 typename I = IndexOptions<>,
60 typename A = std::allocator<T> >
61 class FullStorageView
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<T, Order, I, A> ConstView;
73 typedef FullStorageView 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 FullStorageView(IndexType numRows, IndexType numCols,
81 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 FullStorageView(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 FullStorageView(const FullStorageView &rhs);
96
97 template <typename RHS>
98 FullStorageView(RHS &rhs);
99
100 ~FullStorageView();
101
102 //-- operators ---------------------------------------------------------
103
104 const ElementType &
105 operator()(IndexType row, IndexType col) const;
106
107 ElementType &
108 operator()(IndexType row, IndexType col);
109
110 //-- methods -----------------------------------------------------------
111
112 IndexType
113 firstRow() const;
114
115 IndexType
116 lastRow() const;
117
118 IndexType
119 firstCol() const;
120
121 IndexType
122 lastCol() const;
123
124 IndexType
125 numRows() const;
126
127 IndexType
128 numCols() const;
129
130 IndexType
131 leadingDimension() const;
132
133 IndexType
134 strideRow() const;
135
136 IndexType
137 strideCol() const;
138
139 const ElementType *
140 data() const;
141
142 ElementType *
143 data();
144
145 const Allocator &
146 allocator() const;
147
148 bool
149 resize(IndexType numRows, IndexType numCols,
150 IndexType firstRow = I::defaultIndexBase,
151 IndexType firstCol = I::defaultIndexBase,
152 const ElementType &value = ElementType());
153
154 template <typename FS>
155 bool
156 resize(const FS &rhs, const ElementType &value = ElementType());
157
158 bool
159 fill(const ElementType &value = ElementType(0));
160
161 bool
162 fill(StorageUpLo upLo,
163 const ElementType &value = ElementType(0));
164
165 void
166 changeIndexBase(IndexType firstRow, IndexType firstCol);
167
168 // view of fullstorage scheme as an array
169 const ConstArrayView
170 arrayView(IndexType firstViewIndex = I::defaultIndexBase) const;
171
172 ArrayView
173 arrayView(IndexType firstViewIndex = I::defaultIndexBase);
174
175 // view of rectangular part
176 const ConstView
177 view(IndexType fromRow, IndexType fromCol,
178 IndexType toRow, IndexType toCol,
179 IndexType firstViewRow = I::defaultIndexBase,
180 IndexType firstViewCol = I::defaultIndexBase) const;
181
182 FullStorageView
183 view(IndexType fromRow, IndexType fromCol,
184 IndexType toRow, IndexType toCol,
185 IndexType firstViewRow = I::defaultIndexBase,
186 IndexType firstViewCol = I::defaultIndexBase);
187
188 // view of single row
189 const ConstArrayView
190 viewRow(IndexType row,
191 IndexType firstViewIndex = I::defaultIndexBase) const;
192
193 ArrayView
194 viewRow(IndexType row,
195 IndexType firstViewIndex = I::defaultIndexBase);
196
197 const ConstArrayView
198 viewRow(IndexType row,
199 IndexType firstCol, IndexType lastCol,
200 IndexType firstViewIndex = I::defaultIndexBase) const;
201
202 ArrayView
203 viewRow(IndexType row,
204 IndexType firstCol, IndexType lastCol,
205 IndexType firstViewIndex = I::defaultIndexBase);
206
207 // view of single column
208 const ConstArrayView
209 viewCol(IndexType col,
210 IndexType firstViewIndex = I::defaultIndexBase) const;
211
212 ArrayView
213 viewCol(IndexType col,
214 IndexType firstViewIndex = I::defaultIndexBase);
215
216 const ConstArrayView
217 viewCol(IndexType firstRow, IndexType lastRow,
218 IndexType col,
219 IndexType firstViewIndex = I::defaultIndexBase) const;
220
221 ArrayView
222 viewCol(IndexType firstRow, IndexType lastRow,
223 IndexType col,
224 IndexType firstViewIndex = I::defaultIndexBase);
225
226 // view of d-th diagonal
227 const ConstArrayView
228 viewDiag(IndexType d,
229 IndexType firstViewIndex = I::defaultIndexBase) const;
230
231 ArrayView
232 viewDiag(IndexType d,
233 IndexType firstViewIndex = I::defaultIndexBase);
234
235 private:
236 ElementType *_data;
237 Allocator _allocator;
238 IndexType _numRows, _numCols;
239 IndexType _leadingDimension;
240 IndexType _firstRow, _firstCol;
241 };
242
243 } // namespace flens
244
245 #endif // FLENS_STORAGE_FULLSTORAGE_FULLSTORAGEVIEW_H