1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//! Display data from a matrix oracle.
use Itertools;
use MatrixOracle;
/// Print one row of the matrix (represented as a vector of entries) for each item in the iterator.
///
/// # Example
///
/// ```
/// // import the relevant crates
/// use oat_rust::algebra::matrices::types::vec_of_vec::sorted::VecOfVec; // a particular type of sparse matrix
/// use oat_rust::algebra::matrices::query::MatrixOracle; // the trait for looking up rows and columns
/// use oat_rust::algebra::matrices::display::print_indexed_rows;
///
/// // define sparse version of the following matrix
/// // 0 5 5
/// // 0 0 7
/// let matrix = VecOfVec::new( vec![ vec![ (1,5), (2,5) ], vec![ (2,7) ] ] ).ok().unwrap();
///
/// // define an iterator that runs over the row indices (i.e. the row indices)
/// let iter_row_index = 0..2;
///
/// // print the rows specified by the iterator. this should show the following:
/// // $ row 0: [(1, 5), (2, 5)]
/// // $ row 1: [(2, 7)]
/// print_indexed_rows( &&matrix, iter_row_index ); // we pass `&&matrix` because `&matrix` implements the oracle trait and we have to pass a *reference* to something that implements the oracle trait
/// ```
/// Print one column of the matrix (represented as a vector of entries) for each item in the iterator.
///
/// # Example
///
/// ```
/// // import the relevant crates
/// use oat_rust::algebra::matrices::types::vec_of_vec::sorted::VecOfVec; // a particular type of sparse matrix
/// use oat_rust::algebra::matrices::query::MatrixOracle; // the trait for looking up rows and columns
/// use oat_rust::algebra::matrices::display::print_indexed_columns;
///
/// // define sparse version of the following matrix
/// // 0 5 5
/// // 0 0 7
/// let matrix = VecOfVec::new( vec![ vec![ (1,5), (2,5) ], vec![ (2,7) ] ] ).ok().unwrap();
///
/// // define an iterator that runs over the column indices (i.e. the row indices)
/// let iter_column_index = 0..3;
///
/// // print the columns specified by the iterator. this should show the following:
/// // $ column 0: []
/// // $ column 1: [(0, 5)]
/// // $ column 2: [(1, 5), (2, 7)]
/// print_indexed_columns( &&matrix, iter_column_index ); // we pass `&&matrix` because `&matrix` implements the oracle trait and we have to pass a *reference* to something that implements the oracle trait
/// ```