1 | #include <itpp/itbase.h> |
---|
2 | #include "libBM.h" |
---|
3 | #include "itpp_ext.h" |
---|
4 | |
---|
5 | using namespace itpp; |
---|
6 | |
---|
7 | using std::cout; |
---|
8 | |
---|
9 | void RV::init( ivec in_ids, Array<std::string> in_names, ivec in_sizes, ivec in_times, ivec in_obs ) { |
---|
10 | // |
---|
11 | len = in_ids.length(); |
---|
12 | //PRUDENT_MODE |
---|
13 | // All vetors should be of same length |
---|
14 | if ( ( len != in_ids.length() ) || \ |
---|
15 | ( len != in_names.length() ) || \ |
---|
16 | ( len != in_sizes.length() ) || \ |
---|
17 | ( len != in_times.length() ) || \ |
---|
18 | ( len != in_obs.length() ) ) { |
---|
19 | it_error( "RV::RV inconsistent length of input vectors." ); |
---|
20 | } |
---|
21 | |
---|
22 | ids = in_ids; |
---|
23 | names = in_names; |
---|
24 | sizes = in_sizes; |
---|
25 | times = in_times; |
---|
26 | obs = in_obs; |
---|
27 | }; |
---|
28 | |
---|
29 | RV::RV ( ivec in_ids, Array<std::string> in_names, ivec in_sizes, ivec in_times, ivec in_obs ) { |
---|
30 | init ( in_ids, in_names, in_sizes, in_times, in_obs ); |
---|
31 | } |
---|
32 | |
---|
33 | RV::RV () {}; |
---|
34 | |
---|
35 | inline int RV::length () {return len;}; |
---|
36 | |
---|
37 | RV::RV ( ivec in_ids ) { |
---|
38 | |
---|
39 | len = in_ids.length(); |
---|
40 | Array<std::string> A( len ); |
---|
41 | std::string rvstr = "rv"; |
---|
42 | |
---|
43 | for ( int i = 0; i < len;i++ ) { |
---|
44 | A( i ) = rvstr + to_str(i); |
---|
45 | } |
---|
46 | |
---|
47 | init ( in_ids, A, ones_i( len ), zeros_i( len ), zeros_i( len ) ); |
---|
48 | } |
---|
49 | |
---|
50 | RV RV::rvsubselect(ivec ind){ |
---|
51 | return RV(ids(ind), names(to_Arr(ind)), sizes(ind), times(ind), obs(ind)); |
---|
52 | } |
---|
53 | |
---|
54 | void RV::t(int delta){ times +=delta;} |
---|
55 | |
---|
56 | RV RV::operator()(ivec ind){ |
---|
57 | return RV(ids(ind), names(to_Arr(ind)), sizes(ind), times(ind), obs(ind)); |
---|
58 | } |
---|
59 | |
---|
60 | std::ostream &operator<<( std::ostream &os, const RV &rv ) { |
---|
61 | |
---|
62 | for ( int i = 0; i < rv.len ;i++ ) { |
---|
63 | os << rv.ids( i ) << "(" << rv.sizes( i ) << ")" << // id(size)= |
---|
64 | "=" << rv.names( i ) << "_{" << rv.times( i ) << "}; "; //name_{time} |
---|
65 | } |
---|
66 | return os; |
---|
67 | } |
---|