Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow/python/ops/gen_optional_ops.py: 17%

155 statements  

« prev     ^ index     » next       coverage.py v7.4.0, created at 2024-01-03 07:57 +0000

1"""Python wrappers around TensorFlow ops. 

2 

3This file is MACHINE GENERATED! Do not edit. 

4""" 

5 

6import collections 

7 

8from tensorflow.python import pywrap_tfe as pywrap_tfe 

9from tensorflow.python.eager import context as _context 

10from tensorflow.python.eager import core as _core 

11from tensorflow.python.eager import execute as _execute 

12from tensorflow.python.framework import dtypes as _dtypes 

13from tensorflow.security.fuzzing.py import annotation_types as _atypes 

14 

15from tensorflow.python.framework import op_def_registry as _op_def_registry 

16from tensorflow.python.framework import ops as _ops 

17from tensorflow.python.framework import op_def_library as _op_def_library 

18from tensorflow.python.util.deprecation import deprecated_endpoints 

19from tensorflow.python.util import dispatch as _dispatch 

20from tensorflow.python.util.tf_export import tf_export 

21 

22from typing import TypeVar 

23 

24def optional_from_value(components, name=None): 

25 r"""Constructs an Optional variant from a tuple of tensors. 

26 

27 Args: 

28 components: A list of `Tensor` objects. 

29 name: A name for the operation (optional). 

30 

31 Returns: 

32 A `Tensor` of type `variant`. 

33 """ 

34 _ctx = _context._context or _context.context() 

35 tld = _ctx._thread_local_data 

36 if tld.is_eager: 

37 try: 

38 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

39 _ctx, "OptionalFromValue", name, components) 

40 return _result 

41 except _core._NotOkStatusException as e: 

42 _ops.raise_from_not_ok_status(e, name) 

43 except _core._FallbackException: 

44 pass 

45 try: 

46 return optional_from_value_eager_fallback( 

47 components, name=name, ctx=_ctx) 

48 except _core._SymbolicException: 

49 pass # Add nodes to the TensorFlow graph. 

50 # Add nodes to the TensorFlow graph. 

51 _, _, _op, _outputs = _op_def_library._apply_op_helper( 

52 "OptionalFromValue", components=components, name=name) 

53 _result = _outputs[:] 

54 if _execute.must_record_gradient(): 

55 _attrs = ("Toutput_types", _op.get_attr("Toutput_types")) 

56 _inputs_flat = _op.inputs 

57 _execute.record_gradient( 

58 "OptionalFromValue", _inputs_flat, _attrs, _result) 

59 _result, = _result 

60 return _result 

61 

62OptionalFromValue = tf_export("raw_ops.OptionalFromValue")(_ops.to_raw_op(optional_from_value)) 

63 

64 

65def optional_from_value_eager_fallback(components, name, ctx): 

66 _attr_Toutput_types, components = _execute.convert_to_mixed_eager_tensors(components, ctx) 

67 _inputs_flat = list(components) 

68 _attrs = ("Toutput_types", _attr_Toutput_types) 

69 _result = _execute.execute(b"OptionalFromValue", 1, inputs=_inputs_flat, 

70 attrs=_attrs, ctx=ctx, name=name) 

71 if _execute.must_record_gradient(): 

72 _execute.record_gradient( 

73 "OptionalFromValue", _inputs_flat, _attrs, _result) 

74 _result, = _result 

75 return _result 

76 

77 

78def optional_get_value(optional, output_types, output_shapes, name=None): 

79 r"""Returns the value stored in an Optional variant or raises an error if none exists. 

80 

81 Args: 

82 optional: A `Tensor` of type `variant`. 

83 output_types: A list of `tf.DTypes` that has length `>= 1`. 

84 output_shapes: A list of shapes (each a `tf.TensorShape` or list of `ints`) that has length `>= 1`. 

85 name: A name for the operation (optional). 

86 

87 Returns: 

88 A list of `Tensor` objects of type `output_types`. 

89 """ 

90 _ctx = _context._context or _context.context() 

91 tld = _ctx._thread_local_data 

92 if tld.is_eager: 

93 try: 

94 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

95 _ctx, "OptionalGetValue", name, optional, "output_types", 

96 output_types, "output_shapes", output_shapes) 

97 return _result 

98 except _core._NotOkStatusException as e: 

99 _ops.raise_from_not_ok_status(e, name) 

100 except _core._FallbackException: 

101 pass 

102 try: 

103 return optional_get_value_eager_fallback( 

104 optional, output_types=output_types, output_shapes=output_shapes, 

105 name=name, ctx=_ctx) 

106 except _core._SymbolicException: 

107 pass # Add nodes to the TensorFlow graph. 

108 # Add nodes to the TensorFlow graph. 

109 if not isinstance(output_types, (list, tuple)): 

110 raise TypeError( 

111 "Expected list for 'output_types' argument to " 

112 "'optional_get_value' Op, not %r." % output_types) 

113 output_types = [_execute.make_type(_t, "output_types") for _t in output_types] 

114 if not isinstance(output_shapes, (list, tuple)): 

115 raise TypeError( 

116 "Expected list for 'output_shapes' argument to " 

117 "'optional_get_value' Op, not %r." % output_shapes) 

118 output_shapes = [_execute.make_shape(_s, "output_shapes") for _s in output_shapes] 

119 _, _, _op, _outputs = _op_def_library._apply_op_helper( 

120 "OptionalGetValue", optional=optional, output_types=output_types, 

121 output_shapes=output_shapes, name=name) 

122 _result = _outputs[:] 

123 if _execute.must_record_gradient(): 

124 _attrs = ("output_types", _op.get_attr("output_types"), "output_shapes", 

125 _op.get_attr("output_shapes")) 

