I've written a C++ model which has inputs, outputs, and internal variables. In this case, the inputs are a sample stream x[n]. The outputs and internal variables are also sample streams. I'm calling this version of the code the "golden reference".
I've also thought of some code optimizations that I want to try. I'm calling this version of the code "experimental". But I want to make sure that any changes don't break the code. That is, the experimental code's inputs, outputs, and some internal variables match the golden reference's.
So for a sample stream input, I want to check that the experimental codes inputs, outputs, and internal variables match the golden references.
But I'm trying to think of a code/build structure that will allow me to run both versions at the same time with minimal changes to file names, class names, etc.
So far the easiest solution seems to me to edit each file in the experimental code base and rename the namespace and the #include paths. Is there a better solution that doesn't require a lot of renaming?
Most code resides in header files because of templates, etc.
// Golden src/top.h
#include "src/sub1.h"
#include "src/sub2.h"
namespace model {
class Top {
public:
Sub1 sub1;
Sub2 sub2;
Var var;
Var process(Var x) {
var = sub1.process(x);
return sub2.process(var);
}
};
}
// Experimental src_expr/top.h
#include "src_expr/sub1.h" // Have to edit include paths!
#include "src_expr/sub2.h"
namespace model_expr { // Have to rename namespaces!
class Top {
public:
Sub1 sub1;
Sub2 sub2;
Var var;
Var process(Var x) {
var = sub1.process(x);
return sub2.process(var);
}
};
}
// test.cpp
#include "src/top.h" // golden
#include "src_expr/top.h" // experimental
void test(std::vector<Var> xvec) {
model::Top top_gold;
model_expr::Top top_expr;
for (const auto& x : xvec) {
Var y_gold = top_gold.process(x);
Var y_expr = top_expr.process(x);
assert(y_gold == y_expr);
assert(top_gold.var == top_expr.var);
}
}
Aucun commentaire:
Enregistrer un commentaire