File: factory.cpp

package info (click to toggle)
dynare 4.5.7-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 49,408 kB
  • sloc: cpp: 84,998; ansic: 29,058; pascal: 13,843; sh: 4,833; objc: 4,236; yacc: 3,622; makefile: 2,278; lex: 1,541; python: 236; lisp: 69; 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;
}