File: smat_meal_passrng_hpp.h

package info (click to toggle)
r-cran-pcapp 1.9-73-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 800 kB
  • sloc: cpp: 5,961; ansic: 917; sh: 13; makefile: 2
file content (65 lines) | stat: -rw-r--r-- 1,534 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef SMAT_MEAL_PASSRNG_HPP
#define SMAT_MEAL_PASSRNG_HPP

#ifndef SMAT_MEAL_H
	#error "File 'smat.meal.h' not included. Please include before including 'smat_meal_passrng.hpp'."
#endif

#ifndef SMAT_MEAL_PASSRNG_H
	#error "File 'smat_meal_passrng.h' not included. Please include before including 'smat_meal_passrng.hpp'."
#endif

//	when including this files make sure, that "smat_meal_passrng.h" and "smat.meal.h" has been included first!

	CPassRng::CPassRng ()
		: m_pCurData (NULL)
		, m_pDataEnd (NULL)
	{

	}

	double CPassRng::Get ()
	{
		THROW (m_pCurData < m_pDataEnd) ;
		return *(m_pCurData++) ;
	}

	void CPassRng::Set (double *pData, t_size n)
	{
		m_data.Require (n) ;
		m_data.Copy (pData, n) ;

		m_pCurData = m_data ;
		m_pDataEnd = m_data.GetDataEnd () ;
	}

	CPassRng &GetPassRng_runif ()
	{
		static CPassRng obj ;
		return obj ;
	}

	CPassRng &GetPassRng_rnorm ()
	{
		static CPassRng obj ;
		return obj ;
	}

	CPassRng &GetPassRng_rexp ()
	{
		static CPassRng obj ;
		return obj ;
	}

	void pass_runif (double *pd, int n) { GetPassRng_runif ().Set (pd, n) ; }
	void pass_rnorm (double *pd, int n) { GetPassRng_rnorm ().Set (pd, n) ;	}
	void pass_rexp  (double *pd, int n) { GetPassRng_rexp  ().Set (pd, n) ;	}

	void meal_PutRNGstate () {}
	void meal_GetRNGstate () {}

	double meal_unif_rand () { return GetPassRng_runif ().Get () ; }
	double meal_norm_rand () { return GetPassRng_rnorm ().Get () ; }
	double meal_exp_rand  () { return GetPassRng_rexp  ().Get () ; }

#endif	//	#ifndef SMAT_MEAL_PASSRNG_HPP