From a3b36a3bb4af3967432c3c6808e287ae5dd51e4c Mon Sep 17 00:00:00 2001 From: Gunhyun Park Date: Thu, 8 Feb 2024 14:55:36 -0800 Subject: [PATCH] Convert lambda call to a function call (#1999) The `hasDuplicates` function was originally factored out because it is used frequently. However it was still defined as lambda, so I've updated it to be a function. There was also an unnecessary conversion to a vector (the underlying data does not change), so I've removed the conversion too. --- stablehlo/dialect/TypeInference.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/stablehlo/dialect/TypeInference.cpp b/stablehlo/dialect/TypeInference.cpp index 6c4356e70a8..4b4509c8508 100644 --- a/stablehlo/dialect/TypeInference.cpp +++ b/stablehlo/dialect/TypeInference.cpp @@ -68,10 +68,10 @@ namespace hlo { //===----------------------------------------------------------------------===// // Checks if the vector `nums` has duplicates. -const auto hasDuplicates = [](const ArrayRef nums) { +bool hasDuplicates(ArrayRef nums) { llvm::SmallDenseSet set(nums.begin(), nums.end()); return set.size() != nums.size(); -}; +} bool tensorsHaveSameElType(TypeRange types, bool ignoreFpPrecision = true) { if (!types.empty()) { @@ -3274,16 +3274,15 @@ LogicalResult verifyBroadcastInDimOp(std::optional location, dimensionsSize, ") does not match operand rank (", operandRank, ")"); - auto dimensions = llvm::to_vector(broadcastDimensions); // broadcast_in_dim_c4 - if (hasDuplicates(dimensions)) + if (hasDuplicates(broadcastDimensions)) return emitOptionalError(location, "broadcast_dimensions should not have duplicates"); auto resultType = result.getType().cast(); auto resultRank = resultType.getRank(); for (size_t i = 0; i != dimensionsSize; ++i) { - auto dimIndex = dimensions[i]; + auto dimIndex = broadcastDimensions[i]; // broadcast_in_dim_c3 if (dimIndex < 0 || dimIndex >= resultRank) return emitOptionalError(location,