| 6197 | } |
| 6198 | |
| 6199 | array bitwise_impl( |
| 6200 | const array& a, |
| 6201 | const array& b, |
| 6202 | BitwiseBinary::Op op, |
| 6203 | const std::string& op_name, |
| 6204 | const StreamOrDevice& s, |
| 6205 | std::optional<Dtype> out_type_ = std::nullopt) { |
| 6206 | auto out_type = out_type_ ? *out_type_ : promote_types(a.dtype(), b.dtype()); |
| 6207 | if (!(issubdtype(out_type, integer) || out_type == bool_)) { |
| 6208 | std::ostringstream msg; |
| 6209 | msg << "[" << op_name |
| 6210 | << "] Only allowed on integer or boolean types " |
| 6211 | "but got types " |
| 6212 | << a.dtype() << " and " << b.dtype() << "."; |
| 6213 | throw std::runtime_error(msg.str()); |
| 6214 | } |
| 6215 | auto inputs = |
| 6216 | broadcast_arrays({astype(a, out_type, s), astype(b, out_type, s)}, s); |
| 6217 | auto& out_shape = inputs[0].shape(); |
| 6218 | return array( |
| 6219 | out_shape, |
| 6220 | out_type, |
| 6221 | std::make_shared<BitwiseBinary>(to_stream(s), op), |
| 6222 | std::move(inputs)); |
| 6223 | } |
| 6224 | |
| 6225 | array bitwise_and(const array& a, const array& b, StreamOrDevice s /* = {} */) { |
| 6226 | return bitwise_impl(a, b, BitwiseBinary::Op::And, "bitwise_and", s); |
no test coverage detected