Skip to content

Commit

Permalink
Convert lambda call to a function call (#1999)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ghpvnist authored Feb 8, 2024
1 parent c4c0465 commit a3b36a3
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions stablehlo/dialect/TypeInference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ namespace hlo {
//===----------------------------------------------------------------------===//

// Checks if the vector `nums` has duplicates.
const auto hasDuplicates = [](const ArrayRef<int64_t> nums) {
bool hasDuplicates(ArrayRef<int64_t> nums) {
llvm::SmallDenseSet<int64_t> set(nums.begin(), nums.end());
return set.size() != nums.size();
};
}

bool tensorsHaveSameElType(TypeRange types, bool ignoreFpPrecision = true) {
if (!types.empty()) {
Expand Down Expand Up @@ -3274,16 +3274,15 @@ LogicalResult verifyBroadcastInDimOp(std::optional<Location> 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<RankedTensorType>();
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,
Expand Down

0 comments on commit a3b36a3

Please sign in to comment.