root/bdm/stat/libBM.cpp @ 14

Revision 14, 1.6 kB (checked in by smidl, 16 years ago)

restructuring

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        int i;
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;
28        size = 0;
29        for(i=0;i<len;i++){size+=sizes(i);}
30};
31
32RV::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}
35
36RV::RV () {};
37
38RV::RV ( ivec in_ids ) {
39       
40        len = in_ids.length();
41        Array<std::string> A( len );
42        std::string rvstr = "rv";
43
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 ) );
49}
50
51RV RV::subselect(ivec ind){
52        return RV(ids(ind), names(to_Arr(ind)), sizes(ind), times(ind), obs(ind));
53}
54
55void RV::t(int delta){ times +=delta;}
56
57RV RV::operator()(ivec ind){
58        return RV(ids(ind), names(to_Arr(ind)), sizes(ind), times(ind), obs(ind));
59}
60
61std::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}
Note: See TracBrowser for help on using the browser.