Skip to content

Support Nx.stack on Ortex tensors - #57

Open
reidmorrison wants to merge 2 commits into
elixir-nx:mainfrom
reidmorrison:backend-stack
Open

reidmorrison wants to merge 2 commits into
elixir-nx:mainfrom
reidmorrison:backend-stack

Conversation

@reidmorrison

@reidmorrison reidmorrison commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Since Nx 0.8, Nx.stack/2 calls the backend's stack/3 instead of using new_axis plus concatenate, so on Nx 0.8 and later (including 1.0) stacking Ortex tensors raises operation stack is not yet supported on Ortex.Backend.

This implements stack/3 the way Nx used to do it: each tensor gets the new axis through the backend's reshape, then they're joined with the existing concatenate. Tests are in test/shape/stack_test.exs. Because stack/3 isn't a callback on Nx 0.6 (the version in mix.lock), @impl is derived from Nx.Backend.behaviour_info/1; a plain @impl true fails --warnings-as-errors there, which the first CI run caught.

On Nx 1.0.0 the new tests fail without the change and pass with it, and the full suite passes with --warnings-as-errors on both Nx 0.6.2 and 1.0.0. CI currently runs Nx 0.6.2, where Nx.stack doesn't reach this code, so the newer-Nx CI job from #56 is what covers it in CI.

Code Review. No findings.

Since Nx 0.8, Nx.stack/2 calls the backend's stack/3 instead of using
new_axis plus concatenate, so stacking Ortex tensors on Nx 0.8 and
later (including 1.0) raised "operation stack is not yet supported on
Ortex.Backend".

Implement it the way Nx did before: give each tensor the new axis with
the backend's reshape, then join them with its concatenate.
Nx 0.6, the version in mix.lock, has no stack/3 backend callback, so
"@impl true" produced a warning and failed
"mix compile --warnings-as-errors" in CI. Derive @impl from
Nx.Backend.behaviour_info/1, which the module already uses for its
unimplemented callbacks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant