File: KronVector.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 (109 lines) | stat: -rw-r--r-- 2,752 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* $Header: /var/lib/cvs/dynare_cpp/sylv/cc/KronVector.cpp,v 1.1.1.1 2004/06/04 13:00:31 kamenik Exp $ */

/* Tag $Name:  $ */

#include "KronVector.h"
#include "SylvException.h"

int power(int m, int depth)
{
	int p = 1;
	for (int i = 0; i < depth; i++) {
		p *= m;
	}
	return p;
}

KronVector::KronVector(int mm, int nn, int dp)
	: Vector(power(mm,dp)*nn), m(mm), n(nn), depth(dp)
{}

KronVector::KronVector(Vector& v, int mm, int nn, int dp)
	: Vector(v), m(mm), n(nn), depth(dp)
{
	len = power(m,depth)*n;
	if (v.length() != length()) {
		throw SYLV_MES_EXCEPTION("Bad conversion KronVector from Vector.");
	}
}

KronVector::KronVector(KronVector& v, int i)
	: Vector(v, i*power(v.m,v.depth-1)*v.n, power(v.m, v.depth-1)*v.n), m(v.m), n(v.n),
	  depth(v.depth-1)
{
	if (depth < 0) {
		throw SYLV_MES_EXCEPTION("Bad KronVector pick, depth < 0.");
	}
}

KronVector::KronVector(const ConstKronVector& v)
	: Vector(v.length()), m(v.getM()), n(v.getN()), depth(v.getDepth())
{
	Vector::operator=(v);
}

const KronVector& KronVector::operator=(const ConstKronVector& v)
{
	Vector::operator=(v);
	m=v.getM();
	n=v.getN();
	depth = v.getDepth();
	return *this;
}

const KronVector& KronVector::operator=(const Vector& v)
{
	if (length() != v.length()) {
		throw SYLV_MES_EXCEPTION("Wrong lengths for vector operator =.");
	}
	Vector::operator=(v);
	return *this;
}



ConstKronVector::ConstKronVector(const KronVector& v)
	: ConstVector(v), m(v.getM()), n(v.getN()), depth(v.getDepth())
{}

ConstKronVector::ConstKronVector(const ConstKronVector& v)
	: ConstVector(power(v.getM(),v.getDepth())*v.getN()), m(v.getM()), n(v.getN()),
	  depth(v.getDepth())	  
{}

ConstKronVector::ConstKronVector(const Vector& v, int mm, int nn, int dp)
	: ConstVector(v), m(mm), n(nn), depth(dp)
{
	len = power(m,depth)*n;
	if (v.length() != length()) {
		throw SYLV_MES_EXCEPTION("Bad conversion KronVector from Vector.");
	}
}

ConstKronVector::ConstKronVector(const ConstVector& v, int mm, int nn, int dp)
	: ConstVector(v), m(mm), n(nn), depth(dp)
{
	len = power(m,depth)*n;
	if (v.length() != length()) {
		throw SYLV_MES_EXCEPTION("Bad conversion KronVector from Vector.");
	}
}

ConstKronVector::ConstKronVector(const KronVector& v, int i)
	: ConstVector(v, i*power(v.getM(),v.getDepth()-1)*v.getN(),
				  power(v.getM(),v.getDepth()-1)*v.getN()),
	  m(v.getM()), n(v.getN()), depth(v.getDepth()-1)
{
	if (depth < 0) {
		throw SYLV_MES_EXCEPTION("Bad KronVector pick, depth < 0.");
	}
}

ConstKronVector::ConstKronVector(const ConstKronVector& v, int i)
	: ConstVector(v, i*power(v.m,v.depth-1)*v.n, power(v.m,v.depth-1)*v.n),
	  m(v.getM()), n(v.getN()), depth(v.getDepth()-1)
{
	if (depth < 0) {
		throw SYLV_MES_EXCEPTION("Bad KronVector pick, depth < 0.");
	}
}