|
|
@ -822,17 +822,25 @@ def max_sequence_len(rank_table):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def lod_tensor_to_array(x, table):
|
|
|
|
def lod_tensor_to_array(x, table):
|
|
|
|
""" Convert a LOD_TENSOR to an LOD_TENSOR_ARRAY.
|
|
|
|
"""
|
|
|
|
|
|
|
|
Convert a LoDTensor to a LoDTensorArray.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This function split a LoDTesnor to a LoDTensorArray according to its LoD
|
|
|
|
|
|
|
|
information. LoDTensorArray is an alias of C++ std::vector<LoDTensor> in
|
|
|
|
|
|
|
|
PaddlePaddle. The generated LoDTensorArray of this function can be further read
|
|
|
|
|
|
|
|
or written by `read_from_array()` and `write_to_array()` operators. However,
|
|
|
|
|
|
|
|
this function is generally an internal component of PaddlePaddle `DynamicRNN`.
|
|
|
|
|
|
|
|
Users should not use it directly.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
Args:
|
|
|
|
x (Variable|list): The LOD tensor to be converted to a LOD tensor array.
|
|
|
|
x (Variable|list): The LoDTensor to be converted to a LoDTensorArray.
|
|
|
|
table (ParamAttr|list): The variable that stores the level of lod
|
|
|
|
table (ParamAttr|list): The variable that stores the level of lod
|
|
|
|
which is ordered by sequence length in
|
|
|
|
which is ordered by sequence length in
|
|
|
|
descending order.
|
|
|
|
descending order. It is generally generated
|
|
|
|
|
|
|
|
by `layers.lod_rank_table()` API.
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
|
Variable: The variable of type array that has been converted from a
|
|
|
|
Variable: The LoDTensorArray that has been converted from the input tensor.
|
|
|
|
tensor.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
Examples:
|
|
|
|
.. code-block:: python
|
|
|
|
.. code-block:: python
|
|
|
@ -897,8 +905,7 @@ def increment(x, value=1.0, in_place=True):
|
|
|
|
in_place (bool): If the increment should be performed in-place.
|
|
|
|
in_place (bool): If the increment should be performed in-place.
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
|
Variable: The tensor variable storing the transformation of
|
|
|
|
Variable: The elementwise-incremented object.
|
|
|
|
element-wise increment of each value in the input.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
Examples:
|
|
|
|
.. code-block:: python
|
|
|
|
.. code-block:: python
|
|
|
@ -940,7 +947,7 @@ def array_write(x, i, array=None):
|
|
|
|
Variable: The output LOD_TENSOR_ARRAY where the input tensor is written.
|
|
|
|
Variable: The output LOD_TENSOR_ARRAY where the input tensor is written.
|
|
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
Examples:
|
|
|
|
.. code-block::python
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
|
|
tmp = fluid.layers.zeros(shape=[10], dtype='int32')
|
|
|
|
tmp = fluid.layers.zeros(shape=[10], dtype='int32')
|
|
|
|
i = fluid.layers.fill_constant(shape=[1], dtype='int64', value=10)
|
|
|
|
i = fluid.layers.fill_constant(shape=[1], dtype='int64', value=10)
|
|
|
@ -1054,14 +1061,31 @@ def equal(x, y, cond=None, **ignored):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def array_read(array, i):
|
|
|
|
def array_read(array, i):
|
|
|
|
"""This function performs the operation to read the data in as an
|
|
|
|
"""
|
|
|
|
|
|
|
|
This function performs the operation to read the data in as an
|
|
|
|
LOD_TENSOR_ARRAY.
|
|
|
|
LOD_TENSOR_ARRAY.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Given:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
array = [0.6, 0.1, 0.3, 0.1]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
And:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i = 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Then:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
output = 0.3
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
Args:
|
|
|
|
array (Variable|list): The input tensor that will be written to an array.
|
|
|
|
array (Variable|list): The input tensor that store data to be read.
|
|
|
|
i (Variable|list): The subscript index in tensor array, that points the
|
|
|
|
i (Variable|list): The index of the data to be read from input array.
|
|
|
|
place where data will be written to.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
|
Variable: The tensor type variable that has the data written to it.
|
|
|
|
Variable: The tensor type variable that has the data written to it.
|
|
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
Examples:
|
|
|
|
.. code-block:: python
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
|
@ -1154,6 +1178,13 @@ def array_length(array):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ConditionalBlockGuard(BlockGuard):
|
|
|
|
class ConditionalBlockGuard(BlockGuard):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
ConditionalBlockGuard is derived from BlockGuard. It is dedicated for
|
|
|
|
|
|
|
|
holding a ConditionalBlock, and helping users entering and exiting the
|
|
|
|
|
|
|
|
ConditionalBlock via Python's 'with' keyword. However, ConditionalBlockGuard
|
|
|
|
|
|
|
|
is generally an internal component of IfElse, users should not use it directly.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, block):
|
|
|
|
def __init__(self, block):
|
|
|
|
if not isinstance(block, ConditionalBlock):
|
|
|
|
if not isinstance(block, ConditionalBlock):
|
|
|
|
raise TypeError("block should be conditional block")
|
|
|
|
raise TypeError("block should be conditional block")
|
|
|
@ -1875,26 +1906,26 @@ def reorder_lod_tensor_by_rank(x, rank_table):
|
|
|
|
|
|
|
|
|
|
|
|
def is_empty(x, cond=None, **ignored):
|
|
|
|
def is_empty(x, cond=None, **ignored):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
**Is Empty**
|
|
|
|
Test whether a Variable is empty.
|
|
|
|
|
|
|
|
|
|
|
|
This layer returns the truth value of whether the variable is empty.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
Args:
|
|
|
|
x(Variable): Operand of *is_empty*
|
|
|
|
x (Variable): The Variable to be tested.
|
|
|
|
cond(Variable|None): Optional output variable to store the result
|
|
|
|
cond (Variable|None): Output parameter. Returns the test result
|
|
|
|
of *is_empty*
|
|
|
|
of given 'x'. Default: None
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
|
Variable: The tensor variable storing the output of *is_empty*.
|
|
|
|
Variable: A bool scalar. True if 'x' is an empty Variable.
|
|
|
|
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
Raises:
|
|
|
|
TypeError: If input cond is not a variable, or cond's dtype is
|
|
|
|
TypeError: If input cond is not a variable, or cond's dtype is
|
|
|
|
not bool
|
|
|
|
not bool.
|
|
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
Examples:
|
|
|
|
.. code-block:: python
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
|
|
less = fluid.layers.is_empty(x=input)
|
|
|
|
res = fluid.layers.is_empty(x=input)
|
|
|
|
|
|
|
|
# or:
|
|
|
|
|
|
|
|
fluid.layers.is_empty(x=input, cond=res)
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
helper = LayerHelper("is_empty", **locals())
|
|
|
|
helper = LayerHelper("is_empty", **locals())
|
|
|
|
if cond is None:
|
|
|
|
if cond is None:
|
|
|
|