Skip to content

Commit

Permalink
Use int64_t instead of ssize_t (#1673)
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz authored Dec 8, 2024
1 parent 7c10c93 commit 6f316b8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mlx/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ bool is_same_shape(const std::vector<array>& arrays);
template <typename T>
int check_shape_dim(const T dim) {
constexpr bool is_signed = std::numeric_limits<T>::is_signed;
using U = std::conditional_t<is_signed, ssize_t, size_t>;
using U = std::conditional_t<is_signed, int64_t, size_t>;
constexpr U min = static_cast<U>(std::numeric_limits<int>::min());
constexpr U max = static_cast<U>(std::numeric_limits<int>::max());

Expand Down
8 changes: 4 additions & 4 deletions tests/utils_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ TEST_CASE("test check shape dimension") {
CHECK_EQ(check_shape_dim(-4), -4);
CHECK_EQ(check_shape_dim(0), 0);
CHECK_EQ(check_shape_dim(12), 12);
CHECK_EQ(check_shape_dim(static_cast<ssize_t>(dim_min)), dim_min);
CHECK_EQ(check_shape_dim(static_cast<ssize_t>(dim_max)), dim_max);
CHECK_EQ(check_shape_dim(static_cast<int64_t>(dim_min)), dim_min);
CHECK_EQ(check_shape_dim(static_cast<int64_t>(dim_max)), dim_max);
CHECK_EQ(check_shape_dim(static_cast<size_t>(0)), 0);
CHECK_EQ(check_shape_dim(static_cast<size_t>(dim_max)), dim_max);
CHECK_THROWS_AS(
check_shape_dim(static_cast<ssize_t>(dim_min) - 1),
check_shape_dim(static_cast<int64_t>(dim_min) - 1),
std::invalid_argument);
CHECK_THROWS_AS(
check_shape_dim(static_cast<ssize_t>(dim_max) + 1),
check_shape_dim(static_cast<int64_t>(dim_max) + 1),
std::invalid_argument);
CHECK_THROWS_AS(
check_shape_dim(static_cast<size_t>(dim_max) + 1), std::invalid_argument);
Expand Down

0 comments on commit 6f316b8

Please sign in to comment.