[1991be]: src / lib / compiler / NodeFactory.cc  Maximize  Restore  History

Download this file

94 lines (83 with data), 2.1 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
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
#include <compiler/NodeFactory.h>
#include <graph/Node.h>
#include <util/nainf.h>
#include <cfloat>
#include <cmath>
using std::vector;
namespace jags {
/* Comparison function for arrays of doubles of equal length */
bool lt(double const *value1, double const *value2, unsigned int length)
{
for (unsigned long i = 0; i < length; ++i) {
if (lt(value1[i], value2[i])) {
return true;
}
else if (lt(value2[i], value1[i])) {
return false;
}
}
return false;
}
/* Comparison function for STL vectors */
/*
bool lt(vector<double> const &value1, vector<double> const &value2)
{
for (unsigned long i = 0; i < value1.size(); ++i) {
if (lt(value1[i], value2[i])) {
return true;
}
else if (lt(value2[i], value1[i])) {
return false;
}
}
return false;
}
*/
/* Comparison function for Nodes */
bool lt(Node const *node1, Node const *node2)
{
if (node1 == node2) {
// A node is always identical to itself
return false;
}
bool fix1 = node1->isFixed();
bool fix2 = node2->isFixed();
if (fix1 && fix2) {
//Fixed nodes are sorted by dimension, then value
if (node1->dim() == node2->dim()) {
return lt(node1->value(0), node2->value(0), node1->length());
}
else {
return node1->dim() < node2->dim();
}
}
else if (!fix1 && !fix2) {
//Non-fixed nodes are sorted by address. The ordering is
//arbitrary, but unique.
return (node1 < node2);
}
else {
//Fixed nodes come before non-fixed nodes
return fix1 > fix2;
}
}
/* Comparison operator for vectors of parameters */
bool lt(vector<Node const *> const &par1, vector<Node const *> const &par2)
{
if (par1.size() == par2.size()) {
//Equal sized vectors: Sort by ordering of elements
for (unsigned int i = 0; i < par1.size(); ++i) {
if (lt(par1[i], par2[i])) {
return true;
}
else if (lt(par2[i], par1[i])) {
return false;
}
}
return false;
}
else {
return par1.size() < par2.size();
}
}
}

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

Sign up for the SourceForge newsletter:





No, thanks