#include "loco/IR/NodeShape.h"
#include <cassert>
+#include <stdexcept>
//
// BiasShape Support
}
} // namespace loco
+
+namespace loco
+{
+
+bool operator==(const NodeShape &lhs, const NodeShape &rhs)
+{
+ if (lhs.domain() != rhs.domain())
+ return false;
+
+ switch (lhs.domain())
+ {
+ case loco::Domain::Tensor:
+ {
+ auto lhs_t = lhs.as<TensorShape>();
+ auto rhs_t = rhs.as<TensorShape>();
+ if (lhs_t.rank() != rhs_t.rank())
+ return false;
+ for (uint32_t axis = 0; axis < lhs_t.rank(); ++axis)
+ {
+ if (!(lhs_t.dim(axis) == rhs_t.dim(axis)))
+ return false;
+ }
+ return true;
+ }
+
+ case loco::Domain::Feature:
+ {
+ auto lhs_f = lhs.as<FeatureShape>();
+ auto rhs_f = rhs.as<FeatureShape>();
+
+ return (lhs_f.count() == rhs_f.count() && lhs_f.depth() == rhs_f.depth() &&
+ lhs_f.height() == rhs_f.height() && lhs_f.width() == rhs_f.width());
+ }
+
+ case loco::Domain::Filter:
+ {
+ auto lhs_f = lhs.as<FilterShape>();
+ auto rhs_f = rhs.as<FilterShape>();
+
+ return (lhs_f.count() == rhs_f.count() && lhs_f.depth() == rhs_f.depth() &&
+ lhs_f.height() == rhs_f.height() && lhs_f.width() == rhs_f.width());
+ }
+
+ case loco::Domain::DepthwiseFilter:
+ {
+ auto lhs_f = lhs.as<DepthwiseFilterShape>();
+ auto rhs_f = rhs.as<DepthwiseFilterShape>();
+
+ return (lhs_f.multiplier() == rhs_f.multiplier() && lhs_f.depth() == rhs_f.depth() &&
+ lhs_f.height() == rhs_f.height() && lhs_f.width() == rhs_f.width());
+ }
+
+ case loco::Domain::Bias:
+ {
+ auto lhs_f = lhs.as<BiasShape>();
+ auto rhs_f = rhs.as<BiasShape>();
+
+ return (lhs_f.length() == rhs_f.length());
+ }
+
+ default:
+ throw std::runtime_error("Not supported domain for NodeShape equality");
+ }
+ return false;
+}
+
+} // namespace loco