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
3 changes: 1 addition & 2 deletions exla/lib/exla/defn.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1141,8 +1141,7 @@ defmodule EXLA.Defn do
end

batch_size = tensor_rank - length(axes)
offset_size = indices_rank - length(axes)
offset_dims = count_up(batch_size, offset_size)
offset_dims = count_up(batch_size, index_vector_dim)

Value.gather(
tensor,
Expand Down
36 changes: 36 additions & 0 deletions exla/test/exla/backend_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,42 @@ defmodule EXLA.BackendTest do
"1.0-0.0i, 2.0+0.0i, 3.0-0.0i, 0.0+1.0i, 0.0+2.0i"
end

test "gather vectorized regression" do
gradients =
Nx.tensor(
[
[1.0, 1.0],
[-1.0, 1.0],
[1.0, -1.0],
[-1.0, -1.0]
],
backend: EXLA.Backend
)

i =
Nx.tensor([[0, 2, 3, 2, 2, 2, 2, 1]], type: {:u, 16}, backend: EXLA.Backend)
|> Nx.vectorize([:x, :octaves])

result = Nx.gather(gradients, Nx.reshape(i, {1}))

assert_equal(
result,
Nx.tensor([
[
[1.0, 1.0],
[1.0, -1.0],
[-1.0, -1.0],
[1.0, -1.0],
[1.0, -1.0],
[1.0, -1.0],
[1.0, -1.0],
[-1.0, 1.0]
]
])
|> Nx.vectorize([:x, :octaves])
)
end

describe "quantized types" do
test "s2" do
tensor = Nx.s2(-1)
Expand Down