Translate a Python Tensor to PaddlePaddle static graph Tensor
(x, dtype=None)
| 42 | |
| 43 | |
| 44 | def 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 | |
| 67 | def convert_attr(x, attr): |
no test coverage detected