CUSP
Loading...
Searching...
No Matches
dia_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/array2d.h>
27#include <cusp/detail/format.h>
28#include <cusp/detail/matrix_base.h>
29#include <cusp/detail/utils.h>
30#include <cusp/detail/type_traits.h>
31
32namespace cusp
33{
34
35// Forward definitions
36template <typename ArrayType1, typename ArrayType2, typename IndexType, typename ValueType, typename MemorySpace> class dia_matrix_view;
37
119template <typename IndexType, typename ValueType, class MemorySpace>
120class dia_matrix : public cusp::detail::matrix_base<IndexType,ValueType,MemorySpace,cusp::dia_format>
121{
122private:
123
124 typedef cusp::detail::matrix_base<IndexType,ValueType,MemorySpace,cusp::dia_format> Parent;
125
126public:
127 // TODO statically assert is_signed<IndexType>
128
130 typedef cusp::array1d<IndexType, MemorySpace> diagonal_offsets_array_type;
132
134
135 typedef cusp::dia_matrix_view<
136 typename diagonal_offsets_array_type::view,
137 typename values_array_type::view,
138 IndexType, ValueType, MemorySpace> view;
139
140 typedef cusp::dia_matrix_view<
141 typename diagonal_offsets_array_type::const_view,
142 typename values_array_type::const_view,
143 IndexType, ValueType, MemorySpace> const_view;
144
145 typedef typename cusp::detail::coo_view_type<diagonal_offsets_array_type,
146 diagonal_offsets_array_type,
147 typename values_array_type::values_array_type,
148 cusp::dia_format>::view coo_view_type;
149 // TODO : Why does GCC 4.4 fail using const type? Is it necessary?
150 typedef typename cusp::detail::coo_view_type<diagonal_offsets_array_type,
151 diagonal_offsets_array_type,
152 typename values_array_type::values_array_type,
153 cusp::dia_format>::view const_coo_view_type;
154
155 template<typename MemorySpace2>
156 struct rebind
157 {
159 };
164 diagonal_offsets_array_type diagonal_offsets;
165
168 values_array_type values;
169
173 dia_matrix(void) {}
174
184 dia_matrix(const size_t num_rows, const size_t num_cols, const size_t num_entries,
185 const size_t num_diagonals, const size_t alignment = 32);
186
191 template <typename MatrixType>
192 dia_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_diagonals);
203
212 void resize(const size_t num_rows, const size_t num_cols, const size_t num_entries,
213 const size_t num_diagonals, const size_t alignment);
214
219 void swap(dia_matrix& matrix);
220
225 template <typename MatrixType>
226 dia_matrix& operator=(const MatrixType& matrix);
227}; // class dia_matrix
322template <typename ArrayType1,
323 typename ArrayType2,
324 typename IndexType = typename ArrayType1::value_type,
325 typename ValueType = typename ArrayType2::value_type,
326 typename MemorySpace = typename cusp::minimum_space<typename ArrayType1::memory_space, typename ArrayType2::memory_space>::type >
327class dia_matrix_view : public cusp::detail::matrix_base<IndexType,ValueType,MemorySpace,cusp::dia_format>
328{
329private:
330
331 typedef cusp::detail::matrix_base<IndexType,ValueType,MemorySpace,cusp::dia_format> Parent;
332
333public:
335 typedef ArrayType1 diagonal_offsets_array_type;
336 typedef ArrayType2 values_array_type;
340
341 typedef typename cusp::detail::coo_view_type<diagonal_offsets_array_type,
342 diagonal_offsets_array_type,
343 typename values_array_type::values_array_type,
344 cusp::dia_format>::view coo_view_type;
345 // TODO : Why does GCC 4.4 fail using const type? Is it necessary?
346 typedef typename cusp::detail::coo_view_type<diagonal_offsets_array_type,
347 diagonal_offsets_array_type,
348 typename values_array_type::values_array_type,
349 cusp::dia_format>::view const_coo_view_type;
355 diagonal_offsets_array_type diagonal_offsets;
356
360 values_array_type values;
361
366
376 template <typename OtherArrayType1, typename OtherArrayType2>
377 dia_matrix_view(size_t num_rows, size_t num_cols, size_t num_entries,
378 OtherArrayType1& diagonal_offsets, OtherArrayType2& values)
379 : Parent(num_rows, num_cols, num_entries),
381 values(values) {}
382
392 template <typename OtherArrayType1, typename OtherArrayType2>
393 dia_matrix_view(size_t num_rows, size_t num_cols, size_t num_entries,
394 const OtherArrayType1& diagonal_offsets, const OtherArrayType2& values)
395 : Parent(num_rows, num_cols, num_entries),
397 values(values) {}
398
407
416
422 : Parent(matrix),
424 values(matrix.values) {}
425
431 : Parent(matrix),
433 values(matrix.values) {}
434
442 void resize(const size_t num_rows, const size_t num_cols, const size_t num_entries,
443 const size_t num_diagonals);
444
453 void resize(const size_t num_rows, const size_t num_cols, const size_t num_entries,
454 const size_t num_diagonals, const size_t alignment);
455}; // class dia_matrix_view
456
457/* Convenience functions */
458
473template <typename ArrayType1,
474 typename ArrayType2>
476make_dia_matrix_view(size_t num_rows,
477 size_t num_cols,
478 size_t num_entries,
479 ArrayType1 diagonal_offsets,
480 ArrayType2 values)
481{
483 view(num_rows, num_cols, num_entries, diagonal_offsets, values);
484
485 return view;
486}
487
503template <typename ArrayType1,
504 typename ArrayType2,
505 typename IndexType,
506 typename ValueType,
507 typename MemorySpace>
508dia_matrix_view<ArrayType1,ArrayType2,IndexType,ValueType,MemorySpace>
513
526template <typename IndexType, typename ValueType, class MemorySpace>
527typename dia_matrix<IndexType,ValueType,MemorySpace>::view
535
548template <typename IndexType, typename ValueType, class MemorySpace>
549typename dia_matrix<IndexType,ValueType,MemorySpace>::const_view
557
561} // end namespace cusp
562
563#include <cusp/detail/dia_matrix.inl>
1D array of elements that may reside in "host" or "device" memory space
2D array of elements that may reside in "host" or "device" memory space
The array1d class is a 1D vector container that may contain elements stored in "host" or "device" mem...
Definition array1d.h:99
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 dia_matrix.
Definition dia_matrix.h:328
dia_matrix_view(dia_matrix< IndexType, ValueType, MemorySpace > &matrix)
Definition dia_matrix.h:403
void resize(const size_t num_rows, const size_t num_cols, const size_t num_entries, const size_t num_diagonals, const size_t alignment)
values_array_type values
Definition dia_matrix.h:360
dia_matrix_view(const dia_matrix< IndexType, ValueType, MemorySpace > &matrix)
Definition dia_matrix.h:412
dia_matrix_view(size_t num_rows, size_t num_cols, size_t num_entries, OtherArrayType1 &diagonal_offsets, OtherArrayType2 &values)
Definition dia_matrix.h:377
dia_matrix_view(const dia_matrix_view &matrix)
Definition dia_matrix.h:430
void resize(const size_t num_rows, const size_t num_cols, const size_t num_entries, const size_t num_diagonals)
dia_matrix_view(size_t num_rows, size_t num_cols, size_t num_entries, const OtherArrayType1 &diagonal_offsets, const OtherArrayType2 &values)
Definition dia_matrix.h:393
dia_matrix_view(dia_matrix_view &matrix)
Definition dia_matrix.h:421
diagonal_offsets_array_type diagonal_offsets
Definition dia_matrix.h:355
Diagonal (DIA) representation a sparse matrix.
Definition dia_matrix.h:121
void resize(const size_t num_rows, const size_t num_cols, const size_t num_entries, const size_t num_diagonals, const size_t alignment)
diagonal_offsets_array_type diagonal_offsets
Definition dia_matrix.h:164
void resize(const size_t num_rows, const size_t num_cols, const size_t num_entries, const size_t num_diagonals)
dia_matrix(const MatrixType &matrix)
void swap(dia_matrix &matrix)
values_array_type values
Definition dia_matrix.h:168
dia_matrix & operator=(const MatrixType &matrix)
dia_matrix(const size_t num_rows, const size_t num_cols, const size_t num_entries, const size_t num_diagonals, const size_t alignment=32)
array1d_view< Iterator > make_array1d_view(Iterator first, Iterator last)
Definition array1d.h:695
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
dia_matrix_view< ArrayType1, ArrayType2 > make_dia_matrix_view(size_t num_rows, size_t num_cols, size_t num_entries, ArrayType1 diagonal_offsets, ArrayType2 values)
Definition dia_matrix.h:476