From d0f471cff734889ecae45a81e42d46048f791dbf Mon Sep 17 00:00:00 2001 From: Cheng Date: Mon, 9 Dec 2024 01:16:28 +0900 Subject: [PATCH] Using math defines requires switch in MSVC (#1665) * Using math defines requires switch in MSVC * Fix more math macros * Fix type * Remove _MSC_VER guard for math defines --- mlx/ops.cpp | 4 ++++ mlx/primitives.cpp | 4 ++++ tests/autograd_tests.cpp | 3 +++ tests/compile_tests.cpp | 3 +++ tests/ops_tests.cpp | 4 ++++ 5 files changed, 18 insertions(+) diff --git a/mlx/ops.cpp b/mlx/ops.cpp index 13ae53f761..577a178518 100644 --- a/mlx/ops.cpp +++ b/mlx/ops.cpp @@ -1,4 +1,8 @@ // Copyright © 2023-2024 Apple Inc. + +// Required for using M_PI in MSVC. +#define _USE_MATH_DEFINES + #include #include #include diff --git a/mlx/primitives.cpp b/mlx/primitives.cpp index 06be5f2a53..7acb4129cf 100644 --- a/mlx/primitives.cpp +++ b/mlx/primitives.cpp @@ -1,4 +1,8 @@ // Copyright © 2023-2024 Apple Inc. + +// Required for using M_2_SQRTPI in MSVC. +#define _USE_MATH_DEFINES + #include #include #include diff --git a/tests/autograd_tests.cpp b/tests/autograd_tests.cpp index 9b763ec8bd..3fe839ca5d 100644 --- a/tests/autograd_tests.cpp +++ b/tests/autograd_tests.cpp @@ -1,5 +1,8 @@ // Copyright © 2023 Apple Inc. +// Required for using M_2_SQRTPI in MSVC. +#define _USE_MATH_DEFINES + #include #include #include diff --git a/tests/compile_tests.cpp b/tests/compile_tests.cpp index 5bcba68f44..9ca4cf19f0 100644 --- a/tests/compile_tests.cpp +++ b/tests/compile_tests.cpp @@ -1,5 +1,8 @@ // Copyright © 2023-2024 Apple Inc. +// Required for using M_SQRT2 in MSVC. +#define _USE_MATH_DEFINES + #include "doctest/doctest.h" #include "mlx/mlx.h" diff --git a/tests/ops_tests.cpp b/tests/ops_tests.cpp index 9d87b8e2c3..3b9a11e6f4 100644 --- a/tests/ops_tests.cpp +++ b/tests/ops_tests.cpp @@ -1,4 +1,8 @@ // Copyright © 2023-2024 Apple Inc. + +// Required for using M_PI_2 in MSVC. +#define _USE_MATH_DEFINES + #include #include