Skip to content

Commit 440e72c

Browse files
wenxin0319facebook-github-bot
authored andcommitted
Fix Signed-Unsigned Comparison in Tensor Utils (#4279)
Summary: Resolved warnings caused by comparisons between signed and unsigned integers in tensor_utils.h. Changed the loop index variable i from int to size_t to match the type of sizes.size(), ensuring consistent and safe comparisons. This change eliminates the -Wsign-compare warnings during compilation. The original error message here: ``` buck-out/v2/gen/fbcode/b43bb943fef57626/deeplearning/fbgemm/fbgemm_gpu/__fbgemm_gpu_cpu__/buck-headers/fbgemm_gpu/utils/tensor_utils.h:53:20: error: comparison of integers of different signs: 'int' and 'size_t' (aka 'unsigned long') [-Werror,-Wsign-compare] 53 | for (auto i = 0; i < sizes.size(); ++i) { | ~ ^ ~~~~~~~~~~~~ buck-out/v2/gen/fbcode/b43bb943fef57626/deeplearning/fbgemm/fbgemm_gpu/__fbgemm_gpu_cpu__/buck-headers/fbgemm_gpu/utils/tensor_utils.h:55:7: error: comparison of integers of different signs: 'int' and 'size_t' (aka 'unsigned long') [-Werror,-Wsign-compare] 55 | if (i != (sizes.size() - (1))) { | ~ ^ ~~~~~~~~~~~~~~~~~~ 2 errors generated. ``` Differential Revision: D76093914
1 parent 2283ec6 commit 440e72c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fbgemm_gpu/include/fbgemm_gpu/utils/tensor_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ inline const std::string torch_tensor_shape_str(const at::Tensor& ten) {
5050
std::stringstream ss;
5151
const auto sizes = ten.sizes();
5252
ss << "[";
53-
for (auto i = 0; i < sizes.size(); ++i) {
53+
for (std::size_t i = 0; i < sizes.size(); ++i) {
5454
ss << sizes[i];
5555
if (i != sizes.size() - 1) {
5656
ss << ", ";

0 commit comments

Comments
 (0)