1
#ifndef YASMIC_MATRIX_ROW_COL_GRAPH
2
#define YASMIC_MATRIX_ROW_COL_GRAPH
5
* @file matrix_row_col_graph.hpp
8
* A row and column graph filter for a matrix.
10
* Regardless of the input, the output is just a nonzero-matrix.
12
* The row and column graph of a matrix has a vertex for each row and column
13
* and an edge where A(i,j) != 0. The weight on the edge is A(i,j).
15
* The first m vertices correspond to the row vertices, the next
16
* n vertices correspond to the columns.
18
* We just wrap the original dataset and forward calls.
19
* (This does not make a copy of the original matrix!)
27
template <class Matrix>
28
struct matrix_row_col_graph_nz_iter_help
31
typedef typename smatrix_traits<Matrix>::index_type index_type;
32
typedef typename smatrix_traits<Matrix>::value_type value_type;
34
typedef boost::tuple<index_type, index_type, value_type> nz_type;
37
// implement the "repeating" iterator
38
template <class Matrix>
39
class matrix_row_col_graph_nz_iterator
40
: public boost::iterator_facade<
41
matrix_row_col_graph_nz_iterator<Matrix>,
42
typename matrix_row_col_graph_nz_iter_help<Matrix>::nz_type const,
43
boost::forward_traversal_tag,
44
typename matrix_row_col_graph_nz_iter_help<Matrix>::nz_type const >
48
matrix_row_col_graph_nz_iterator()
49
: _m(NULL), _repeat(true), _nr(0)
52
matrix_row_col_graph_nz_iterator(Matrix& m)
53
: _m(&m), _repeat(true), _nr(nrows(m))
55
i = nonzeros(m).first;
58
matrix_row_col_graph_nz_iterator(Matrix& m,bool)
59
: _m(&m), _repeat(true), _nr(nrows(m))
61
i = nonzeros(m).second;
66
friend class boost::iterator_core_access;
81
bool equal(matrix_row_col_graph_nz_iterator const& other) const
83
return (i == other.i && _repeat == other._repeat);
86
typename matrix_row_col_graph_nz_iter_help<Matrix>::nz_type
91
return boost::make_tuple(
92
row(*i, *_m),column(*i, *_m)+_nr,value(*i,*_m));
96
return boost::make_tuple(
97
column(*i, *_m)+_nr,row(*i, *_m),value(*i,*_m));
105
typename smatrix_traits<Matrix>::nonzero_iterator i;
106
typename smatrix_traits<Matrix>::index_type _nr;
110
} /* end namespace yasmic::impl */
113
template <class Matrix>
114
class matrix_row_col_graph
119
matrix_row_col_graph(Matrix& m)
123
typedef typename smatrix_traits<Matrix>::index_type index_type;
124
typedef typename smatrix_traits<Matrix>::value_type value_type;
126
typedef typename boost::tuple<index_type, index_type, value_type> nonzero_descriptor;
127
typedef impl::matrix_row_col_graph_nz_iterator<Matrix> nonzero_iterator;
129
typedef void row_iterator;
130
typedef void row_nonzero_descriptor;
131
typedef void row_nonzero_iterator;
133
typedef void column_iterator;
135
typedef typename smatrix_traits<Matrix>::size_type size_type;
136
typedef typename smatrix_traits<Matrix>::nz_index_type nz_index_type;
137
typedef typename smatrix_traits<Matrix>::properties properties;
142
template <class Matrix>
143
struct matrix_row_col_graph_help
145
typedef smatrix_traits<matrix_row_col_graph<Matrix> > traits;
147
typedef std::pair<typename traits::size_type, typename traits::size_type> dims_ret_type;
148
typedef std::pair<typename traits::nonzero_iterator, typename traits::nonzero_iterator> nzs_ret_type;
149
typedef typename traits::size_type nnz_ret_type;
154
template <class Matrix>
155
inline typename impl::matrix_row_col_graph_help<Matrix>::nnz_ret_type
156
nnz(matrix_row_col_graph<Matrix>& tm)
161
template <class Matrix>
162
inline typename impl::matrix_row_col_graph_help<Matrix>::dims_ret_type
163
dimensions(matrix_row_col_graph<Matrix>& tm)
165
typename impl::transpose_matrix_help<Matrix>::dims_ret_type d = dimensions(tm._m);
166
return (std::make_pair(d.second + d.first, d.second + d.first));
169
template <class Matrix>
170
inline typename impl::matrix_row_col_graph_help<Matrix>::nzs_ret_type
171
nonzeros(matrix_row_col_graph<Matrix>& tm)
174
return std::make_pair( impl::matrix_row_col_graph_nz_iterator<Matrix>(tm._m),
175
impl::matrix_row_col_graph_nz_iterator<Matrix>(tm._m,true));
178
} // namespace yasmic
180
#endif // YASMIC_MATRIX_ROW_COL_GRAPH