126 _inputs_flat = _op.inputs 

127 _execute.record_gradient( 

128 "OptionalGetValue", _inputs_flat, _attrs, _result) 

129 return _result 

130 

131OptionalGetValue = tf_export("raw_ops.OptionalGetValue")(_ops.to_raw_op(optional_get_value)) 

132 

133 

134def optional_get_value_eager_fallback(optional, output_types, output_shapes, name, ctx): 

135 if not isinstance(output_types, (list, tuple)): 

136 raise TypeError( 

137 "Expected list for 'output_types' argument to " 

138 "'optional_get_value' Op, not %r." % output_types) 

139 output_types = [_execute.make_type(_t, "output_types") for _t in output_types] 

140 if not isinstance(output_shapes, (list, tuple)): 

141 raise TypeError( 

142 "Expected list for 'output_shapes' argument to " 

143 "'optional_get_value' Op, not %r." % output_shapes) 

144 output_shapes = [_execute.make_shape(_s, "output_shapes") for _s in output_shapes] 

145 optional = _ops.convert_to_tensor(optional, _dtypes.variant) 

146 _inputs_flat = [optional] 

147 _attrs = ("output_types", output_types, "output_shapes", output_shapes) 

148 _result = _execute.execute(b"OptionalGetValue", len(output_types), 

149 inputs=_inputs_flat, attrs=_attrs, ctx=ctx, 

150 name=name) 

151 if _execute.must_record_gradient(): 

152 _execute.record_gradient( 

153 "OptionalGetValue", _inputs_flat, _attrs, _result) 

154 return _result 

155 

156 

157def optional_has_value(optional, name=None): 

158 r"""Returns true if and only if the given Optional variant has a value. 

159 

160 Args: 

161 optional: A `Tensor` of type `variant`. 

162 name: A name for the operation (optional). 

163 

164 Returns: 

165 A `Tensor` of type `bool`. 

166 """ 

167 _ctx = _context._context or _context.context() 

168 tld = _ctx._thread_local_data 

169 if tld.is_eager: 

170 try: 

171 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

172 _ctx, "OptionalHasValue", name, optional) 

173 return _result 

174 except _core._NotOkStatusException as e: 

175 _ops.raise_from_not_ok_status(e, name) 

176 except _core._FallbackException: 

177 pass 

178 try: 

179 return optional_has_value_eager_fallback( 

180 optional, name=name, ctx=_ctx) 

181 except _core._SymbolicException: 

182 pass # Add nodes to the TensorFlow graph. 

183 # Add nodes to the TensorFlow graph. 

184 _, _, _op, _outputs = _op_def_library._apply_op_helper( 

185 "OptionalHasValue", optional=optional, name=name) 

186 _result = _outputs[:] 

187 if _execute.must_record_gradient(): 

188 _attrs = () 

189 _inputs_flat = _op.inputs 

190 _execute.record_gradient( 

191 "OptionalHasValue", _inputs_flat, _attrs, _result) 

192 _result, = _result 

193 return _result 

194 

195OptionalHasValue = tf_export("raw_ops.OptionalHasValue")(_ops.to_raw_op(optional_has_value)) 

196 

197 

198def optional_has_value_eager_fallback(optional, name, ctx): 

199 optional = _ops.convert_to_tensor(optional, _dtypes.variant) 

200 _inputs_flat = [optional] 

201 _attrs = None 

202 _result = _execute.execute(b"OptionalHasValue", 1, inputs=_inputs_flat, 

203 attrs=_attrs, ctx=ctx, name=name) 

204 if _execute.must_record_gradient(): 

205 _execute.record_gradient( 

206 "OptionalHasValue", _inputs_flat, _attrs, _result) 

207 _result, = _result 

208 return _result 

209 

210 

211def optional_none(name=None): 

212 r"""Creates an Optional variant with no value. 

213 

214 Args: 

215 name: A name for the operation (optional). 

216 

217 Returns: 

218 A `Tensor` of type `variant`. 

219 """ 

220 _ctx = _context._context or _context.context() 

221 tld = _ctx._thread_local_data 

222 if tld.is_eager: 

223 try: 

224 _result = pywrap_tfe.TFE_Py_FastPathExecute( 

225 _ctx, "OptionalNone", name) 

226 return _result 

227 except _core._NotOkStatusException as e: 

228 _ops.raise_from_not_ok_status(e, name) 

229 except _core._FallbackException: 

230 pass 

231 try: 

232 return optional_none_eager_fallback( 

233 name=name, ctx=_ctx) 

234 except _core._SymbolicException: 

235 pass # Add nodes to the TensorFlow graph. 

236 # Add nodes to the TensorFlow graph. 

237 _, _, _op, _outputs = _op_def_library._apply_op_helper( 

238 "OptionalNone", name=name) 

239 _result = _outputs[:] 

240 if _execute.must_record_gradient(): 

241 _attrs = () 

242 _inputs_flat = _op.inputs 

243 _execute.record_gradient( 

244 "OptionalNone", _inputs_flat, _attrs, _result) 

245 _result, = _result 

246 return _result 

247 

248OptionalNone = tf_export("raw_ops.OptionalNone")(_ops.to_raw_op(optional_none)) 

249 

250 

251def optional_none_eager_fallback(name, ctx): 

252 _inputs_flat = [] 

253 _attrs = None 

254 _result = _execute.execute(b"OptionalNone", 1, inputs=_inputs_flat, 

255 attrs=_attrs, ctx=ctx, name=name) 

256 if _execute.must_record_gradient(): 

257 _execute.record_gradient( 

258 "OptionalNone", _inputs_flat, _attrs, _result) 

259 _result, = _result 

260 return _result 

261