Beginner question here:
I want to process all elements in a given tensor in a loop (or one go). As far as i understand, in Elixir you cannot access variables from outer scopes. So the following code does nothing:
def update_all_cells(world) do
shape = Nx.shape(world)
rows = elem(shape, 0)
columns = elem(shape, 1)
# we need a temp_world because we cannot update the world
# as we need it to calculate the next state
temp_world = fn (world, rows, columns) ->
temp_world = Nx.tensor(world, names: [:x, :y, :cell_info], type: {:s, 64})
Enum.each(0..rows-1, fn x ->
Enum.each(0..columns-1, fn y ->
updated_cell = update_cell(world, x, y)
temp_world = update_world(world, x, y, updated_cell)
end)
end)
temp_world
end
temp_world.(world, rows, columns)
end
I understand that I need to use something like Enum.map, however that only works for enumerables and so does not work for Nx.tensors. I saw that there is Nx.map…
I can call something like Nx.map(world[cell_info: 0..-1//1], fn x -> some_function(x) end)
however I still need to define my variables and update them somehow. I am kind of lost here
Can somebody help me?