Commit 203a4c4c authored by Paul's avatar Paul
Browse files

Add more validation

parent 84714596
......@@ -62,16 +62,26 @@ struct instruction
return std::addressof(i) == std::addressof(*ref);
}
bool valid() const
bool valid(instruction_ref start) const
{
return std::all_of(output.begin(),
std::vector<shape> shapes(arguments.size());
std::transform(arguments.begin(), arguments.end(), shapes.begin(), [](instruction_ref ins) { return ins->result; });
shape computed;
try
{
computed = op.compute_shape(shapes);
}
catch(migraph::exception&) { return false; }
return result == computed &&
std::all_of(output.begin(),
output.end(),
[&](instruction_ref i) {
return std::find(i->arguments.begin(), i->arguments.end(), *this) !=
i->arguments.end();
}) &&
std::all_of(arguments.begin(), arguments.end(), [&](instruction_ref i) {
return std::find(i->output.begin(), i->output.end(), *this) != i->output.end();
auto self = std::find(i->output.begin(), i->output.end(), *this);
return self != i->output.end() && std::distance(start, i) < std::distance(start, *self);
});
}
......
......@@ -129,7 +129,7 @@ instruction_ref program::validate() const
{
return std::find_if(impl->instructions.begin(),
impl->instructions.end(),
[](const instruction& i) { return i.valid(); });
[&](const instruction& i) { return i.valid(impl->instructions.begin()); });
}
void program::compile(const target& t)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment