"tools/vscode:/vscode.git/clone" did not exist on "c9ad3605a78bb06e3729d7c82f4e6a700ccf584a"
Commit f33c7a48 authored by Paul's avatar Paul
Browse files

Formatting

parent 3d9bef13
...@@ -4,15 +4,18 @@ ...@@ -4,15 +4,18 @@
namespace migraph { namespace migraph {
instruction::instruction(operation o, shape r, std::vector<instruction_ref> args) instruction::instruction(operation o, shape r, std::vector<instruction_ref> args)
: op(std::move(o)), result(std::move(r)), arguments(std::move(args)) : op(std::move(o)), result(std::move(r)), arguments(std::move(args))
{ {
} }
instruction::instruction(literal l) : op(builtin::literal{}), result(l.get_shape()), lit(std::move(l)) {} instruction::instruction(literal l)
: op(builtin::literal{}), result(l.get_shape()), lit(std::move(l))
{
}
void instruction::replace(const shape& r) void instruction::replace(const shape& r)
{ {
if(r != result) if(r != result)
{ {
result = r; result = r;
...@@ -22,35 +25,35 @@ namespace migraph { ...@@ -22,35 +25,35 @@ namespace migraph {
ins->recompute_shape(); ins->recompute_shape();
} }
} }
} }
void instruction::recompute_shape() { replace(compute_shape(op, arguments)); } void instruction::recompute_shape() { replace(compute_shape(op, arguments)); }
void instruction::clear_arguments() void instruction::clear_arguments()
{ {
for(auto&& arg : arguments) for(auto&& arg : arguments)
{ {
arg->remove_output(*this); arg->remove_output(*this);
} }
arguments.clear(); arguments.clear();
} }
bool operator==(const instruction& i, instruction_ref ref) bool operator==(const instruction& i, instruction_ref ref)
{ {
return std::addressof(i) == std::addressof(*ref); return std::addressof(i) == std::addressof(*ref);
} }
bool instruction::valid(instruction_ref start) const bool instruction::valid(instruction_ref start) const
{ {
return valid() && std::all_of(arguments.begin(), arguments.end(), [&](instruction_ref i) { return valid() && std::all_of(arguments.begin(), arguments.end(), [&](instruction_ref i) {
auto self = std::find(i->outputs().begin(), i->outputs().end(), *this); auto self = std::find(i->outputs().begin(), i->outputs().end(), *this);
return self != i->outputs().end() && return self != i->outputs().end() &&
std::distance(start, i) < std::distance(start, *self); std::distance(start, i) < std::distance(start, *self);
}); });
} }
bool instruction::valid() const bool instruction::valid() const
{ {
shape computed; shape computed;
if(op.name() == "@literal") if(op.name() == "@literal")
{ {
...@@ -71,84 +74,86 @@ namespace migraph { ...@@ -71,84 +74,86 @@ namespace migraph {
return false; return false;
} }
} }
return result == computed && return result == computed && std::all_of(output.begin(), output.end(), [&](instruction_ref i) {
std::all_of(output.begin(), output.end(), [&](instruction_ref i) { return std::find(i->inputs().begin(), i->inputs().end(), *this) != i->inputs().end();
return std::find(i->inputs().begin(), i->inputs().end(), *this) !=
i->inputs().end();
}); });
} }
shape instruction::get_shape() const { return result; } shape instruction::get_shape() const { return result; }
const literal& instruction::get_literal() const const literal& instruction::get_literal() const
{ {
assert(op.name() == "@literal"); assert(op.name() == "@literal");
return lit; return lit;
} }
const operation& instruction::get_operator() const { return op; } const operation& instruction::get_operator() const { return op; }
std::string instruction::name() const { return op.name(); } std::string instruction::name() const { return op.name(); }
const std::vector<instruction_ref>& instruction::inputs() const { return arguments; } const std::vector<instruction_ref>& instruction::inputs() const { return arguments; }
const std::vector<instruction_ref>& instruction::outputs() const { return output; } const std::vector<instruction_ref>& instruction::outputs() const { return output; }
bool operator==(instruction_ref ref, const instruction& i) { return i == ref; } bool operator==(instruction_ref ref, const instruction& i) { return i == ref; }
bool operator!=(const instruction& i, instruction_ref ref) { return !(i == ref); } bool operator!=(const instruction& i, instruction_ref ref) { return !(i == ref); }
bool operator!=(instruction_ref ref, const instruction& i) { return !(i == ref); } bool operator!=(instruction_ref ref, const instruction& i) { return !(i == ref); }
void instruction::add_output(instruction_ref ins) void instruction::add_output(instruction_ref ins)
{ {
if(std::find(output.begin(), output.end(), ins) == output.end()) if(std::find(output.begin(), output.end(), ins) == output.end())
output.push_back(ins); output.push_back(ins);
} }
template <class T> template <class T>
void instruction::remove_output(const T& ins) void instruction::remove_output(const T& ins)
{ {
migraph::erase(output, ins); migraph::erase(output, ins);
} }
void instruction::backreference(instruction_ref ref) void instruction::backreference(instruction_ref ref)
{ {
for(auto&& arg : ref->inputs()) for(auto&& arg : ref->inputs())
arg->add_output(ref); arg->add_output(ref);
} }
void instruction::replace_argument(instruction_ref ins, instruction_ref old, instruction_ref new_ins) void instruction::replace_argument(instruction_ref ins,
{ instruction_ref old,
instruction_ref new_ins)
{
ins->replace_argument(old, new_ins); ins->replace_argument(old, new_ins);
backreference(ins); backreference(ins);
ins->recompute_shape(); ins->recompute_shape();
} }
void void instruction::replace(instruction_ref ins,
instruction::replace(instruction_ref ins, operation o, const shape& r, std::vector<instruction_ref> args) operation o,
{ const shape& r,
std::vector<instruction_ref> args)
{
ins->replace(std::move(o), r, std::move(args)); ins->replace(std::move(o), r, std::move(args));
backreference(ins); backreference(ins);
} }
void instruction::replace(operation o, const shape& r, std::vector<instruction_ref> args) void instruction::replace(operation o, const shape& r, std::vector<instruction_ref> args)
{ {
op = std::move(o); op = std::move(o);
replace(r); replace(r);
replace(std::move(args)); replace(std::move(args));
} }
void instruction::replace(std::vector<instruction_ref> args) void instruction::replace(std::vector<instruction_ref> args)
{ {
clear_arguments(); clear_arguments();
arguments = std::move(args); arguments = std::move(args);
} }
void instruction::replace_argument(instruction_ref old, instruction_ref new_ins) void instruction::replace_argument(instruction_ref old, instruction_ref new_ins)
{ {
std::replace(arguments.begin(), arguments.end(), old, new_ins); std::replace(arguments.begin(), arguments.end(), old, new_ins);
old->remove_output(*this); old->remove_output(*this);
} }
shape compute_shape(const operation& op, const std::vector<instruction_ref>& args) shape compute_shape(const operation& op, const std::vector<instruction_ref>& args)
{ {
......
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