mirror of
https://github.com/ml-explore/mlx.git
synced 2025-06-25 18:11:15 +08:00
metal: add complex log1p
This commit is contained in:
parent
e444e2cbc0
commit
0cdccd54ae
@ -74,6 +74,7 @@ instantiate_unary_all_same(Cos, complex64, complex64_t)
|
|||||||
instantiate_unary_all_same(Cosh, complex64, complex64_t)
|
instantiate_unary_all_same(Cosh, complex64, complex64_t)
|
||||||
instantiate_unary_all_same(Exp, complex64, complex64_t)
|
instantiate_unary_all_same(Exp, complex64, complex64_t)
|
||||||
instantiate_unary_all_same(Log, complex64, complex64_t)
|
instantiate_unary_all_same(Log, complex64, complex64_t)
|
||||||
|
instantiate_unary_all_same(Log1p, complex64, complex64_t)
|
||||||
instantiate_unary_all_same(Log2, complex64, complex64_t)
|
instantiate_unary_all_same(Log2, complex64, complex64_t)
|
||||||
instantiate_unary_all_same(Log10, complex64, complex64_t)
|
instantiate_unary_all_same(Log10, complex64, complex64_t)
|
||||||
instantiate_unary_all_same(Negative, complex64, complex64_t)
|
instantiate_unary_all_same(Negative, complex64, complex64_t)
|
||||||
|
@ -328,6 +328,23 @@ inline bfloat16_t log1p(bfloat16_t x) {
|
|||||||
return bfloat16_t(x * (metal::log(xp1) / (xp1 - 1.0f)));
|
return bfloat16_t(x * (metal::log(xp1) / (xp1 - 1.0f)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline complex64_t log1p(complex64_t in) {
|
||||||
|
float x = in.real;
|
||||||
|
float y = in.imag;
|
||||||
|
float zabs = metal::precise::sqrt(x * x + y * y);
|
||||||
|
float theta = metal::atan2(y, x + 1);
|
||||||
|
if (zabs < 0.5f) {
|
||||||
|
float r = x * (2 + x) + y * y;
|
||||||
|
if (r == 0) { // handle underflow
|
||||||
|
return {x, theta};
|
||||||
|
}
|
||||||
|
return {0.5f * log1p(r), theta};
|
||||||
|
} else {
|
||||||
|
auto z0 = metal::sqrt((x + 1) * (x + 1) + y * y);
|
||||||
|
return {metal::log(z0), theta};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// SIMD shuffle ops
|
// SIMD shuffle ops
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
Loading…
Reference in New Issue
Block a user