File: sparse_tensor.h

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 (130 lines) | stat: -rw-r--r-- 2,628 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*1:*/
#line 29 "./sparse_tensor.hweb"

#ifndef SPARSE_TENSOR_H
#define SPARSE_TENSOR_H

#include "symmetry.h"
#include "tensor.h"
#include "gs_tensor.h"
#include "Vector.h"

#include <map> 

using namespace std;

/*2:*/
#line 50 "./sparse_tensor.hweb"

struct ltseq{
bool operator()(const IntSequence&s1,const IntSequence&s2)const
{return s1<s2;}
};

/*:2*/
#line 42 "./sparse_tensor.hweb"
;
/*3:*/
#line 60 "./sparse_tensor.hweb"

class SparseTensor{
public:
typedef pair<int,double> Item;
typedef multimap<IntSequence,Item,ltseq> Map;
typedef Map::const_iterator const_iterator;
protected:
typedef Map::iterator iterator;

Map m;
const int dim;
const int nr;
const int nc;
int first_nz_row;
int last_nz_row;
public:
SparseTensor(int d,int nnr,int nnc)
:dim(d),nr(nnr),nc(nnc),first_nz_row(nr),last_nz_row(-1){}
SparseTensor(const SparseTensor&t)
:m(t.m),dim(t.dim),nr(t.nr),nc(t.nc){}
virtual~SparseTensor(){}
void insert(const IntSequence&s,int r,double c);
const Map&getMap()const
{return m;}
int dimen()const
{return dim;}
int nrows()const
{return nr;}
int ncols()const
{return nc;}
double getFillFactor()const
{return((double)m.size())/(nrows()*ncols());}
double getFoldIndexFillFactor()const;
double getUnfoldIndexFillFactor()const;
int getNumNonZero()const
{return m.size();}
int getFirstNonZeroRow()const
{return first_nz_row;}
int getLastNonZeroRow()const
{return last_nz_row;}
virtual const Symmetry&getSym()const= 0;
void print()const;
bool isFinite()const;
}

/*:3*/
#line 43 "./sparse_tensor.hweb"
;
/*4:*/
#line 109 "./sparse_tensor.hweb"

class FSSparseTensor:public SparseTensor{
public:
typedef SparseTensor::const_iterator const_iterator;
private:
const int nv;
const Symmetry sym;
public:
FSSparseTensor(int d,int nvar,int r);
FSSparseTensor(const FSSparseTensor&t);
void insert(const IntSequence&s,int r,double c);
void multColumnAndAdd(const Tensor&t,Vector&v)const;
const Symmetry&getSym()const
{return sym;}
int nvar()const
{return nv;}
void print()const;
};


/*:4*/
#line 44 "./sparse_tensor.hweb"
;
/*5:*/
#line 134 "./sparse_tensor.hweb"

class GSSparseTensor:public SparseTensor{
public:
typedef SparseTensor::const_iterator const_iterator;
private:
const TensorDimens tdims;
public:
GSSparseTensor(const FSSparseTensor&t,const IntSequence&ss,
const IntSequence&coor,const TensorDimens&td);
GSSparseTensor(const GSSparseTensor&t)
:SparseTensor(t),tdims(t.tdims){}
void insert(const IntSequence&s,int r,double c);
const Symmetry&getSym()const
{return tdims.getSym();}
const TensorDimens&getDims()const
{return tdims;}
void print()const;

};

/*:5*/
#line 45 "./sparse_tensor.hweb"
;

#endif

/*:1*/