MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / data

Function data

python/paddle/static/input.py:59–224  ·  view source on GitHub ↗

This function creates a variable on the global block. The global variable can be accessed by all the following operators in the graph. The variable is a placeholder that could be fed with input, such as Executor can feed input into the variable. When `dtype` is None, the dtype

(
    name: str,
    shape: ShapeLike,
    dtype: DTypeLike | None = None,
    lod_level: int = 0,
)

Source from the content-addressed store, hash-verified

57
58@static_only
59def data(
60 name: str,
61 shape: ShapeLike,
62 dtype: DTypeLike | None = None,
63 lod_level: int = 0,
64) -> paddle.Tensor:
65 """
66
67 This function creates a variable on the global block. The global variable
68 can be accessed by all the following operators in the graph. The variable
69 is a placeholder that could be fed with input, such as Executor can feed
70 input into the variable. When `dtype` is None, the dtype
71 will get from the global dtype by `paddle.get_default_dtype()`.
72
73 Args:
74 name (str): The name/alias of the variable, see :ref:`api_guide_Name`
75 for more details.
76 shape (list|tuple): List|Tuple of integers declaring the shape. You can
77 set None or -1 at a dimension to indicate the dimension can be of any
78 size. For example, it is useful to set changeable batch size as None or -1.
79 dtype (np.dtype|str, optional): The type of the data. Supported
80 dtype: bool, float16, float32, float64, int8, int16, int32, int64,
81 uint8. Default: None. When `dtype` is not set, the dtype will get
82 from the global dtype by `paddle.get_default_dtype()`.
83 lod_level (int, optional): The LoD level of the DenseTensor. Usually users
84 don't have to set this value. Default: 0.
85
86 Returns:
87 Variable: The global variable that gives access to the data.
88
89 Examples:
90 .. code-block:: pycon
91
92 >>> # doctest: +SKIP("This has diff in xdoctest env")
93 >>> import numpy as np
94 >>> import paddle
95 >>> paddle.enable_static()
96
97 # Creates a variable with fixed size [3, 2, 1]
98 # User can only feed data of the same shape to x
99 # the dtype is not set, so it will set "float32" by
100 # paddle.get_default_dtype(). You can use paddle.get_default_dtype() to
101 # change the global dtype
102 >>> x = paddle.static.data(name='x', shape=[3, 2, 1])
103
104 # Creates a variable with changeable batch size -1.
105 # Users can feed data of any batch size into y,
106 # but size of each data sample has to be [2, 1]
107 >>> y = paddle.static.data(name='y', shape=[-1, 2, 1], dtype='float32')
108
109 >>> z = x + y
110
111 # In this example, we will feed x and y with np-ndarray "1"
112 # and fetch z, like implementing "1 + 1 = 2" in PaddlePaddle
113 >>> feed_data = np.ones(shape=[3, 2, 1], dtype=np.float32)
114
115 >>> exe = paddle.static.Executor(paddle.framework.CPUPlace())
116 >>> out = exe.run(

Callers 8

get_modelMethod · 0.90
test_mulMethod · 0.90
_create_feed_layerMethod · 0.70
_insert_funcMethod · 0.50
_wrap_dataMethod · 0.50
eval_batchMethod · 0.50
_wrap_dataMethod · 0.50

Calls 15

append_opMethod · 0.95
LayerHelperClass · 0.90
check_typeFunction · 0.90
in_pir_modeFunction · 0.90
listFunction · 0.85
rangeFunction · 0.85
ValueErrorClass · 0.85
strFunction · 0.85
evaluate_flagFunction · 0.85
get_default_dtypeMethod · 0.80

Tested by 1

test_mulMethod · 0.72