CUSP
Loading...
Searching...
No Matches
ell_matrix.h
Go to the documentation of this file.
1/*
2 * Copyright 2008-2014 NVIDIA Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
21#pragma once
22
23#include <cusp/detail/config.h>
24
25#include <cusp/array1d.h>
26#include <cusp/memory.h>
27
28#include <cusp/detail/format.h>
29#include <cusp/detail/matrix_base.h>
30#include <cusp/detail/type_traits.h>
31#include <cusp/detail/utils.h>
32
33namespace cusp
34{
35
37template<typename,typename,typename> class array2d;
38template<typename,typename> class array2d_view;
39template<typename,typename,typename,typename,typename> class ell_matrix_view;
40
41template<typename T, class MemorySpace, class Orientation>
42array2d_view<typename cusp::array1d_view<typename cusp::array1d<T,MemorySpace>::iterator>, Orientation>
44
45template<typename T, class MemorySpace, class Orientation>
46array2d_view<typename cusp::array1d_view<typename cusp::array1d<T,MemorySpace>::const_iterator>, Orientation>
118template <typename IndexType, typename ValueType, typename MemorySpace>
119class ell_matrix : public cusp::detail::matrix_base<IndexType,ValueType,MemorySpace,cusp::ell_format>
120{
121private:
122
123 typedef cusp::detail::matrix_base<IndexType,ValueType,MemorySpace,cusp::ell_format> Parent;
124
125public:
126
129 const static IndexType invalid_index = static_cast<IndexType>(-1);
130
132 typedef typename cusp::array2d<IndexType, MemorySpace, cusp::column_major> column_indices_array_type;
133 typedef typename cusp::array2d<ValueType, MemorySpace, cusp::column_major> values_array_type;
134
136
137 typedef typename cusp::ell_matrix_view<
138 typename column_indices_array_type::view,
139 typename values_array_type::view,
140 IndexType, ValueType, MemorySpace> view;
141
142 typedef typename cusp::ell_matrix_view<
143 typename column_indices_array_type::const_view,
144 typename values_array_type::const_view,
145 IndexType, ValueType, MemorySpace> const_view;
146
147 typedef typename cusp::detail::coo_view_type<typename column_indices_array_type::values_array_type,
148 typename column_indices_array_type::values_array_type,
149 typename values_array_type::values_array_type,
150 cusp::ell_format>::view coo_view_type;
151 typedef typename cusp::detail::coo_view_type<typename column_indices_array_type::values_array_type,
152 typename column_indices_array_type::values_array_type,
153 typename values_array_type::values_array_type,
154 cusp::ell_format>::view const_coo_view_type;
155
156 template<typename MemorySpace2>
157 struct rebind
158 {
160 };
165 column_indices_array_type column_indices;
166
169 values_array_type values;
170
173 ell_matrix(void) {}
174
184 ell_matrix(const size_t num_rows, const size_t num_cols, const size_t num_entries,
185 const size_t num_entries_per_row, const size_t alignment = 32);
186
191 template <typename MatrixType>
192 ell_matrix(const MatrixType& matrix);
193
201 void resize(const size_t num_rows, const size_t num_cols, const size_t num_entries,
202 const size_t num_entries_per_row);
203
212 void resize(const size_t num_rows, const size_t num_cols, const size_t num_entries,
213 const size_t num_entries_per_row, const size_t alignment);
214
219 void swap(ell_matrix& matrix);
220
227 template <typename MatrixType>
228 ell_matrix& operator=(const MatrixType& matrix);
229}; // class ell_matrix
317template <typename ArrayType1,
318 typename ArrayType2,
319 typename IndexType = typename ArrayType1::value_type,
320 typename ValueType = typename ArrayType2::value_type,
321 typename MemorySpace = typename cusp::minimum_space<typename ArrayType1::memory_space, typename ArrayType2::memory_space>::type >
322class ell_matrix_view : public cusp::detail::matrix_base<IndexType,ValueType,MemorySpace,cusp::ell_format>
323{
324private:
325
326 typedef cusp::detail::matrix_base<IndexType,ValueType,MemorySpace,cusp::ell_format> Parent;
327
328public:
329
331 typedef ArrayType1 column_indices_array_type;
332 typedef ArrayType2 values_array_type;
333
337
338 typedef typename cusp::detail::coo_view_type<typename column_indices_array_type::values_array_type,
339 typename column_indices_array_type::values_array_type,
340 typename values_array_type::values_array_type,
341 cusp::ell_format>::view coo_view_type;
342 typedef typename cusp::detail::coo_view_type<typename column_indices_array_type::values_array_type,
343 typename column_indices_array_type::values_array_type,
344 typename values_array_type::values_array_type,
345 cusp::ell_format>::view const_coo_view_type;
351 const static IndexType invalid_index = container::invalid_index;
352
356 column_indices_array_type column_indices;
357
361 values_array_type values;
362
367
377 template <typename OtherArrayType1, typename OtherArrayType2>
378 ell_matrix_view(const size_t num_rows, const size_t num_cols, const size_t num_entries,
379 const OtherArrayType1& column_indices, const OtherArrayType2& values)
380 : Parent(num_rows, num_cols, num_entries),
382 values(values) {}
383
392
401
407 : Parent(matrix),
409 values(matrix.values) {}
410
416 : Parent(matrix),
418 values(matrix.values) {}
419
427 void resize(size_t num_rows, size_t num_cols, size_t num_entries,
428 size_t num_entries_per_row);
429
438 void resize(size_t num_rows, size_t num_cols, size_t num_entries,
439 size_t num_entries_per_row, size_t alignment);
440}; // class ell_matrix_view
441
456template <typename ArrayType1, typename ArrayType2>
458make_ell_matrix_view(size_t num_rows, size_t num_cols, size_t num_entries,
459 ArrayType1 column_indices, ArrayType2 values)
460{
462 view(num_rows, num_cols, num_entries, column_indices, values);
463
464 return view;
465}
466
482template <typename ArrayType1,
483 typename ArrayType2,
484 typename IndexType,
485 typename ValueType,
486 typename MemorySpace>
487ell_matrix_view<ArrayType1,ArrayType2,IndexType,ValueType,MemorySpace>
492
505template <typename IndexType, typename ValueType, typename MemorySpace>
506typename ell_matrix<IndexType,ValueType,MemorySpace>::view
514
527template <typename IndexType, typename ValueType, typename MemorySpace>
528typename ell_matrix<IndexType,ValueType,MemorySpace>::const_view
536
540} // end namespace cusp
541
542#include <cusp/detail/ell_matrix.inl>
1D array of elements that may reside in "host" or "device" memory space
The array2d class is a 2D vector container that may contain elements stored in "host" or "device" mem...
Definition array2d.h:94
View of a ell_matrix.
Definition ell_matrix.h:323
ell_matrix_view(ell_matrix_view &matrix)
Definition ell_matrix.h:406
void resize(size_t num_rows, size_t num_cols, size_t num_entries, size_t num_entries_per_row, size_t alignment)
ell_matrix_view(const size_t num_rows, const size_t num_cols, const size_t num_entries, const OtherArrayType1 &column_indices, const OtherArrayType2 &values)
Definition ell_matrix.h:378
static const IndexType invalid_index
Definition ell_matrix.h:351
column_indices_array_type column_indices
Definition ell_matrix.h:356
ell_matrix_view(const ell_matrix< IndexType, ValueType, MemorySpace > &matrix)
Definition ell_matrix.h:397
ell_matrix_view(const ell_matrix_view &matrix)
Definition ell_matrix.h:415
void resize(size_t num_rows, size_t num_cols, size_t num_entries, size_t num_entries_per_row)
values_array_type values
Definition ell_matrix.h:361
ell_matrix_view(ell_matrix< IndexType, ValueType, MemorySpace > &matrix)
Definition ell_matrix.h:388
Packed row (ELLPACK/ITPACK) representation of a sparse matrix.
Definition ell_matrix.h:120
static const IndexType invalid_index
Definition ell_matrix.h:129
ell_matrix & operator=(const MatrixType &matrix)
values_array_type values
Definition ell_matrix.h:169
column_indices_array_type column_indices
Definition ell_matrix.h:165
ell_matrix(const MatrixType &matrix)
void resize(const size_t num_rows, const size_t num_cols, const size_t num_entries, const size_t num_entries_per_row, const size_t alignment)
void swap(ell_matrix &matrix)
ell_matrix(const size_t num_rows, const size_t num_cols, const size_t num_entries, const size_t num_entries_per_row, const size_t alignment=32)
void resize(const size_t num_rows, const size_t num_cols, const size_t num_entries, const size_t num_entries_per_row)
array2d_view< typename cusp::array1d_view< Iterator >, Orientation > make_array2d_view(size_t num_rows, size_t num_cols, size_t pitch, const cusp::array1d_view< Iterator > &values, Orientation)
Definition array2d.h:479
ell_matrix_view< ArrayType1, ArrayType2 > make_ell_matrix_view(size_t num_rows, size_t num_cols, size_t num_entries, ArrayType1 column_indices, ArrayType2 values)
Definition ell_matrix.h:458