| 42 | } |
| 43 | |
| 44 | inline 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 | |
| 57 | inline nb::handle get_handle_of_object(const ScalarOrArray& v) { |
| 58 | return std::get<ArrayLike>(v).obj.ptr(); |