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