root/libBM.cpp @ 5

Revision 5, 1.5 kB (checked in by smidl, 16 years ago)

RV

Line 
1#include <itpp/itbase.h>
2#include "libBM.h"
3#include "itpp_ext.h"
4
5using namespace itpp;
6
7using std::cout;
8
9void 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
29RV::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
33RV::RV ( ivec in_ids ) {
34       
35        len = in_ids.length();
36        Array<std::string> A( len );
37        std::string rvstr = "rv";
38
39        for ( int i = 0; i < len;i++ ) {
40                A( i ) = rvstr + to_str(i);
41        }
42
43        init ( in_ids, A, ones_i( len ), zeros_i( len ), zeros_i( len ) );
44}
45
46RV RV::rvsubselect(ivec ind){
47        return RV(ids(ind), names(to_Arr(ind)), sizes(ind), times(ind), obs(ind));
48}
49
50RV RV::operator()(ivec ind){
51        return RV(ids(ind), names(to_Arr(ind)), sizes(ind), times(ind), obs(ind));
52}
53
54std::ostream &operator<<( std::ostream &os, const RV &rv ) {
55
56        for ( int i = 0; i < rv.len ;i++ ) {
57                os << rv.ids( i ) << "(" << rv.sizes( i ) << ")" <<  // id(size)=
58                "=" << rv.names( i )  << "_{"  << rv.times( i ) << "}; "; //name_{time}
59        }
60        return os;
61}
Note: See TracBrowser for help on using the browser.