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

Function is_comparable_with_array

python/src/utils.h:44–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44inline bool is_comparable_with_array(const ScalarOrArray& v) {
45 // Checks if the value can be compared to an array (or is already an
46 // mlx array)
47 if (auto pv = std::get_if<ArrayLike>(&v); pv) {
48 auto obj = (*pv).obj;
49 return nb::isinstance<mx::array>(obj) || nb::hasattr(obj, "__mlx_array__");
50 } else {
51 // If it's not an object, it's a scalar (nb::int_, nb::float_, etc.)
52 // and can be compared to an array
53 return true;
54 }
55}
56
57inline nb::handle get_handle_of_object(const ScalarOrArray& v) {
58 return std::get<ArrayLike>(v).obj.ptr();

Callers 1

init_arrayFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected