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

Function create_tensor

python/paddle/tensor/creation.py:289–330  ·  view source on GitHub ↗

Create a variable, which will hold a Tensor with data type dtype. Args: dtype(str|paddle.dtype|np.dtype, optional): the data type of Tensor to be created, the data type is bool, float16, float32, float64, int8, int16, int32 and int64. name(string, optional): The

(
    dtype: DTypeLike, name: str | None = None, persistable: bool = False
)

Source from the content-addressed store, hash-verified

287
288
289def create_tensor(
290 dtype: DTypeLike, name: str | None = None, persistable: bool = False
291) -> paddle.Tensor:
292 """
293 Create a variable, which will hold a Tensor with data type dtype.
294
295 Args:
296 dtype(str|paddle.dtype|np.dtype, optional): the data type of Tensor to be created, the
297 data type is bool, float16, float32, float64, int8, int16, int32 and int64.
298 name(string, optional): The default value is None. Normally there is no need for
299 user to set this property. For more information, please refer to :ref:`api_guide_Name`
300 persistable(bool): Set the persistable flag of the create tensor.
301 default value is False.
302
303 Returns:
304 Variable: The tensor to be created according to dtype.
305
306 Examples:
307 .. code-block:: pycon
308
309 >>> import paddle
310 >>> tensor = paddle.tensor.create_tensor(dtype='float32')
311 """
312 check_dtype(
313 dtype,
314 'dtype',
315 [
316 'bool',
317 'float16',
318 'float32',
319 'float64',
320 'int8',
321 'int32',
322 'int32',
323 'int64',
324 ],
325 'create_tensor',
326 )
327 helper = LayerHelper("create_tensor", **locals())
328 return helper.create_variable(
329 name=helper.name, dtype=dtype, persistable=persistable
330 )
331
332
333@param_two_alias(["stop", "end"], ["num", "steps"])

Callers

nothing calls this directly

Calls 3

LayerHelperClass · 0.85
check_dtypeFunction · 0.50
create_variableMethod · 0.45

Tested by

no test coverage detected