MCPcopy Create free account
hub / github.com/ml-explore/mlx / bitwise_impl

Function bitwise_impl

mlx/ops.cpp:6199–6223  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6197}
6198
6199array 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
6225array bitwise_and(const array& a, const array& b, StreamOrDevice s /* = {} */) {
6226 return bitwise_impl(a, b, BitwiseBinary::Op::And, "bitwise_and", s);

Callers 5

bitwise_andFunction · 0.85
bitwise_orFunction · 0.85
bitwise_xorFunction · 0.85
left_shiftFunction · 0.85
right_shiftFunction · 0.85

Calls 6

promote_typesFunction · 0.85
issubdtypeFunction · 0.85
broadcast_arraysFunction · 0.85
astypeFunction · 0.85
to_streamFunction · 0.85
arrayFunction · 0.70

Tested by

no test coverage detected