[0513cd]: src / include / compiler / ConstantFactory.h  Maximize  Restore  History

Download this file

59 lines (50 with data), 1.6 kB

 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
#ifndef CONSTANT_FACTORY_H_
#define CONSTANT_FACTORY_H_
#include <map>
#include <compiler/NodeFactory.h>
namespace jags {
class ConstantNode;
class Model;
/**
* @short STL function object for the map class using double as a key
*/
struct ltdouble
{
bool operator()(double arg1, double arg2) const
{
return lt(arg1, arg2);
}
};
typedef std::pair<std::vector<unsigned int>, std::vector<double> > constpair;
/**
* @short Factory for ConstantNode objects
*
* The purpose of a ConstantFactory is to avoid unnecessary
* duplication of constant nodes by having a container class and
* factory for them that will create and/or lookup constant nodes
* based on their value.
*/
class ConstantFactory
{
unsigned int _nchain;
std::map<double, ConstantNode*, ltdouble> _constmap;
std::map<constpair, ConstantNode*> _mv_constmap;
public:
ConstantFactory(unsigned int nchain);
/**
* Get a constant node with a given value. The results are cached,
* so if a request is repeated, the same node will be returned.
* If a node is newly allocated, it is added to the given model.
*/
ConstantNode *getConstantNode(double value, Model &graph);
/**
* Get a multivariate constant node. The results are cached
* so that if a request is repeated, the same node will be returned.
* If a node is newly allocated, it is added to the given model.
*/
ConstantNode *getConstantNode(std::vector<unsigned int> const &dim,
std::vector<double> const &value,
Model &graph);
};
} /* namespace jags */
#endif /* CONSTANT_FACTORY_H_ */

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks