Skip to content

Commit 246fcab

Browse files
committed
Fix deprecation warnings
1 parent 749630f commit 246fcab

File tree

6 files changed

+24
-17
lines changed

6 files changed

+24
-17
lines changed

nx/lib/nx.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ defmodule Nx do
13051305
out =
13061306
case shape do
13071307
{n} ->
1308-
intermediate_shape = Tuple.duplicate(1, tuple_size(out_shape) - 1) |> Tuple.append(n)
1308+
intermediate_shape = Tuple.duplicate(1, tuple_size(out_shape) - 1) |> tuple_append(n)
13091309

13101310
backend.eye(
13111311
%T{type: type, shape: intermediate_shape, names: names},
@@ -1609,7 +1609,7 @@ defmodule Nx do
16091609
t
16101610
else
16111611
diag_length = div(Nx.size(t), Tuple.product(batch_shape))
1612-
Nx.reshape(t, Tuple.append(batch_shape, diag_length))
1612+
Nx.reshape(t, tuple_append(batch_shape, diag_length))
16131613
end
16141614
end
16151615

@@ -10365,9 +10365,9 @@ defmodule Nx do
1036510365
if opts[:keep_axis] do
1036610366
new_shape
1036710367
|> Tuple.delete_at(tuple_size(new_shape) - 1)
10368-
|> Tuple.append(:auto)
10368+
|> tuple_append(:auto)
1036910369
else
10370-
Tuple.append(new_shape, :auto)
10370+
tuple_append(new_shape, :auto)
1037110371
end
1037210372

1037310373
reshaped_tensor = reshape(tensor, flattened_shape)
@@ -13554,7 +13554,7 @@ defmodule Nx do
1355413554
end)
1355513555
|> Nx.stack()
1355613556
|> Nx.revectorize(vectorized_axes,
13557-
target_shape: Tuple.append(List.to_tuple(lengths), :auto)
13557+
target_shape: tuple_append(List.to_tuple(lengths), :auto)
1355813558
)
1355913559

