@@ -33,7 +33,7 @@ int check_shape_dim(int64_t dim) {
3333
3434template <typename T>
3535mx::array nd_array_to_mlx_contiguous (
36- nb::ndarray<nb::ro, nb::c_contig, nb::device::cpu > nd_array,
36+ nb::ndarray<nb::ro, nb::c_contig> nd_array,
3737 const mx::Shape& shape,
3838 mx::Dtype dtype) {
3939 // Make a copy of the numpy buffer
@@ -43,9 +43,14 @@ mx::array nd_array_to_mlx_contiguous(
4343}
4444
4545mx::array nd_array_to_mlx (
46- nb::ndarray<nb::ro, nb::c_contig, nb::device::cpu > nd_array,
46+ nb::ndarray<nb::ro, nb::c_contig> nd_array,
4747 std::optional<mx::Dtype> dtype,
4848 std::optional<nb::dlpack::dtype> nb_dtype) {
49+ if (nd_array.device_type () != nb::device::cpu::value) {
50+ throw std::invalid_argument (
51+ " Cannot convert non-CPU DLPack array to mlx array." );
52+ }
53+
4954 // Compute the shape and size
5055 mx::Shape shape;
5156 shape.reserve (nd_array.ndim ());
@@ -495,7 +500,7 @@ mx::array create_array(nb::object v, std::optional<mx::Dtype> t) {
495500 auto arr = nb::cast<mx::array>(v);
496501 return mx::astype (arr, t.value_or (arr.dtype ()));
497502 } else if (nb::ndarray_check (v)) {
498- using ContigArray = nb::ndarray<nb::ro, nb::c_contig, nb::device::cpu >;
503+ using ContigArray = nb::ndarray<nb::ro, nb::c_contig>;
499504 ContigArray nd;
500505 std::optional<nb::dlpack::dtype> nb_dtype;
501506 // Nanobind does not recognize bfloat16 numpy array:
0 commit comments