1 #include <config.h>
2 #include "Sum.h"
3 #include <util/logical.h>
4 
5 using std::vector;
6 
7 namespace jags {
8 namespace bugs {
9 
Sum()10     Sum::Sum () : ScalarVectorFunction("sum", 0)
11     {
12     }
13 
scalarEval(vector<double const * > const & args,vector<unsigned int> const & lengths) const14     double Sum::scalarEval(vector <double const *> const &args,
15 			   vector<unsigned int> const &lengths) const
16     {
17 	double value = 0;
18 	for (unsigned int j = 0; j < args.size(); ++j) {
19 	    for (unsigned int i = 0; i < lengths[j]; ++i) {
20 		value += args[j][i];
21 	    }
22 	}
23 	return value;
24     }
25 
isDiscreteValued(vector<bool> const & mask) const26     bool Sum::isDiscreteValued(vector<bool> const &mask) const
27     {
28 	return allTrue(mask);
29     }
30 
31     bool
isAdditive(vector<bool> const & mask,vector<bool> const & fixed) const32     Sum::isAdditive(vector<bool> const &mask, vector<bool> const &fixed) const
33     {
34 	//Only one argument may be additive.
35 	bool found = false;
36 	for (unsigned int i = 0; i < mask.size(); ++i) {
37 	    if (mask[i]) {
38 		if (found) return false;
39 		else found = true;
40 	    }
41 	    if (!fixed.empty() && !fixed[i]) {
42 		return false;
43 	    }
44 	}
45 	return found;
46     }
47 
isScale(vector<bool> const & mask,vector<bool> const & fix) const48     bool Sum::isScale(vector<bool> const &mask, vector<bool> const &fix) const
49     {
50 	return allTrue(mask);
51     }
52 
isLinear(vector<bool> const & mask,vector<bool> const & fix) const53     bool Sum::isLinear(vector<bool> const &mask, vector<bool> const &fix) const
54     {
55 	return true;
56     }
57 
58 }}
59