Fork me on GitHub
 All Classes Files Functions Variables Groups Pages
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 
33 namespace cusp
34 {
35 
37 // Forward definitions
38 struct column_major;
39 
40 template<typename,typename,typename> class array2d;
41 template<typename,typename> class array2d_view;
42 template<typename,typename,typename,typename,typename> class ell_matrix_view;
43 
44 template<typename T, class MemorySpace, class Orientation>
45 array2d_view<typename cusp::array1d_view<typename cusp::array1d<T,MemorySpace>::iterator>, Orientation>
47 
48 template<typename T, class MemorySpace, class Orientation>
49 array2d_view<typename cusp::array1d_view<typename cusp::array1d<T,MemorySpace>::const_iterator>, Orientation>
121 template <typename IndexType, typename ValueType, typename MemorySpace>
122 class ell_matrix : public cusp::detail::matrix_base<IndexType,ValueType,MemorySpace,cusp::ell_format>
123 {
124 private:
125 
126  typedef cusp::detail::matrix_base<IndexType,ValueType,MemorySpace,cusp::ell_format> Parent;
127 
128 public:
129 
132  const static IndexType invalid_index = static_cast<IndexType>(-1);
133 
135  typedef typename cusp::array2d<IndexType, MemorySpace, cusp::column_major> column_indices_array_type;
136  typedef typename cusp::array2d<ValueType, MemorySpace, cusp::column_major> values_array_type;
137 
138  typedef typename cusp::ell_matrix<IndexType, ValueType, MemorySpace> container;
139 
140  typedef typename cusp::ell_matrix_view<
141  typename column_indices_array_type::view,
142  typename values_array_type::view,
143  IndexType, ValueType, MemorySpace> view;
144 
145  typedef typename cusp::ell_matrix_view<
146  typename column_indices_array_type::const_view,
147  typename values_array_type::const_view,
148  IndexType, ValueType, MemorySpace> const_view;
149 
150  typedef typename cusp::detail::coo_view_type<container, cusp::ell_format>::view coo_view_type;
151  typedef typename cusp::detail::coo_view_type<container const, cusp::ell_format>::view const_coo_view_type;
152 
153  template<typename MemorySpace2>
154  struct rebind
155  {
157  };
162  column_indices_array_type column_indices;
163 
166  values_array_type values;
167 
170  ell_matrix(void) {}
171 
181  ell_matrix(const size_t num_rows, const size_t num_cols, const size_t num_entries,
182  const size_t num_entries_per_row, const size_t alignment = 32);
183 
188  template <typename MatrixType>
189  ell_matrix(const MatrixType& matrix);
190 
198  void resize(const size_t num_rows, const size_t num_cols, const size_t num_entries,
199  const size_t num_entries_per_row);
200 
209  void resize(const size_t num_rows, const size_t num_cols, const size_t num_entries,
210  const size_t num_entries_per_row, const size_t alignment);
211 
216  void swap(ell_matrix& matrix);
217 
224  template <typename MatrixType>
225  ell_matrix& operator=(const MatrixType& matrix);
226 }; // class ell_matrix
314 template <typename ArrayType1,
315  typename ArrayType2,
316  typename IndexType = typename ArrayType1::value_type,
317  typename ValueType = typename ArrayType2::value_type,
318  typename MemorySpace = typename cusp::minimum_space<typename ArrayType1::memory_space, typename ArrayType2::memory_space>::type >
319 class ell_matrix_view : public cusp::detail::matrix_base<IndexType,ValueType,MemorySpace,cusp::ell_format>
320 {
321 private:
322 
323  typedef cusp::detail::matrix_base<IndexType,ValueType,MemorySpace,cusp::ell_format> Parent;
324 
325 public:
326 
328  typedef ArrayType1 column_indices_array_type;
329  typedef ArrayType2 values_array_type;
330 
334 
335  typedef typename cusp::detail::coo_view_type<view,cusp::ell_format>::view coo_view_type;
336  typedef typename cusp::detail::coo_view_type<view const,cusp::ell_format>::view const_coo_view_type;
342  const static IndexType invalid_index = container::invalid_index;
343 
347  column_indices_array_type column_indices;
348 
352  values_array_type values;
353 
357  ell_matrix_view(void) {}
358 
368  template <typename OtherArrayType1, typename OtherArrayType2>
369  ell_matrix_view(const size_t num_rows, const size_t num_cols, const size_t num_entries,
370  const OtherArrayType1& column_indices, const OtherArrayType2& values)
371  : Parent(num_rows, num_cols, num_entries),
372  column_indices(column_indices),
373  values(values) {}
374 
380  : Parent(matrix),
382  values(make_array2d_view(matrix.values)) {}
383 
388  ell_matrix_view(const ell_matrix<IndexType,ValueType,MemorySpace>& matrix)
389  : Parent(matrix),
391  values(make_array2d_view(matrix.values)) {}
392 
398  : Parent(matrix),
400  values(matrix.values) {}
401 
406  ell_matrix_view(const ell_matrix_view& matrix)
407  : Parent(matrix),
409  values(matrix.values) {}
410 
418  void resize(size_t num_rows, size_t num_cols, size_t num_entries,
419  size_t num_entries_per_row);
420 
429  void resize(size_t num_rows, size_t num_cols, size_t num_entries,
430  size_t num_entries_per_row, size_t alignment);
431 }; // class ell_matrix_view
432 
447 template <typename ArrayType1, typename ArrayType2>
449 make_ell_matrix_view(size_t num_rows, size_t num_cols, size_t num_entries,
450  ArrayType1 column_indices, ArrayType2 values)
451 {
453  view(num_rows, num_cols, num_entries, column_indices, values);
454 
455  return view;
456 }
457 
473 template <typename ArrayType1,
474  typename ArrayType2,
475  typename IndexType,
476  typename ValueType,
477  typename MemorySpace>
480 {
482 }
483 
496 template <typename IndexType, typename ValueType, typename MemorySpace>
499 {
500  return make_ell_matrix_view
501  (m.num_rows, m.num_cols, m.num_entries,
504 }
505 
518 template <typename IndexType, typename ValueType, typename MemorySpace>
521 {
522  return make_ell_matrix_view
523  (m.num_rows, m.num_cols, m.num_entries,
526 }
527 
531 } // end namespace cusp
532 
533 #include <cusp/detail/ell_matrix.inl>
values_array_type values
Definition: ell_matrix.h:351
static const IndexType invalid_index
Definition: ell_matrix.h:341
void resize(const size_t num_rows, const size_t num_cols, const size_t num_entries, const size_t num_entries_per_row)
void swap(ell_matrix &matrix)
column_indices_array_type column_indices
Definition: ell_matrix.h:162
values_array_type values
Definition: ell_matrix.h:166
void resize(size_t num_rows, size_t num_cols, size_t num_entries, size_t num_entries_per_row)
The array2d class is a 2D vector container that may contain elements stored in "host" or "device" mem...
Definition: array2d.h:93
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:458
Packed row (ELLPACK/ITPACK) representation of a sparse matrix.
Definition: ell_matrix.h:122
ell_matrix & operator=(const MatrixType &matrix)
ell_matrix< IndexType, ValueType, MemorySpace >::const_view make_ell_matrix_view(const ell_matrix< IndexType, ValueType, MemorySpace > &m)
Definition: ell_matrix.h:519
static const IndexType invalid_index
Definition: ell_matrix.h:132
View of a ell_matrix.
Definition: ell_matrix.h:318
1D array of elements that may reside in "host" or "device" memory space
column_indices_array_type column_indices
Definition: ell_matrix.h:346