1 #include <config.h>
2 #include "Seq.h"
3 
4 using std::vector;
5 using std::string;
6 
7 namespace jags {
8     namespace base {
9 
Seq()10 	Seq::Seq() : VectorFunction(":", 2)
11 	{
12 	}
13 
evaluate(double * value,vector<double const * > const & par_values,vector<unsigned int> const & par_lengths) const14 	void Seq::evaluate(double *value,
15 			   vector <double const *> const &par_values,
16 			   vector <unsigned int> const &par_lengths) const
17 	{
18 	    int lhs = static_cast<int>(*par_values[0]);
19 	    int rhs = static_cast<int>(*par_values[1]);
20 
21 	    if (rhs < lhs) return;
22 
23 	    int N = rhs - lhs + 1;
24 	    for (int i = 0; i < N; ++i) {
25 		value[i] = lhs + i;
26 	    }
27 	}
28 
length(vector<unsigned int> const & lengths,vector<double const * > const & values) const29 	unsigned int Seq::length(vector <unsigned int> const &lengths,
30 				 vector <double const *> const &values) const
31 	{
32 	    int lhs = static_cast<int>(*values[0]);
33 	    int rhs = static_cast<int>(*values[1]);
34 
35 	    if (rhs < lhs) {
36 		return 0;
37 	    }
38 	    else {
39 		return rhs - lhs + 1;
40 	    }
41 	}
42 
checkParameterLength(vector<unsigned int> const & len) const43 	bool Seq::checkParameterLength(vector<unsigned int> const &len) const
44 	{
45 	    return (len[0] == 1) && (len[1] == 1);
46 	}
47 
isDiscreteValued(vector<bool> const & mask) const48         bool Seq::isDiscreteValued(vector<bool> const &mask) const
49 	{
50 	    return true;
51 	}
52 
checkParameterDiscrete(vector<bool> const & mask) const53         bool Seq::checkParameterDiscrete(vector<bool> const &mask) const
54 	{
55 	    //Both parameters must be discrete
56 	    return mask[0] && mask[1];
57 	}
58 
checkParameterFixed(vector<bool> const & mask) const59 	bool Seq::checkParameterFixed(vector<bool> const &mask) const
60 	{
61 	    //Both parameters must be fixed so that the length of the
62 	    //output vector is fixed
63 	    return mask[0] && mask[1];
64 	}
65 
deparse(vector<string> const & par) const66 	string Seq::deparse(vector<string> const &par) const
67 	{
68 	    return par[0] + ":" + par[1];
69 	}
70 
71     } /* namespace base */
72 } /* namespace jags */
73 
74