File: factory.cpp

package info (click to toggle)
dynare 4.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 40,640 kB
  • sloc: fortran: 82,231; cpp: 72,734; ansic: 28,874; pascal: 13,241; sh: 4,300; objc: 3,281; yacc: 2,833; makefile: 1,288; lex: 1,162; python: 162; lisp: 54; xml: 8
file content (49 lines) | stat: -rw-r--r-- 846 bytes parent folder | download | duplicates (5)
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
/* $Id: factory.cpp 148 2005-04-19 15:12:26Z kamenik $ */
/* Copyright 2004, Ondra Kamenik */

#include "factory.h"

#include <cstdlib>
#include <cmath>

void Factory::init(const Symmetry& s, const IntSequence& nvs)
{
	IntSequence sym(s);
	long int seed = sym[0];
	seed = 256*seed + nvs[0];
	if (sym.size() > 1)
		seed = 256*seed + sym[1];
	if (nvs.size() > 1)
		seed = 256*seed + nvs[0];
	srand48(seed);
}

void Factory::init(int dim, int nv)
{
	long int seed = dim;
	seed = 256*seed + nv;
	srand48(seed);
}

double Factory::get() const
{
	return 1.0*(drand48()-0.5);
}

void Factory::fillMatrix(TwoDMatrix& m) const
{
	Vector& d = m.getData();
	for (int i = 0; i < d.length(); i++)
		d[i] = get();
}

Vector* Factory::makeVector(int n)
{
	init(n, n*n);

	Vector* v = new Vector(n);
	for (int i = 0; i < n; i++)
		(*v)[i] = get();

	return v;
}