Notes: The constructor of Variable should not be invoked directly. In Static Graph Mode: Please use ** `Block.create_var` ** to create a Static variable which has no data until being feed. In Dygraph Mode: Please use ** :ref:`api_paddle_to_tensor` ** to create a dygra
| 1720 | |
| 1721 | |
| 1722 | class Variable(metaclass=VariableMetaClass): |
| 1723 | """ |
| 1724 | |
| 1725 | Notes: |
| 1726 | The constructor of Variable should not be invoked directly. |
| 1727 | |
| 1728 | In Static Graph Mode: Please use ** `Block.create_var` ** to create a Static variable which has no data until being feed. |
| 1729 | |
| 1730 | In Dygraph Mode: Please use ** :ref:`api_paddle_to_tensor` ** to create a dygraph variable with real data. |
| 1731 | |
| 1732 | In Fluid, every input and output of an OP is a variable. In most |
| 1733 | cases, variables are used for holding different kinds of data or training |
| 1734 | labels. A variable belongs to a :ref:`api_guide_Block_en` . All variable has its own name and |
| 1735 | two variables in different :ref:`api_guide_Block_en` could have the same name. |
| 1736 | |
| 1737 | There are many kinds of variables. Each kind of them has its own attributes |
| 1738 | and usages. Please refer to the `framework.proto <https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/phi/core/framework/framework.proto>`_ for details. |
| 1739 | |
| 1740 | Most of a Variable's member variables can be set to be None. It mean |
| 1741 | it is not available or will be specified later. |
| 1742 | |
| 1743 | Examples: |
| 1744 | In Static Graph Mode: |
| 1745 | |
| 1746 | .. code-block:: pycon |
| 1747 | :name: code-example-1 |
| 1748 | |
| 1749 | >>> import paddle |
| 1750 | >>> import paddle.base as base |
| 1751 | >>> with paddle.pir_utils.OldIrGuard(): |
| 1752 | ... cur_program = base.Program() |
| 1753 | ... cur_block = cur_program.current_block() |
| 1754 | ... new_variable = cur_block.create_var( |
| 1755 | ... name="X", |
| 1756 | ... shape=[-1, 23, 48], |
| 1757 | ... dtype="float32", |
| 1758 | ... ) |
| 1759 | |
| 1760 | In Dygraph Mode: |
| 1761 | |
| 1762 | .. code-block:: pycon |
| 1763 | :name: code-example-2 |
| 1764 | |
| 1765 | >>> import paddle.base as base |
| 1766 | >>> import numpy as np |
| 1767 | >>> import paddle |
| 1768 | |
| 1769 | >>> with base.dygraph.guard(): |
| 1770 | ... new_variable = paddle.to_tensor(np.arange(10)) |
| 1771 | |
| 1772 | """ |
| 1773 | |
| 1774 | def __init__( |
| 1775 | self, |
| 1776 | block, |
| 1777 | type=core.VarDesc.VarType.DENSE_TENSOR, |
| 1778 | name=None, |
| 1779 | shape=None, |
no outgoing calls
no test coverage detected