Fork me on GitHub
 All Classes Files Functions Variables Groups Pages
permutation_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 #include <cusp/detail/format.h>
25 #include <cusp/detail/matrix_base.h>
26 
27 #include <cusp/array1d.h>
28 #include <cusp/memory.h>
29 
30 namespace cusp
31 {
32 
33 // forward definition
34 template <typename ArrayType, typename IndexType, typename MemorySpace> class permutation_matrix_view;
35 
107 template <typename IndexType, typename MemorySpace>
108 class permutation_matrix : public cusp::detail::matrix_base<IndexType,IndexType,MemorySpace,cusp::permutation_format>
109 {
110 private:
111 
112  typedef cusp::detail::matrix_base<IndexType,IndexType,MemorySpace,cusp::permutation_format> Parent;
113 
114 public:
115 
117  typedef typename cusp::array1d<IndexType, MemorySpace> permutation_array_type;
118 
119  typedef typename cusp::permutation_matrix<IndexType, MemorySpace> container;
120 
121  typedef typename cusp::permutation_matrix_view<
122  typename permutation_array_type::view,
123  IndexType,
124  MemorySpace> view;
125 
126  typedef typename cusp::permutation_matrix_view<
127  typename permutation_array_type::const_view,
128  IndexType,
129  MemorySpace> const_view;
130 
131  template<typename MemorySpace2>
132  struct rebind {
134  };
139  permutation_array_type permutation;
140 
144 
149  permutation_matrix(const size_t num_rows)
150  : Parent(num_rows, num_rows, num_rows),
151  permutation(cusp::counting_array<int>(num_rows)) {}
152 
159  template<typename MemorySpace2>
161  : Parent(matrix), permutation(matrix.permutation) {}
162 
170  template<typename ArrayType>
171  permutation_matrix(const size_t num_rows, const ArrayType& permutation)
172  : Parent(num_rows, num_rows, num_rows), permutation(permutation) {}
173 
178  void resize(const size_t num_rows);
179 
184  void swap(permutation_matrix& matrix);
185 
192  template<typename MatrixType>
193  void symmetric_permute(MatrixType& matrix);
194 }; // class permutation_matrix
273 template <typename ArrayType,
274  typename IndexType = typename ArrayType::value_type,
275  typename MemorySpace = typename ArrayType::memory_space>
276 class permutation_matrix_view : public cusp::detail::matrix_base<IndexType,IndexType,MemorySpace,cusp::permutation_format>
277 {
278 private:
279 
280  typedef cusp::detail::matrix_base<IndexType,IndexType,MemorySpace,cusp::permutation_format> Parent;
281 
282 public:
283 
285  typedef ArrayType permutation_array_type;
286 
287  typedef typename cusp::permutation_matrix<IndexType, MemorySpace> container;
288 
294  permutation_array_type permutation;
295 
299  : Parent() {}
300 
307  permutation_matrix_view(const size_t num_rows, ArrayType& permutation)
308  : Parent(num_rows, num_rows, num_rows),
309  permutation(permutation) {}
310 
317  permutation_matrix_view(const size_t num_rows, const ArrayType& permutation)
318  : Parent(num_rows, num_rows, num_rows),
319  permutation(permutation) {}
320 
325  permutation_matrix_view(permutation_matrix<IndexType,MemorySpace>& matrix)
326  : Parent(matrix),
327  permutation(matrix.permutation) {}
328 
333  permutation_matrix_view(const permutation_matrix<IndexType,MemorySpace>& matrix)
334  : Parent(matrix),
335  permutation(matrix.permutation) {}
336 
341  permutation_matrix_view(permutation_matrix_view<ArrayType>& matrix)
342  : Parent(matrix),
343  permutation(matrix.permutation) {}
344 
349  permutation_matrix_view(const permutation_matrix_view<ArrayType>& matrix)
350  : Parent(matrix),
351  permutation(matrix.permutation) {}
352 
357  void resize(const size_t num_rows);
358 
363  template<typename MatrixType>
364  void symmetric_permute(MatrixType& matrix);
365 };
366 
367 /* Convenience functions */
368 
379 template <typename ArrayType>
381 make_permutation_matrix_view(size_t num_rows, ArrayType permutation)
382 {
383  permutation_matrix_view<ArrayType> view(num_rows, permutation);
384 
385  return view;
386 }
387 
401 template <typename ArrayType, typename IndexType, typename MemorySpace>
404 {
406 }
407 
419 template <typename IndexType, class MemorySpace>
422 {
424 }
425 
437 template <typename IndexType, class MemorySpace>
440 {
442 }
446 } // end namespace cusp
447 
448 #include <cusp/detail/permutation_matrix.inl>
The array1d class is a 1D vector container that may contain elements stored in "host" or "device" mem...
Definition: array1d.h:98
permutation_matrix(const permutation_matrix< IndexType, MemorySpace2 > &matrix)
void resize(const size_t num_rows)
void swap(permutation_matrix &matrix)
permutation_matrix(const size_t num_rows, const ArrayType &permutation)
void symmetric_permute(MatrixType &matrix)
void symmetric_permute(MatrixType &matrix)
array1d_view< Iterator > make_array1d_view(Iterator first, Iterator last)
Definition: array1d.h:693
permutation_matrix(const size_t num_rows)
void resize(const size_t num_rows)
View of a permutation_matrix.
Simple representation a permutation matrix.
1D array of elements that may reside in "host" or "device" memory space
permutation_array_type permutation
Specialized array1d_view wrapping thrust::counting_iterator.
Definition: array1d.h:562
permutation_matrix< IndexType, MemorySpace >::const_view make_permutation_matrix_view(const permutation_matrix< IndexType, MemorySpace > &m)
permutation_array_type permutation