MUQ  0.4.3
ConstantVector.cpp
Go to the documentation of this file.
3 
4 using namespace muq::Modeling;
5 
6 ConstantVector::ConstantVector(std::vector<Eigen::VectorXd> const& outs) : ModPiece(Eigen::VectorXi(), OutSizes(outs))
7 {
8  outputs.resize(outs.size());
9  for( unsigned int i=0; i<outs.size(); ++i ) {
10  outputs.at(i) = outs[i];
11  }
12 }
13 
14 ConstantVector::ConstantVector(std::vector<boost::any> const& outs) : ModPiece(Eigen::VectorXi(), OutSizes(outs))
15 {
16  outputs.resize(outs.size());
17  for( unsigned int i=0; i<outs.size(); ++i ) {
18  assert(typeid(Eigen::VectorXd)==outs[i].type());
19  outputs.at(i) = boost::any_cast<Eigen::VectorXd>(outs[i]);
20  }
21 }
22 
23 ConstantVector::ConstantVector(Eigen::VectorXd const& valIn) : ModPiece(Eigen::VectorXi(), valIn.size()*Eigen::VectorXi::Ones(1))
24 {
25  outputs.resize(1);
26  outputs.at(0) = valIn;
27 }
28 
29 Eigen::VectorXi ConstantVector::OutSizes(std::vector<Eigen::VectorXd> const& outs) {
30  Eigen::VectorXi oSizes(outs.size());
31  for( unsigned int i=0; i<outs.size(); ++i ) {
32  oSizes(i) = outs[i].size();
33  }
34 
35  return oSizes;
36 }
37 
38 Eigen::VectorXi ConstantVector::OutSizes(std::vector<boost::any> const& outs) {
39  Eigen::VectorXi oSizes(outs.size());
40  for( unsigned int i=0; i<outs.size(); ++i ) {
41  assert(typeid(Eigen::VectorXd)==outs[i].type());
42  oSizes(i) = boost::any_cast<Eigen::VectorXd>(outs[i]).size();
43  }
44 
45  return oSizes;
46 }
47 
48 void ConstantVector::SetValue(Eigen::VectorXd const& valIn)
49 {
50  if(valIn.size() != outputSizes(0))
51  throw muq::WrongSizeError("In ConstantVector::SetValue, new vector has size " + std::to_string(valIn.size()) + ", but expected a size of " + std::to_string(outputSizes(0)) + ".");
52 
53  outputs.at(0) = valIn;
54 }
55 
57  return;
58 }
void SetValue(Eigen::VectorXd const &valIn)
Set the outputs.
static Eigen::VectorXi OutSizes(std::vector< Eigen::VectorXd > const &outs)
virtual void EvaluateImpl(muq::Modeling::ref_vector< Eigen::VectorXd > const &inputs) override
The outputs are already set and not cleared so don't do anything.
ConstantVector(std::vector< Eigen::VectorXd > const &outs)
Create a muq::Modeling::ConstantPiece with the outputs given in a vector of vectors.
Provides an abstract interface for defining vector-valued model components.
Definition: ModPiece.h:148
std::vector< Eigen::VectorXd > outputs
Definition: ModPiece.h:503
const Eigen::VectorXi outputSizes
Definition: ModPiece.h:472
Exception to throw when matrices, vectors, or arrays are the wrong size.
Definition: Exceptions.h:58
std::vector< std::reference_wrapper< const T > > ref_vector
A vector of references to something ...
Definition: WorkPiece.h:37
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
Definition: json.h:25172