From 76ef1e98f368f423e0652864a99b343fd8a729be Mon Sep 17 00:00:00 2001 From: Ronan Collobert Date: Thu, 30 Oct 2025 16:18:59 -0700 Subject: [PATCH] WIP (common) --- mlx/backend/common/reduce.cpp | 4 ++-- mlx/backend/common/utils.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mlx/backend/common/reduce.cpp b/mlx/backend/common/reduce.cpp index ceef46400..aa4c73560 100644 --- a/mlx/backend/common/reduce.cpp +++ b/mlx/backend/common/reduce.cpp @@ -28,7 +28,7 @@ std::pair shapes_without_reduction_axes( ReductionPlan get_reduction_plan(const array& x, const std::vector& axes) { // The data is all there and we are reducing over everything - if (x.size() == x.data_size() && axes.size() == x.ndim() && + if (x.size() == x.data_size() && std::ssize(axes) == x.ndim() && x.flags().contiguous) { return ContiguousAllReduce; } @@ -38,7 +38,7 @@ ReductionPlan get_reduction_plan(const array& x, const std::vector& axes) { // Merge consecutive axes Shape shape = {x.shape(axes[0])}; Strides strides = {x.strides()[axes[0]]}; - for (int i = 1; i < axes.size(); i++) { + for (int i = 1; i < std::ssize(axes); i++) { if (axes[i] - 1 == axes[i - 1] && x.shape(axes[i]) > 1) { shape.back() *= x.shape(axes[i]); strides.back() = x.strides()[axes[i]]; diff --git a/mlx/backend/common/utils.cpp b/mlx/backend/common/utils.cpp index ae169e35e..e2c11d669 100644 --- a/mlx/backend/common/utils.cpp +++ b/mlx/backend/common/utils.cpp @@ -28,7 +28,7 @@ std::tuple> collapse_contiguous_dims( if (shape[0] != 1) { to_collapse.push_back(0); } - size_t size = shape[0]; + int64_t size = shape[0]; for (int i = 1; i < shape.size(); i++) { bool contiguous = true; size *= shape[i]; @@ -64,7 +64,7 @@ std::tuple> collapse_contiguous_dims( current_shape *= shape[to_collapse[k]]; } out_shape.push_back(current_shape); - for (int j = 0; j < strides.size(); j++) { + for (int j = 0; j < std::ssize(strides); j++) { const auto& st = strides[j]; out_strides[j].push_back(st[to_collapse[k - 1]]); }