Add convenience function for checking arrays of shapes compatible.

Expand existing one to handle the common case for verifying compatible
is existing and inferred. This considers arrays equivalent if they they
have the same size and pairwise compatible elements.
This commit is contained in:
Jacques Pienaar 2021-01-28 10:47:07 -08:00
parent 8af0ccf5a4
commit acaf85f700
2 changed files with 17 additions and 0 deletions

View File

@ -55,6 +55,11 @@ LogicalResult verifyCompatibleShape(ArrayRef<int64_t> shape1,
/// does not matter.
LogicalResult verifyCompatibleShape(Type type1, Type type2);
/// Returns success if the given two arrays have the same number of elements and
/// each pair wise entries have compatible shape.
LogicalResult verifyCompatibleShapes(ArrayRef<Type> types1,
ArrayRef<Type> types2);
//===----------------------------------------------------------------------===//
// Utility Iterators
//===----------------------------------------------------------------------===//

View File

@ -86,6 +86,18 @@ LogicalResult mlir::verifyCompatibleShape(Type type1, Type type2) {
return verifyCompatibleShape(sType1.getShape(), sType2.getShape());
}
/// Returns success if the given two arrays have the same number of elements and
/// each pair wise entries have compatible shape.
LogicalResult mlir::verifyCompatibleShapes(ArrayRef<Type> types1,
ArrayRef<Type> types2) {
if (types1.size() != types2.size())
return failure();
for (auto it : zip_first(types1, types2))
if (failed(verifyCompatibleShape(std::get<0>(it), std::get<1>(it))))
return failure();
return success();
}
OperandElementTypeIterator::OperandElementTypeIterator(
Operation::operand_iterator it)
: llvm::mapped_iterator<Operation::operand_iterator, Type (*)(Value)>(