Add asarray to __array_namespace__ (#2966)

This commit is contained in:
Anri Lombard
2026-01-12 16:16:27 +02:00
committed by GitHub
parent 46ee0e9068
commit edab937248
2 changed files with 71 additions and 0 deletions
+19
View File
@@ -1668,6 +1668,25 @@ void init_ops(nb::module_& m) {
Returns:
array: The array of zeros with the specified shape.
)pbdoc");
m.def(
"asarray",
[](const ArrayInitType& a, std::optional<mx::Dtype> dtype) {
return create_array(a, dtype);
},
nb::arg(),
"dtype"_a = nb::none(),
nb::sig("def asarray(a: Union[scalar, array, Sequence], dtype: "
"Optional[Dtype] = None) -> array"),
R"pbdoc(
Convert the input to an array.
Args:
a: Input data.
dtype (Dtype, optional): The desired data-type for the array.
Returns:
array: An array interpretation of the input.
)pbdoc");
m.def(
"zeros_like",
&mx::zeros_like,