| 116 | |
| 117 | template <typename... NDParams> |
| 118 | nb::ndarray<NDParams...> mlx_to_nd_array(const mx::array& a) { |
| 119 | switch (a.dtype()) { |
| 120 | case mx::bool_: |
| 121 | return mlx_to_nd_array_impl<bool, NDParams...>(a); |
| 122 | case mx::uint8: |
| 123 | return mlx_to_nd_array_impl<uint8_t, NDParams...>(a); |
| 124 | case mx::uint16: |
| 125 | return mlx_to_nd_array_impl<uint16_t, NDParams...>(a); |
| 126 | case mx::uint32: |
| 127 | return mlx_to_nd_array_impl<uint32_t, NDParams...>(a); |
| 128 | case mx::uint64: |
| 129 | return mlx_to_nd_array_impl<uint64_t, NDParams...>(a); |
| 130 | case mx::int8: |
| 131 | return mlx_to_nd_array_impl<int8_t, NDParams...>(a); |
| 132 | case mx::int16: |
| 133 | return mlx_to_nd_array_impl<int16_t, NDParams...>(a); |
| 134 | case mx::int32: |
| 135 | return mlx_to_nd_array_impl<int32_t, NDParams...>(a); |
| 136 | case mx::int64: |
| 137 | return mlx_to_nd_array_impl<int64_t, NDParams...>(a); |
| 138 | case mx::float16: |
| 139 | return mlx_to_nd_array_impl<mx::float16_t, NDParams...>(a); |
| 140 | case mx::bfloat16: |
| 141 | throw nb::type_error("bfloat16 arrays cannot be converted to NumPy."); |
| 142 | case mx::float32: |
| 143 | return mlx_to_nd_array_impl<float, NDParams...>(a); |
| 144 | case mx::float64: |
| 145 | return mlx_to_nd_array_impl<double, NDParams...>(a); |
| 146 | case mx::complex64: |
| 147 | return mlx_to_nd_array_impl<std::complex<float>, NDParams...>(a); |
| 148 | default: |
| 149 | throw nb::type_error("type cannot be converted to NumPy."); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | nb::ndarray<nb::numpy> mlx_to_np_array(const mx::array& a) { |
| 154 | return mlx_to_nd_array<nb::numpy>(a); |
nothing calls this directly
no outgoing calls
no test coverage detected