Skip to content

Commit 72cde9a

Browse files
authored
[API Compatibility No.48、63、74、215、235] Add parameter alias support for column_stack,dstack,hstack,row_stack,vstack - part (PaddlePaddle#78069)
* fix * fix * fix
1 parent 8eadb31 commit 72cde9a

File tree

2 files changed

+346
-5
lines changed

2 files changed

+346
-5
lines changed

python/paddle/tensor/manipulation.py

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,7 +2379,13 @@ def stack(
23792379
return out
23802380

23812381

2382-
def hstack(x: Sequence[Tensor], name: str | None = None) -> Tensor:
2382+
@param_one_alias(["x", "tensors"])
2383+
def hstack(
2384+
x: Sequence[Tensor],
2385+
name: str | None = None,
2386+
*,
2387+
out: Tensor | None = None,
2388+
) -> Tensor:
23832389
"""
23842390
Stacks all the input tensors ``x`` along horizontal axis.
23852391
All tensors must be of the same dtype.
@@ -2394,8 +2400,12 @@ def hstack(x: Sequence[Tensor], name: str | None = None) -> Tensor:
23942400
Args:
23952401
x (list[Tensor]|tuple[Tensor]): Input ``x`` can be a ``list`` or ``tuple`` of tensors, the Tensors in ``x`` must be of the same
23962402
shape and dtype. Supported data types: ``float16``, ``float32``, ``float64``, ``int8``, ``int32``, ``int64`` or ``bfloat16``.
2403+
Alias: ``tensors``.
23972404
name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
23982405
2406+
Keyword args:
2407+
out(Tensor, optional): The output tensor.
2408+
23992409
Returns:
24002410
Tensor, The stacked tensor with same data type as input.
24012411
@@ -2447,7 +2457,13 @@ def hstack(x: Sequence[Tensor], name: str | None = None) -> Tensor:
24472457
return paddle.concat(arrays, axis=1, name=name)
24482458

24492459

2450-
def vstack(x: Sequence[Tensor], name: str | None = None) -> Tensor:
2460+
@param_one_alias(["x", "tensors"])
2461+
def vstack(
2462+
x: Sequence[Tensor],
2463+
name: str | None = None,
2464+
*,
2465+
out: Tensor | None = None,
2466+
) -> Tensor:
24512467
"""
24522468
Stacks all the input tensors ``x`` along vertical axis.
24532469
All tensors must be of the same dtype.
@@ -2462,8 +2478,12 @@ def vstack(x: Sequence[Tensor], name: str | None = None) -> Tensor:
24622478
Args:
24632479
x (list[Tensor]|tuple[Tensor]): Input ``x`` can be a ``list`` or ``tuple`` of tensors, the Tensors in ``x`` must be of the same
24642480
shape and dtype. Supported data types: ``float16``, ``float32``, ``float64``, ``int8``, ``int32``, ``int64`` or ``bfloat16``.
2481+
Alias: ``tensors``.
24652482
name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
24662483
2484+
Keyword args:
2485+
out(Tensor, optional): The output tensor.
2486+
24672487
Returns:
24682488
Tensor, The stacked tensor with same data type as input.
24692489
@@ -2516,16 +2536,26 @@ def vstack(x: Sequence[Tensor], name: str | None = None) -> Tensor:
25162536
return paddle.concat(arrays, axis=0, name=name)
25172537

25182538

2519-
def dstack(x: Sequence[Tensor], name: str | None = None) -> Tensor:
2539+
@param_one_alias(["x", "tensors"])
2540+
def dstack(
2541+
x: Sequence[Tensor],
2542+
name: str | None = None,
2543+
*,
2544+
out: Tensor | None = None,
2545+
) -> Tensor:
25202546
"""
25212547
Stacks all the input tensors ``x`` along depth axis.
25222548
All tensors must be of the same dtype.
25232549
25242550
Args:
25252551
x (list[Tensor]|tuple[Tensor]): Input ``x`` can be a ``list`` or ``tuple`` of tensors, the Tensors in ``x`` must be of the same
25262552
shape and dtype. Supported data types: ``float16``, ``float32``, ``float64``, ``int8``, ``int32``, ``int64`` or ``bfloat16``.
2553+
Alias: ``tensors``.
25272554
name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
25282555
2556+
Keyword args:
2557+
out(Tensor, optional): The output tensor.
2558+
25292559
Returns:
25302560
Tensor, The stacked tensor with same data type as input.
25312561
@@ -2569,7 +2599,13 @@ def dstack(x: Sequence[Tensor], name: str | None = None) -> Tensor:
25692599
return paddle.concat(arrays, axis=2, name=name)
25702600

25712601

2572-
def column_stack(x: Sequence[Tensor], name: str | None = None) -> Tensor:
2602+
@param_one_alias(["x", "tensors"])
2603+
def column_stack(
2604+
x: Sequence[Tensor],
2605+
name: str | None = None,
2606+
*,
2607+
out: Tensor | None = None,
2608+
) -> Tensor:
25732609
"""
25742610
Stacks all the input tensors ``x`` along horizontal axis. Each tensor in ``x`` will be first reshaped into ``(tensor.numel(), 1)``
25752611
if ``tensor.ndim < 2`` before being stacked.
@@ -2578,8 +2614,12 @@ def column_stack(x: Sequence[Tensor], name: str | None = None) -> Tensor:
25782614
Args:
25792615
x (list[Tensor]|tuple[Tensor]): Input ``x`` can be a ``list`` or ``tuple`` of tensors, the Tensors in ``x`` must be of the same
25802616
shape and dtype. Supported data types: ``float16``, ``float32``, ``float64``, ``int32``, ``int64`` or ``bfloat16``.
2617+
Alias: ``tensors``.
25812618
name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
25822619
2620+
Keyword args:
2621+
out(Tensor, optional): The output tensor.
2622+
25832623
Returns:
25842624
Tensor, The stacked tensor with same data type as input.
25852625
@@ -2629,7 +2669,13 @@ def column_stack(x: Sequence[Tensor], name: str | None = None) -> Tensor:
26292669
return paddle.concat(arrays, axis=1, name=name)
26302670

26312671

2632-
def row_stack(x: Sequence[Tensor], name: str | None = None) -> Tensor:
2672+
@param_one_alias(["x", "tensors"])
2673+
def row_stack(
2674+
x: Sequence[Tensor],
2675+
name: str | None = None,
2676+
*,
2677+
out: Tensor | None = None,
2678+
) -> Tensor:
26332679
"""
26342680
Alias of `paddle.vstack()`.
26352681
Stacks all the input tensors ``x`` along vertical axis.
@@ -2638,8 +2684,13 @@ def row_stack(x: Sequence[Tensor], name: str | None = None) -> Tensor:
26382684
Args:
26392685
x (list[Tensor]|tuple[Tensor]): Input ``x`` can be a ``list`` or ``tuple`` of tensors, the Tensors in ``x`` must be of the same
26402686
shape and dtype. Supported data types: ``float16``, ``float32``, ``float64``, ``int8``, ``int32``, ``int64`` or ``bfloat16``.
2687+
Alias: ``tensors``.
26412688
name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
26422689
2690+
Keyword args:
2691+
out(Tensor, optional): The output tensor.
2692+
2693+
26432694
Returns:
26442695
Tensor, The stacked tensor with same data type as input.
26452696

0 commit comments

Comments
 (0)