Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions python/src/ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3386,14 +3386,14 @@ void init_ops(nb::module_& m) {
mx::StreamOrDevice s) {
std::vector<mx::array> arrays =
nb::cast<std::vector<mx::array>>(arrays_);
return mx::meshgrid(arrays, sparse, indexing, s);
return nb::tuple(nb::cast(mx::meshgrid(arrays, sparse, indexing, s)));

@zcbenz zcbenz Aug 13, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would nb::cast<nb::tuple>() work?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so.

error: no matching function for call to 'cast'
note: candidate not viable: no known conversion from 'std::vector<array>' to 'nb::tuple'

},
"arrays"_a,
"sparse"_a = false,
"indexing"_a = "xy",
"stream"_a = nb::none(),
nb::sig(
"def meshgrid(*arrays: array, sparse: bool | None = False, indexing: str | None = 'xy', stream: StreamOrDevice = None) -> array"),
"def meshgrid(*arrays: array, sparse: bool | None = False, indexing: str | None = 'xy', stream: StreamOrDevice = None) -> tuple[array, ...]"),
R"pbdoc(
Generate multidimensional coordinate grids from 1-D coordinate arrays

Expand All @@ -3406,7 +3406,7 @@ void init_ops(nb::module_& m) {
Defaults to ``'xy'``.

Returns:
list(array): The output arrays.
tuple(array): The output arrays.
)pbdoc");
m.def(
"repeat",
Expand Down
5 changes: 5 additions & 0 deletions python/tests/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -2132,6 +2132,11 @@ def test_meshgrid(self):
x = mx.array([1, 2, 3], dtype=mx.int32)
y = np.array([1, 2, 3], dtype=np.int32)

# Test return type is a tuple
self.assertIsInstance(mx.meshgrid(x), tuple)
self.assertIsInstance(mx.meshgrid(x, x), tuple)
self.assertIsInstance(mx.meshgrid(x, x, x, sparse=True), tuple)

# Test single input
a_mlx = mx.meshgrid(x)
a_np = np.meshgrid(y)
Expand Down
Loading