mirror of
https://github.com/ml-explore/mlx.git
synced 2025-06-24 09:21:16 +08:00
Fix complex power on Metal (#1460)
This commit is contained in:
parent
e4534dac17
commit
95d04805b3
@ -217,7 +217,7 @@ struct Power {
|
||||
|
||||
template <>
|
||||
complex64_t operator()(complex64_t x, complex64_t y) {
|
||||
auto x_theta = metal::atan(x.imag / x.real);
|
||||
auto x_theta = metal::atan2(x.imag, x.real);
|
||||
auto x_ln_r = 0.5 * metal::log(x.real * x.real + x.imag * x.imag);
|
||||
auto mag = metal::exp(y.real * x_ln_r - y.imag * x_theta);
|
||||
auto phase = y.imag * x_ln_r + y.real * x_theta;
|
||||
|
@ -2553,6 +2553,13 @@ TEST_CASE("test power") {
|
||||
auto out = (power(array(a), array(b))).item<complex64_t>();
|
||||
CHECK(abs(out.real() - expected.real()) < 1e-7);
|
||||
CHECK(abs(out.imag() - expected.imag()) < 1e-7);
|
||||
|
||||
a = complex64_t{-1.2, 0.1};
|
||||
b = complex64_t{2.2, 0.0};
|
||||
expected = std::pow(a, b);
|
||||
out = (power(array(a), array(b))).item<complex64_t>();
|
||||
CHECK(abs(out.real() - expected.real()) < 1e-6);
|
||||
CHECK(abs(out.imag() - expected.imag()) < 1e-6);
|
||||
}
|
||||
|
||||
TEST_CASE("test where") {
|
||||
|
Loading…
Reference in New Issue
Block a user