CUSP
Loading...
Searching...
No Matches
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
30namespace cusp
31{
32
33// forward definition
34template <typename ArrayType, typename IndexType, typename MemorySpace> class permutation_matrix_view;
35
107template <typename IndexType, typename MemorySpace>
108class permutation_matrix : public cusp::detail::matrix_base<IndexType,IndexType,MemorySpace,cusp::permutation_format>
109{
110private:
111
112 typedef cusp::detail::matrix_base<IndexType,IndexType,MemorySpace,cusp::permutation_format> Parent;
113
114public:
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>
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
185
192 template<typename MatrixType>
193 void symmetric_permute(MatrixType& matrix);
194}; // class permutation_matrix
273template <typename ArrayType,
274 typename IndexType = typename ArrayType::value_type,
275 typename MemorySpace = typename ArrayType::memory_space>
276class permutation_matrix_view : public cusp::detail::matrix_base<IndexType,IndexType,MemorySpace,cusp::permutation_format>
277{
278private:
279
280 typedef cusp::detail::matrix_base<IndexType,IndexType,MemorySpace,cusp::permutation_format> Parent;
281
282public:
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),
310
317 permutation_matrix_view(const size_t num_rows, const ArrayType& permutation)
318 : Parent(num_rows, num_rows, num_rows),
320
328
336
344
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
379template <typename ArrayType>
381make_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
401template <typename ArrayType, typename IndexType, typename MemorySpace>
402permutation_matrix_view<ArrayType,IndexType,MemorySpace>
407
419template <typename IndexType, class MemorySpace>
420typename permutation_matrix<IndexType,MemorySpace>::view
425
437template <typename IndexType, class MemorySpace>
438typename permutation_matrix<IndexType,MemorySpace>::const_view
446} // end namespace cusp
447
448#include <cusp/detail/permutation_matrix.inl>
1D 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
Specialized array1d_view wrapping thrust::counting_iterator.
Definition array1d.h:566
View of a permutation_matrix.
permutation_matrix_view(permutation_matrix_view< ArrayType > &matrix)
void resize(const size_t num_rows)
permutation_matrix_view(const size_t num_rows, ArrayType &permutation)
permutation_array_type permutation
permutation_matrix_view(const size_t num_rows, const ArrayType &permutation)
permutation_matrix_view(const permutation_matrix_view< ArrayType > &matrix)
void symmetric_permute(MatrixType &matrix)
permutation_matrix_view(permutation_matrix< IndexType, MemorySpace > &matrix)
permutation_matrix_view(const permutation_matrix< IndexType, MemorySpace > &matrix)
Simple representation a permutation matrix.
void resize(const size_t num_rows)
void swap(permutation_matrix &matrix)
permutation_array_type permutation
permutation_matrix(const permutation_matrix< IndexType, MemorySpace2 > &matrix)
permutation_matrix(const size_t num_rows)
void symmetric_permute(MatrixType &matrix)
permutation_matrix(const size_t num_rows, const ArrayType &permutation)
array1d_view< Iterator > make_array1d_view(Iterator first, Iterator last)
Definition array1d.h:695
permutation_matrix_view< ArrayType > make_permutation_matrix_view(size_t num_rows, ArrayType permutation)