mirror of
https://github.com/ml-explore/mlx.git
synced 2025-12-16 01:49:05 +08:00
Bitwise Inverse (#1862)
* add bitwise inverse * add vmap + fix nojit * inverse -> invert * add to compile + remove unused
This commit is contained in:
15
mlx/ops.cpp
15
mlx/ops.cpp
@@ -4853,6 +4853,21 @@ array operator>>(const array& a, const array& b) {
|
||||
return right_shift(a, b);
|
||||
}
|
||||
|
||||
array bitwise_invert(const array& a, StreamOrDevice s /* = {} */) {
|
||||
if (issubdtype(a.dtype(), inexact)) {
|
||||
throw std::invalid_argument(
|
||||
"[bitwise_invert] Bitwise inverse only allowed on integer types.");
|
||||
} else if (a.dtype() == bool_) {
|
||||
return logical_not(a, s);
|
||||
}
|
||||
return array(
|
||||
a.shape(), a.dtype(), std::make_shared<BitwiseInvert>(to_stream(s)), {a});
|
||||
}
|
||||
|
||||
array operator~(const array& a) {
|
||||
return bitwise_invert(a);
|
||||
}
|
||||
|
||||
array view(const array& a, const Dtype& dtype, StreamOrDevice s /* = {} */) {
|
||||
if (a.dtype() == dtype) {
|
||||
return a;
|
||||
|
||||
Reference in New Issue
Block a user