currRhsDim < rhsShape.size()) {
if (lhsSize < rhsSize) {
currLhsDim++;
- lhsSize *= lhsShape[currLhsDim];
+ if (currLhsDim < lhsShape.size()) {
+ lhsSize *= lhsShape[currLhsDim];
+ }
} else {
currRhsDim++;
- rhsSize *= rhsShape[currRhsDim];
+ if (currRhsDim < rhsShape.size()) {
+ rhsSize *= rhsShape[currRhsDim];
+ }
}
}
if (lhsSize == rhsSize) {
return success();
}
+mlir::LogicalResult tosa::ReshapeOp::verify() {
+ ShapedType inputType = getInput1().getType().cast<ShapedType>();
+ ShapedType outputType = getType().cast<ShapedType>();
+
+ if (inputType.hasStaticShape() && outputType.hasStaticShape()) {
+ int64_t inputElementsNum = inputType.getNumElements();
+ int64_t outputElementsNum = outputType.getNumElements();
+ if (inputElementsNum != outputElementsNum) {
+ return emitOpError() << "Cannot reshape " << inputElementsNum
+ << " elements into " << outputElementsNum;
+ }
+ }
+ return mlir::success();
+}
+
LogicalResult tosa::TransposeOp::inferReturnTypeComponents(
MLIRContext *context, ::std::optional<Location> location,
ValueShapeRange operands, DictionaryAttr attributes, RegionRange regions,