CUSP
Loading...
Searching...
No Matches
hyb_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/detail/format.h>
27#include <cusp/detail/matrix_base.h>
28#include <cusp/detail/type_traits.h>
29
30namespace cusp
31{
32
34// Forward definitions
35template <typename IndexType, typename ValueType, class MemorySpace> class ell_matrix;
36template <typename IndexType, typename ValueType, class MemorySpace> class coo_matrix;
37template <typename MatrixType1, typename MatrixType2, typename IndexType, typename ValueType, class MemorySpace> class hyb_matrix_view;
141template <typename IndexType, typename ValueType, class MemorySpace>
142class hyb_matrix : public cusp::detail::matrix_base<IndexType,ValueType,MemorySpace,cusp::hyb_format>
143{
144private:
145
146 typedef cusp::detail::matrix_base<IndexType,ValueType,MemorySpace,cusp::hyb_format> Parent;
147
148public:
149
153
155
156 typedef typename cusp::hyb_matrix_view<
159 IndexType, ValueType, MemorySpace> view;
160
161 typedef typename cusp::hyb_matrix_view<
164 IndexType, ValueType, MemorySpace> const_view;
165
166 typedef typename cusp::detail::coo_view_type<typename coo_matrix_type::row_indices_array_type,
167 typename coo_matrix_type::column_indices_array_type,
168 typename coo_matrix_type::values_array_type,
169 cusp::hyb_format>::view coo_view_type;
170 typedef typename cusp::detail::coo_view_type<typename coo_matrix_type::row_indices_array_type,
171 typename coo_matrix_type::column_indices_array_type,
172 typename coo_matrix_type::values_array_type,
173 cusp::hyb_format>::view const_coo_view_type;
174
175 template<typename MemorySpace2>
176 struct rebind
177 {
179 };
184 ell_matrix_type ell;
185
188 coo_matrix_type coo;
189
192 hyb_matrix(void) {}
193
203 hyb_matrix(IndexType num_rows, IndexType num_cols,
204 IndexType num_ell_entries, IndexType num_coo_entries,
205 IndexType num_entries_per_row, IndexType alignment = 32)
206 : Parent(num_rows, num_cols, num_ell_entries + num_coo_entries),
207 ell(num_rows, num_cols, num_ell_entries, num_entries_per_row, alignment),
208 coo(num_rows, num_cols, num_coo_entries) {}
209
210 // TODO remove default alignment of 32
211
216 template <typename MatrixType>
217 hyb_matrix(const MatrixType& matrix);
218
221 void resize(IndexType num_rows, IndexType num_cols,
222 IndexType num_ell_entries, IndexType num_coo_entries,
223 IndexType num_entries_per_row, IndexType alignment = 32)
224 {
225 Parent::resize(num_rows, num_cols, num_ell_entries + num_coo_entries);
226 ell.resize(num_rows, num_cols, num_ell_entries, num_entries_per_row, alignment);
227 coo.resize(num_rows, num_cols, num_coo_entries);
228 }
229
234 void swap(hyb_matrix& matrix)
235 {
236 Parent::swap(matrix);
237 ell.swap(matrix.ell);
238 coo.swap(matrix.coo);
239 }
240
245 template <typename MatrixType>
246 hyb_matrix& operator=(const MatrixType& matrix);
247
248}; // class hyb_matrix
343template <typename MatrixType1,
344 typename MatrixType2,
345 typename IndexType = typename MatrixType1::index_type,
346 typename ValueType = typename MatrixType1::value_type,
347 typename MemorySpace = typename cusp::minimum_space<typename MatrixType1::memory_space, typename MatrixType2::memory_space>::type >
348class hyb_matrix_view : public cusp::detail::matrix_base<IndexType,ValueType,MemorySpace,cusp::hyb_format>
349{
350private:
351
352 typedef cusp::detail::matrix_base<IndexType,ValueType,MemorySpace,cusp::hyb_format> Parent;
353
354public:
355
357 typedef MatrixType1 ell_matrix_type;
358 typedef MatrixType2 coo_matrix_type;
359
363
364 typedef typename cusp::detail::coo_view_type<typename coo_matrix_type::row_indices_array_type,
365 typename coo_matrix_type::column_indices_array_type,
366 typename coo_matrix_type::values_array_type,
367 cusp::hyb_format>::view coo_view_type;
368 typedef typename cusp::detail::coo_view_type<typename coo_matrix_type::row_indices_array_type,
369 typename coo_matrix_type::column_indices_array_type,
370 typename coo_matrix_type::values_array_type,
371 cusp::hyb_format>::view const_coo_view_type;
376 ell_matrix_type ell;
377
380 coo_matrix_type coo;
381
385
395 template <typename OtherMatrixType1, typename OtherMatrixType2>
396 hyb_matrix_view(OtherMatrixType1& ell, OtherMatrixType2& coo)
397 : Parent(ell.num_rows, ell.num_cols, ell.num_entries + coo.num_entries), ell(ell), coo(coo) {}
398
408 template <typename OtherMatrixType1, typename OtherMatrixType2>
409 hyb_matrix_view(const OtherMatrixType1& ell, const OtherMatrixType2& coo)
410 : Parent(ell.num_rows, ell.num_cols, ell.num_entries + coo.num_entries), ell(ell), coo(coo) {}
411
417 : Parent(matrix), ell(matrix.ell), coo(matrix.coo) {}
418
424 : Parent(matrix), ell(matrix.ell), coo(matrix.coo) {}
425
431 : Parent(matrix), ell(matrix.ell), coo(matrix.coo) {}
432
438 : Parent(matrix), ell(matrix.ell), coo(matrix.coo) {}
439
449 void resize(size_t num_rows, size_t num_cols,
450 size_t num_ell_entries, size_t num_coo_entries,
451 size_t num_entries_per_row, size_t alignment = 32);
452};
456} // end namespace cusp
457
458#include <cusp/detail/hyb_matrix.inl>
1D array of elements that may reside in "host" or "device" memory space
Coordinate (COO) representation a sparse matrix.
Definition coo_matrix.h:117
Packed row (ELLPACK/ITPACK) representation of a sparse matrix.
Definition ell_matrix.h:120
View of a hyb_matrix.
Definition hyb_matrix.h:349
ell_matrix_type ell
Definition hyb_matrix.h:376
void resize(size_t num_rows, size_t num_cols, size_t num_ell_entries, size_t num_coo_entries, size_t num_entries_per_row, size_t alignment=32)
hyb_matrix_view(const hyb_matrix_view &matrix)
Definition hyb_matrix.h:437
hyb_matrix_view(hyb_matrix< IndexType, ValueType, MemorySpace > &matrix)
Definition hyb_matrix.h:416
hyb_matrix_view(const hyb_matrix< IndexType, ValueType, MemorySpace > &matrix)
Definition hyb_matrix.h:423
coo_matrix_type coo
Definition hyb_matrix.h:380
hyb_matrix_view(hyb_matrix_view &matrix)
Definition hyb_matrix.h:430
hyb_matrix_view(const OtherMatrixType1 &ell, const OtherMatrixType2 &coo)
Definition hyb_matrix.h:409
hyb_matrix_view(OtherMatrixType1 &ell, OtherMatrixType2 &coo)
Definition hyb_matrix.h:396
Hybrid (HYB) representation a sparse matrix.
Definition hyb_matrix.h:143
hyb_matrix(const MatrixType &matrix)
ell_matrix_type ell
Definition hyb_matrix.h:184
hyb_matrix & operator=(const MatrixType &matrix)
void swap(hyb_matrix &matrix)
Definition hyb_matrix.h:234
coo_matrix_type coo
Definition hyb_matrix.h:188
hyb_matrix(IndexType num_rows, IndexType num_cols, IndexType num_ell_entries, IndexType num_coo_entries, IndexType num_entries_per_row, IndexType alignment=32)
Definition hyb_matrix.h:203
void resize(IndexType num_rows, IndexType num_cols, IndexType num_ell_entries, IndexType num_coo_entries, IndexType num_entries_per_row, IndexType alignment=32)
Definition hyb_matrix.h:221