Fork me on GitHub
 All Classes Files Functions Variables Groups Pages
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 
30 namespace cusp
31 {
32 
34 // Forward definitions
35 template <typename IndexType, typename ValueType, class MemorySpace> class ell_matrix;
36 template <typename IndexType, typename ValueType, class MemorySpace> class coo_matrix;
37 template <typename MatrixType1, typename MatrixType2, typename IndexType, typename ValueType, class MemorySpace> class hyb_matrix_view;
141 template <typename IndexType, typename ValueType, class MemorySpace>
142 class hyb_matrix : public cusp::detail::matrix_base<IndexType,ValueType,MemorySpace,cusp::hyb_format>
143 {
144 private:
145 
146  typedef cusp::detail::matrix_base<IndexType,ValueType,MemorySpace,cusp::hyb_format> Parent;
147 
148 public:
149 
153 
154  typedef typename cusp::hyb_matrix<IndexType, ValueType, MemorySpace> container;
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<container,cusp::hyb_format>::view coo_view_type;
167  typedef typename cusp::detail::coo_view_type<container const,cusp::hyb_format>::view const_coo_view_type;
168 
169  template<typename MemorySpace2>
170  struct rebind
171  {
173  };
178  ell_matrix_type ell;
179 
182  coo_matrix_type coo;
183 
186  hyb_matrix(void) {}
187 
197  hyb_matrix(IndexType num_rows, IndexType num_cols,
198  IndexType num_ell_entries, IndexType num_coo_entries,
199  IndexType num_entries_per_row, IndexType alignment = 32)
200  : Parent(num_rows, num_cols, num_ell_entries + num_coo_entries),
201  ell(num_rows, num_cols, num_ell_entries, num_entries_per_row, alignment),
202  coo(num_rows, num_cols, num_coo_entries) {}
203 
204  // TODO remove default alignment of 32
205 
210  template <typename MatrixType>
211  hyb_matrix(const MatrixType& matrix);
212 
215  void resize(IndexType num_rows, IndexType num_cols,
216  IndexType num_ell_entries, IndexType num_coo_entries,
217  IndexType num_entries_per_row, IndexType alignment = 32)
218  {
219  Parent::resize(num_rows, num_cols, num_ell_entries + num_coo_entries);
220  ell.resize(num_rows, num_cols, num_ell_entries, num_entries_per_row, alignment);
221  coo.resize(num_rows, num_cols, num_coo_entries);
222  }
223 
228  void swap(hyb_matrix& matrix)
229  {
230  Parent::swap(matrix);
231  ell.swap(matrix.ell);
232  coo.swap(matrix.coo);
233  }
234 
239  template <typename MatrixType>
240  hyb_matrix& operator=(const MatrixType& matrix);
241 
242 }; // class hyb_matrix
337 template <typename MatrixType1,
338  typename MatrixType2,
339  typename IndexType = typename MatrixType1::index_type,
340  typename ValueType = typename MatrixType1::value_type,
341  typename MemorySpace = typename cusp::minimum_space<typename MatrixType1::memory_space, typename MatrixType2::memory_space>::type >
342 class hyb_matrix_view : public cusp::detail::matrix_base<IndexType,ValueType,MemorySpace,cusp::hyb_format>
343 {
344 private:
345 
346  typedef cusp::detail::matrix_base<IndexType,ValueType,MemorySpace,cusp::hyb_format> Parent;
347 
348 public:
349 
351  typedef MatrixType1 ell_matrix_type;
352  typedef MatrixType2 coo_matrix_type;
353 
354  typedef typename cusp::hyb_matrix<IndexType, ValueType, MemorySpace> container;
357 
358  typedef typename cusp::detail::coo_view_type<view,cusp::hyb_format>::view coo_view_type;
359  typedef typename cusp::detail::coo_view_type<view const,cusp::hyb_format>::view const_coo_view_type;
364  ell_matrix_type ell;
365 
368  coo_matrix_type coo;
369 
372  hyb_matrix_view(void) {}
373 
383  template <typename OtherMatrixType1, typename OtherMatrixType2>
384  hyb_matrix_view(OtherMatrixType1& ell, OtherMatrixType2& coo)
385  : Parent(ell.num_rows, ell.num_cols, ell.num_entries + coo.num_entries), ell(ell), coo(coo) {}
386 
396  template <typename OtherMatrixType1, typename OtherMatrixType2>
397  hyb_matrix_view(const OtherMatrixType1& ell, const OtherMatrixType2& coo)
398  : Parent(ell.num_rows, ell.num_cols, ell.num_entries + coo.num_entries), ell(ell), coo(coo) {}
399 
405  : Parent(matrix), ell(matrix.ell), coo(matrix.coo) {}
406 
411  hyb_matrix_view(const hyb_matrix<IndexType,ValueType,MemorySpace>& matrix)
412  : Parent(matrix), ell(matrix.ell), coo(matrix.coo) {}
413 
419  : Parent(matrix), ell(matrix.ell), coo(matrix.coo) {}
420 
425  hyb_matrix_view(const hyb_matrix_view& matrix)
426  : Parent(matrix), ell(matrix.ell), coo(matrix.coo) {}
427 
437  void resize(size_t num_rows, size_t num_cols,
438  size_t num_ell_entries, size_t num_coo_entries,
439  size_t num_entries_per_row, size_t alignment = 32);
440 };
444 } // end namespace cusp
445 
446 #include <cusp/detail/hyb_matrix.inl>
void swap(hyb_matrix &matrix)
Definition: hyb_matrix.h:228
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:215
Hybrid (HYB) representation a sparse matrix.
Definition: hyb_matrix.h:142
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:197
coo_matrix_type coo
Definition: hyb_matrix.h:367
coo_matrix_type coo
Definition: hyb_matrix.h:182
Coordinate (COO) representation a sparse matrix.
Definition: coo_matrix.h:106
View of a hyb_matrix.
Definition: hyb_matrix.h:341
ell_matrix_type ell
Definition: hyb_matrix.h:363
Packed row (ELLPACK/ITPACK) representation of a sparse matrix.
Definition: ell_matrix.h:122
hyb_matrix & operator=(const MatrixType &matrix)
1D array of elements that may reside in "host" or "device" memory space
ell_matrix_type ell
Definition: hyb_matrix.h:178
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)