root/library/bdm/itpp_ext.h @ 1222

Revision 1200, 3.0 kB (checked in by smidl, 14 years ago)

vec ivec conversion

  • Property svn:eol-style set to native
Line 
1//
2// C++ Interface: itpp_ext
3//
4// Description:
5//
6//
7// Author: smidl <smidl@utia.cas.cz>, (C) 2008
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#include <itpp/itbase.h>
13
14#ifndef ITEX_H
15#define ITEX_H
16
17using std::cout;
18using std::endl;
19
20namespace itpp {
21extern vec empty_vec;
22
23Array<int> to_Arr ( const ivec &indices );
24ivec linspace ( int from, int to );
25
26vec get_vec ( const vec &v, const ivec &indexlist );
27
28bvec operator& ( const bvec &a, const bvec &b );
29bvec operator| ( const bvec &a, const bvec &b );
30
31bvec operator> ( const vec &t1, const vec &t2 );
32
33bvec operator< ( const vec &t1, const vec &t2 );
34
35ivec get_from_bvec ( const ivec &v, const bvec &binlist );
36
37vec get_from_ivec ( const ivec &v);
38
39// template<class Num_T>
40// void set_subvector(vec &ov, ivec &iv, const Vec<Num_T> &v);
41
42void set_subvector ( vec &ov, const ivec &iv, const vec &v );
43
44template<class Num_T> inline
45void set_col_part ( mat &M, int c, const Vec<Num_T> &v ) {
46    copy_vector ( v.size(), v._data(), M._data() + c*M.rows() );
47}
48
49static const double inf = std::numeric_limits<double>::infinity();
50
51//#if 0
52/*!
53  \brief Gamma distribution
54  \ingroup randgen
55*/
56class Gamma_RNG {
57public:
58//! constructor. Set lambda.
59    Gamma_RNG ( double a = 1.0, double b = 1.0 );
60    //! Set lambda
61    void setup ( double a0, double b0 ) {
62        alpha = a0;
63        beta = b0;
64    }
65    //! get lambda
66    double get_setup() const;
67    //! Get one sample.
68    double operator() () {
69        return sample();
70    }
71    //! Get a sample vector.
72    vec operator() ( int n );
73    //! Get a sample matrix.
74    mat operator() ( int h, int w );
75protected:
76private:
77    //!
78    double sample();
79    //!
80    double alpha;
81    //!
82    double beta;
83    //!
84    Random_Generator RNG;
85    Normal_RNG NRNG;
86    //! compatibility with R
87    inline double exp_rand() {
88        return -std::log ( RNG.random_01() );
89    }
90    inline double unif_rand() {
91        return RNG.random_01();
92    }
93    inline double norm_rand() {
94        return NRNG.sample();
95    }
96
97};
98bool qr ( const mat &A, mat &R );
99//#endif
100//! reimplementation of matlab num2str
101std::string num2str ( double d );
102
103//! reimplementation of matlabs num2str
104std::string num2str ( int i );
105
106//! implementation of digamma (psi) function
107double psi ( double );
108
109//! implementation of matlab triu function
110void triu ( mat &A );
111
112//! implementation of Mixtools function randun
113//! This function uses Park-Miller linear congruential pseudo-random generator with A=16807 B=0 M=2^31-1
114//!     (it spans all 2^31-1 numbers and has good statistical properties)
115double randun();
116//! implementation of Mixtools function randun
117vec randun ( int n );
118//! implementation of Mixtools function randun
119mat randun ( int n, int m );
120
121//! function returns unique entries in input vector \c in
122ivec unique ( const ivec &in );
123
124//! function returns unique entries of vector \c in that are not present in vector \c base
125ivec unique_complement ( const ivec &in, const ivec &base );
126}
127
128
129#endif //ITEX_H
Note: See TracBrowser for help on using the browser.