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

Function to_static_variable

python/paddle/jit/dy2static/convert_operators.py:44–64  ·  view source on GitHub ↗

Translate a Python Tensor to PaddlePaddle static graph Tensor

(x, dtype=None)

Source from the content-addressed store, hash-verified

42
43
44def to_static_variable(x, dtype=None):
45 '''
46 Translate a Python Tensor to PaddlePaddle static graph Tensor
47 '''
48 if isinstance(x, bool):
49 dtype = 'bool' if dtype is None else dtype
50 return paddle.full(shape=[], dtype=dtype, fill_value=x)
51 if isinstance(x, float):
52 dtype = 'float64' if dtype is None else dtype
53 return paddle.full(shape=[], dtype=dtype, fill_value=x)
54 if isinstance(x, int):
55 dtype = 'int64' if dtype is None else dtype
56 return paddle.full(shape=[], dtype=dtype, fill_value=x)
57 if not use_pir_api() and (isinstance(x, UndefinedVar) or x is None):
58 """
59 for early return case, we need a variable to represent None, current we use data_layer_not_check.
60 """
61 return create_undefined_variable()
62 if is_sequence(x):
63 return map_structure(to_static_variable, x)
64 return x
65
66
67def convert_attr(x, attr):

Callers 4

check_next_varFunction · 0.90
_run_paddle_whileFunction · 0.85

Calls 5

use_pir_apiFunction · 0.90
is_sequenceFunction · 0.90
map_structureFunction · 0.90
fullMethod · 0.80

Tested by

no test coverage detected