1356013560
Nx.gather(tensor, idx)
@@ -14288,7 +14288,7 @@ defmodule Nx do
1428814288
Nx.Shared.optional(:take_along_axis, [tensor, indices, [axis: axis]], out, fn
1428914289
tensor, indices, _opts ->
1429014290
axes_range = axes(indices)
14291-
new_axis_shape = Tuple.append(shape(indices), 1)
14291+
new_axis_shape = tuple_append(shape(indices), 1)
1429214292

1429314293
full_indices =
1429414294
axes_range
@@ -14471,7 +14471,7 @@ defmodule Nx do
1447114471
indices = devectorize(indices, keep_names: false)
1447214472

1447314473
iota_shape =
14474-
indices.shape |> Tuple.delete_at(tuple_size(indices.shape) - 1) |> Tuple.append(1)
14474+
indices.shape |> Tuple.delete_at(tuple_size(indices.shape) - 1) |> tuple_append(1)
1447514475

1447614476
offset_axes = (offset - 1)..0//-1
1447714477

nx/lib/nx/binary_backend.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ defmodule Nx.BinaryBackend do
14921492
dilations = opts[:window_dilations]
14931493

14941494
%T{shape: padded_shape, type: {_, size} = type} =
1495-
tensor = Nx.pad(tensor, acc, Enum.map(padding_config, &Tuple.append(&1, 0)))
1495+
tensor = Nx.pad(tensor, acc, Enum.map(padding_config, &tuple_append(&1, 0)))
14961496

14971497
acc = scalar_to_number(acc)
14981498

@@ -1608,7 +1608,7 @@ defmodule Nx.BinaryBackend do
16081608
init_value = scalar_to_number(init_value)
16091609

16101610
%T{shape: padded_shape, type: {_, size} = type} =
1611-
tensor = Nx.pad(t, init_value, Enum.map(padding, &Tuple.append(&1, 0)))
1611+
tensor = Nx.pad(t, init_value, Enum.map(padding, &tuple_append(&1, 0)))
16121612

16131613
input_data = to_binary(tensor)
16141614
input_weighted_shape = weighted_shape(padded_shape, size, window_dimensions)
@@ -2262,7 +2262,7 @@ defmodule Nx.BinaryBackend do
22622262
<<write_complex(re, im, div(output_size, 2))::binary>>
22632263
end
22642264

2265-
intermediate_shape = out.shape |> Tuple.delete_at(axis) |> Tuple.append(n)
2265+
intermediate_shape = out.shape |> Tuple.delete_at(axis) |> tuple_append(n)
22662266

22672267
permuted_output = from_binary(%{out | shape: intermediate_shape}, output_data)
22682268

nx/lib/nx/defn/grad.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ defmodule Nx.Defn.Grad do
11571157

11581158
num_axes = tuple_size(window_dimensions)
11591159

1160-
indices = Nx.reshape(indices_to_flatten, Tuple.append(source.shape, num_axes))
1160+
indices = Nx.reshape(indices_to_flatten, Nx.Shared.tuple_append(source.shape, num_axes))
11611161

11621162
dsource = Nx.gather(g, indices)
11631163
dtensor = Nx.broadcast(0, tensor)
@@ -1490,7 +1490,7 @@ defmodule Nx.Defn.Grad do
14901490
end
14911491

14921492
defp grad_scatter_window__gather_windows(tensor, window_dimensions, strides, padding) do
1493-
tensor = Nx.pad(tensor, 0, Enum.map(padding, &Tuple.append(&1, 0)))
1493+
tensor = Nx.pad(tensor, 0, Enum.map(padding, &Nx.Shared.tuple_append(&1, 0)))
14941494

14951495
shape_l = Tuple.to_list(tensor.shape)
14961496
window_dims_l = Tuple.to_list(window_dimensions)

nx/lib/nx/lin_alg/svd.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ defmodule Nx.LinAlg.SVD do
5959

6060
collapsed_axes = shape |> Tuple.delete_at(rank - 2) |> Tuple.delete_at(rank - 2)
6161

62-
u_shape = collapsed_axes |> Tuple.append(m) |> Tuple.append(:auto)
63-
s_shape = Tuple.append(collapsed_axes, :auto)
64-
vt_shape = Tuple.append(s_shape, n)
62+
u_shape = collapsed_axes |> Nx.Shared.tuple_append(m) |> Nx.Shared.tuple_append(:auto)
63+
s_shape = Nx.Shared.tuple_append(collapsed_axes, :auto)
64+
vt_shape = Nx.Shared.tuple_append(s_shape, n)
6565

6666
{{m, n}, u_shape, s_shape, vt_shape}
6767
end

nx/lib/nx/random.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ defmodule Nx.Random do
746746
{dim}
747747

748748
dims when is_tuple(dims) ->
749-
Tuple.append(dims, dim)
749+
Nx.Shared.tuple_append(dims, dim)
750750

751751
_ ->
752752
raise ArgumentError,
@@ -1126,7 +1126,7 @@ defmodule Nx.Random do
11261126
case type do
11271127
{:c, _} ->
11281128
type = Nx.Type.to_real(type)
1129-
data = fun.(key, type, Tuple.append(shape, 2))
1129+
data = fun.(key, type, Nx.Shared.tuple_append(shape, 2))
11301130
to_complex = Nx.stack([1, Nx.Constants.i()])
11311131
Nx.dot(data, to_complex)
11321132

nx/lib/nx/shared.ex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,13 @@ defmodule Nx.Shared do
445445

446446
## Helpers
447447

448+
@doc """
449+
Appends an element to a tuple.
450+
"""
451+
def tuple_append(tuple, elem) do
452+
Tuple.insert_at(tuple, tuple_size(tuple), elem)
453+
end
454+
448455
@doc """
449456
Extracts the backend from the given options.
450457
"""

0 commit comments

Comments
 (0)