(data, dtype=None)
| 48 | |
| 49 | |
| 50 | def tensor(data, dtype=None): |
| 51 | if isinstance(data, tf.Tensor): |
| 52 | if dtype is None or data.dtype == dtype: |
| 53 | return data |
| 54 | else: |
| 55 | return tf.cast(data, dtype=dtype) |
| 56 | else: |
| 57 | if isinstance(data, numbers.Number): |
| 58 | data = [data] |
| 59 | return tf.convert_to_tensor(data, dtype=dtype) |
| 60 | |
| 61 | |
| 62 | def initialize_context(): |