MUQ  0.4.3
SplitSumWorkGraph.cpp
Go to the documentation of this file.
6 
7 using namespace muq::Modeling;
8 
9 int main(){
10  auto f = std::make_shared<SinOperator>(2);
11  auto g = std::make_shared<ExpOperator>(2);
12  auto sum = std::make_shared<SumPiece>(2);
13 
14  // Will split x_{1:dim} into two equally sized vectors
15  auto splitter = std::make_shared<SplitVector>(std::vector<int>{0,2}, // indices of output
16  std::vector<int>{2,2}, // sizes of output
17  4); // size of input
18 
19  auto graph = std::make_shared<WorkGraph>();
20 
21  graph->AddNode(splitter, "x12,x34");
22  graph->AddNode(g,"g");
23  graph->AddNode(f,"f");
24  graph->AddEdge("x12,x34",0,"f",0); // connect output 0 of x12,x34 with input 0 of f
25  graph->AddEdge("x12,x34",0,"g",0); // connect output 1 of x12,x34 with input 0 of g
26 
27  graph->AddNode(sum,"f+g");
28  graph->AddEdge("f",0,"f+g",0); // connect output 0 of f with input 0 of f+g
29  graph->AddEdge("g",0,"f+g",1); // connect output 0 of g with intpu 1 of f+g
30 
31  auto mod = graph->CreateModPiece("f+g");
32 
33  Eigen::VectorXd x = Eigen::VectorXd::Random(4);
34  std::cout << "result = " << mod->Evaluate(x).at(0).transpose() << std::endl;
35  return 0;
36 }
int main()