Bitwise Inverse (#1862)

* add bitwise inverse

* add vmap + fix nojit

* inverse -> invert

* add to compile + remove unused
This commit is contained in:
Alex Barron
2025-02-13 08:44:14 -08:00
committed by GitHub
parent e425dc00c0
commit 5cd97f7ffe
19 changed files with 147 additions and 8 deletions

View File

@@ -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;