|
|
|
@ -107,6 +107,7 @@ __all__ = [
|
|
|
|
|
'squeeze',
|
|
|
|
|
'unsqueeze',
|
|
|
|
|
'lod_reset',
|
|
|
|
|
'lod_append',
|
|
|
|
|
'lrn',
|
|
|
|
|
'pad',
|
|
|
|
|
'pad_constant_like',
|
|
|
|
@ -6980,7 +6981,7 @@ def lod_reset(x, y=None, target_lod=None):
|
|
|
|
|
considered as target LoD first, otherwise :attr:`y.data` would be
|
|
|
|
|
considered as target LoD. If :attr:`y` is not provided, target LoD should
|
|
|
|
|
be specified by :attr:`target_lod`. If target LoD is specified by
|
|
|
|
|
:attr:`Y.data` or :attr:`target_lod`, only one level LoD is supported.
|
|
|
|
|
:attr:`y.data` or :attr:`target_lod`, only one level LoD is supported.
|
|
|
|
|
|
|
|
|
|
.. code-block:: text
|
|
|
|
|
|
|
|
|
@ -7032,7 +7033,7 @@ def lod_reset(x, y=None, target_lod=None):
|
|
|
|
|
out.dims = [6, 1]
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
x (Variable): Input variable which could be a Tensor or LodTensor.
|
|
|
|
|
x (Variable): Input variable which could be a Tensor or LoDTensor.
|
|
|
|
|
y (Variable|None): If provided, output's LoD would be derived
|
|
|
|
|
from :attr:`y`.
|
|
|
|
|
target_lod (list|tuple|None): One level LoD which should be considered
|
|
|
|
@ -7065,8 +7066,60 @@ def lod_reset(x, y=None, target_lod=None):
|
|
|
|
|
attrs={'target_lod': target_lod},
|
|
|
|
|
outputs={'Out': out})
|
|
|
|
|
else:
|
|
|
|
|
raise ValueError("y and target_lod should not be both None.")
|
|
|
|
|
raise ValueError("y and target_lod should not be both none.")
|
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def lod_append(x, level):
|
|
|
|
|
"""
|
|
|
|
|
Append level to LoD of :attr:`x`.
|
|
|
|
|
|
|
|
|
|
.. code-block:: text
|
|
|
|
|
|
|
|
|
|
* Example 1:
|
|
|
|
|
|
|
|
|
|
given a 1-level LoDTensor x:
|
|
|
|
|
x.lod = [[ 2, 3, 1 ]]
|
|
|
|
|
x.data = [[1.0], [2.0], [3.0], [4.0], [5.0], [6.0]]
|
|
|
|
|
x.dims = [6, 1]
|
|
|
|
|
|
|
|
|
|
level: [1, 1, 1, 1, 1, 1, 1]
|
|
|
|
|
|
|
|
|
|
then we get a 2-level LoDTensor:
|
|
|
|
|
x.lod = [[ 2, 3, 1 ], [1, 1, 1, 1, 1, 1]]
|
|
|
|
|
x.data = [[1.0], [2.0], [3.0], [4.0], [5.0], [6.0]]
|
|
|
|
|
x.dims = [6, 1]
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
x (Variable): Input variable which could be a tensor or LoDTensor.
|
|
|
|
|
level (list|tuple): The LoD level to be appended into LoD of x.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
Variable: Output variable with new LoD level.
|
|
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
|
ValueError: If :attr:`y` is None or and :attr:`level` is not Iterator.
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
import paddle.fluid as fluid
|
|
|
|
|
x = fluid.layers.data(name='x', shape=[6, 10], lod_level=1)
|
|
|
|
|
out = fluid.layers.lod_append(x, [1,1,1,1,1,1])
|
|
|
|
|
"""
|
|
|
|
|
from collections import Iterable
|
|
|
|
|
if x is None:
|
|
|
|
|
raise ValueError("Input(x) can't be None.")
|
|
|
|
|
if not isinstance(level, Iterable):
|
|
|
|
|
raise ValueError("Input(level) must be list or tuple.")
|
|
|
|
|
helper = LayerHelper("lod_append", **locals())
|
|
|
|
|
out = helper.create_variable_for_type_inference(dtype=x.dtype)
|
|
|
|
|
helper.append_op(
|
|
|
|
|
type="lod_reset",
|
|
|
|
|
inputs={'X': x},
|
|
|
|
|
attrs={'target_lod': level,
|
|
|
|
|
'append': True},
|
|
|
|
|
outputs={'Out': out})
|
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|