Real and Imag (#1490)

* real and imag

* fix

* fix
This commit is contained in:
Awni Hannun
2024-10-15 16:23:15 -07:00
committed by GitHub
parent 2b8ace6a03
commit 3f86399922
21 changed files with 275 additions and 46 deletions

View File

@@ -4657,4 +4657,18 @@ array roll(
return roll(a, std::vector<int>{total_shift}, std::vector<int>{axis}, s);
}
array real(const array& a, StreamOrDevice s /* = {} */) {
if (!issubdtype(a.dtype(), complexfloating)) {
return a;
}
return array(a.shape(), float32, std::make_shared<Real>(to_stream(s)), {a});
}
array imag(const array& a, StreamOrDevice s /* = {} */) {
if (!issubdtype(a.dtype(), complexfloating)) {
return zeros_like(a);
}
return array(a.shape(), float32, std::make_shared<Imag>(to_stream(s)), {a});
}
} // namespace mlx::core