Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow/python/ops/gen_random_ops.py: 9%
524 statements
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
« prev ^ index » next coverage.py v7.4.0, created at 2024-01-03 07:57 +0000
1"""Python wrappers around TensorFlow ops.
3This file is MACHINE GENERATED! Do not edit.
4"""
6import collections
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
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
22from typing import TypeVar
24def multinomial(logits, num_samples, seed=0, seed2=0, output_dtype=_dtypes.int64, name=None):
25 r"""Draws samples from a multinomial distribution.
27 Args:
28 logits: A `Tensor`. Must be one of the following types: `float32`, `float64`, `int32`, `uint8`, `int16`, `int8`, `int64`, `bfloat16`, `uint16`, `half`, `uint32`, `uint64`.
29 2-D Tensor with shape `[batch_size, num_classes]`. Each slice `[i, :]`
30 represents the unnormalized log probabilities for all classes.
31 num_samples: A `Tensor` of type `int32`.
32 0-D. Number of independent samples to draw for each row slice.
33 seed: An optional `int`. Defaults to `0`.
34 If either seed or seed2 is set to be non-zero, the internal random number
35 generator is seeded by the given seed. Otherwise, a random seed is used.
36 seed2: An optional `int`. Defaults to `0`.
37 A second seed to avoid seed collision.
38 output_dtype: An optional `tf.DType` from: `tf.int32, tf.int64`. Defaults to `tf.int64`.
39 name: A name for the operation (optional).
41 Returns:
42 A `Tensor` of type `output_dtype`.
43 """
44 _ctx = _context._context or _context.context()
45 tld = _ctx._thread_local_data
46 if tld.is_eager:
47 try:
48 _result = pywrap_tfe.TFE_Py_FastPathExecute(
49 _ctx, "Multinomial", name, logits, num_samples, "seed", seed, "seed2",
50 seed2, "output_dtype", output_dtype)
51 return _result
52 except _core._NotOkStatusException as e:
53 _ops.raise_from_not_ok_status(e, name)
54 except _core._FallbackException:
55 pass
56 try:
57 return multinomial_eager_fallback(
58 logits, num_samples, seed=seed, seed2=seed2,
59 output_dtype=output_dtype, name=name, ctx=_ctx)
60 except _core._SymbolicException:
61 pass # Add nodes to the TensorFlow graph.
62 # Add nodes to the TensorFlow graph.
63 if seed is None:
64 seed = 0
65 seed = _execute.make_int(seed, "seed")
66 if seed2 is None:
67 seed2 = 0
68 seed2 = _execute.make_int(seed2, "seed2")
69 if output_dtype is None:
70 output_dtype = _dtypes.int64
71 output_dtype = _execute.make_type(output_dtype, "output_dtype")
72 _, _, _op, _outputs = _op_def_library._apply_op_helper(
73 "Multinomial", logits=logits, num_samples=num_samples, seed=seed,
74 seed2=seed2, output_dtype=output_dtype, name=name)
75 _result = _outputs[:]
76 if _execute.must_record_gradient():
77 _attrs = ("seed", _op._get_attr_int("seed"), "seed2",
78 _op._get_attr_int("seed2"), "T", _op._get_attr_type("T"),
79 "output_dtype", _op._get_attr_type("output_dtype"))
80 _inputs_flat = _op.inputs
81 _execute.record_gradient(
82 "Multinomial", _inputs_flat, _attrs, _result)
83 _result, = _result
84 return _result
86Multinomial = tf_export("raw_ops.Multinomial")(_ops.to_raw_op(multinomial))
89def multinomial_eager_fallback(logits, num_samples, seed, seed2, output_dtype, name, ctx):
90 if seed is None:
91 seed = 0
92 seed = _execute.make_int(seed, "seed")
93 if seed2 is None:
94 seed2 = 0
95 seed2 = _execute.make_int(seed2, "seed2")
96 if output_dtype is None:
97 output_dtype = _dtypes.int64
98 output_dtype = _execute.make_type(output_dtype, "output_dtype")
99 _attr_T, (logits,) = _execute.args_to_matching_eager([logits], ctx, [_dtypes.float32, _dtypes.float64, _dtypes.int32, _dtypes.uint8, _dtypes.int16, _dtypes.int8, _dtypes.int64, _dtypes.bfloat16, _dtypes.uint16, _dtypes.half, _dtypes.uint32, _dtypes.uint64, ])
100 num_samples = _ops.convert_to_tensor(num_samples, _dtypes.int32)
101 _inputs_flat = [logits, num_samples]
102 _attrs = ("seed", seed, "seed2", seed2, "T", _attr_T, "output_dtype",
103 output_dtype)
104 _result = _execute.execute(b"Multinomial", 1, inputs=_inputs_flat,
105 attrs=_attrs, ctx=ctx, name=name)
106 if _execute.must_record_gradient():
107 _execute.record_gradient(
108 "Multinomial", _inputs_flat, _attrs, _result)
109 _result, = _result
110 return _result
113def parameterized_truncated_normal(shape, means, stdevs, minvals, maxvals, seed=0, seed2=0, name=None):
114 r"""Outputs random values from a normal distribution. The parameters may each be a
116 scalar which applies to the entire output, or a vector of length shape[0] which
117 stores the parameters for each batch.
119 Args:
120 shape: A `Tensor`. Must be one of the following types: `int32`, `int64`.
121 The shape of the output tensor. Batches are indexed by the 0th dimension.
122 means: A `Tensor`. Must be one of the following types: `half`, `bfloat16`, `float32`, `float64`.
123 The mean parameter of each batch.
124 stdevs: A `Tensor`. Must have the same type as `means`.
125 The standard deviation parameter of each batch. Must be greater than 0.
126 minvals: A `Tensor`. Must have the same type as `means`.
127 The minimum cutoff. May be -infinity.
128 maxvals: A `Tensor`. Must have the same type as `means`.
129 The maximum cutoff. May be +infinity, and must be more than the minval
130 for each batch.
131 seed: An optional `int`. Defaults to `0`.
132 If either `seed` or `seed2` are set to be non-zero, the random number
133 generator is seeded by the given seed. Otherwise, it is seeded by a
134 random seed.
135 seed2: An optional `int`. Defaults to `0`.
136 A second seed to avoid seed collision.
137 name: A name for the operation (optional).
139 Returns:
140 A `Tensor`. Has the same type as `means`.
141 """
142 _ctx = _context._context or _context.context()
143 tld = _ctx._thread_local_data
144 if tld.is_eager:
145 try:
146 _result = pywrap_tfe.TFE_Py_FastPathExecute(
147 _ctx, "ParameterizedTruncatedNormal", name, shape, means, stdevs,
148 minvals, maxvals, "seed", seed, "seed2", seed2)
149 return _result
150 except _core._NotOkStatusException as e:
151 _ops.raise_from_not_ok_status(e, name)
152 except _core._FallbackException:
153 pass
154 try:
155 return parameterized_truncated_normal_eager_fallback(
156 shape, means, stdevs, minvals, maxvals, seed=seed, seed2=seed2,
157 name=name, ctx=_ctx)
158 except _core._SymbolicException:
159 pass # Add nodes to the TensorFlow graph.
160 # Add nodes to the TensorFlow graph.
161 if seed is None:
162 seed = 0
163 seed = _execute.make_int(seed, "seed")
164 if seed2 is None:
165 seed2 = 0
166 seed2 = _execute.make_int(seed2, "seed2")
167 _, _, _op, _outputs = _op_def_library._apply_op_helper(
168 "ParameterizedTruncatedNormal", shape=shape, means=means,
169 stdevs=stdevs, minvals=minvals,
170 maxvals=maxvals, seed=seed,
171 seed2=seed2, name=name)
172 _result = _outputs[:]
173 if _execute.must_record_gradient():
174 _attrs = ("seed", _op._get_attr_int("seed"), "seed2",
175 _op._get_attr_int("seed2"), "dtype",
176 _op._get_attr_type("dtype"), "T", _op._get_attr_type("T"))
177 _inputs_flat = _op.inputs
178 _execute.record_gradient(
179 "ParameterizedTruncatedNormal", _inputs_flat, _attrs, _result)
180 _result, = _result
181 return _result
183ParameterizedTruncatedNormal = tf_export("raw_ops.ParameterizedTruncatedNormal")(_ops.to_raw_op(parameterized_truncated_normal))
186def parameterized_truncated_normal_eager_fallback(shape, means, stdevs, minvals, maxvals, seed, seed2, name, ctx):
187 if seed is None:
188 seed = 0
189 seed = _execute.make_int(seed, "seed")
190 if seed2 is None:
191 seed2 = 0
192 seed2 = _execute.make_int(seed2, "seed2")
193 _attr_dtype, _inputs_dtype = _execute.args_to_matching_eager([means, stdevs, minvals, maxvals], ctx, [_dtypes.half, _dtypes.bfloat16, _dtypes.float32, _dtypes.float64, ])
194 (means, stdevs, minvals, maxvals) = _inputs_dtype
195 _attr_T, (shape,) = _execute.args_to_matching_eager([shape], ctx, [_dtypes.int32, _dtypes.int64, ])
196 _inputs_flat = [shape, means, stdevs, minvals, maxvals]
197 _attrs = ("seed", seed, "seed2", seed2, "dtype", _attr_dtype, "T", _attr_T)
198 _result = _execute.execute(b"ParameterizedTruncatedNormal", 1,
199 inputs=_inputs_flat, attrs=_attrs, ctx=ctx,
200 name=name)
201 if _execute.must_record_gradient():
202 _execute.record_gradient(
203 "ParameterizedTruncatedNormal", _inputs_flat, _attrs, _result)
204 _result, = _result
205 return _result
208def random_gamma(shape, alpha, seed=0, seed2=0, name=None):
209 r"""Outputs random values from the Gamma distribution(s) described by alpha.
211 This op uses the algorithm by Marsaglia et al. to acquire samples via
212 transformation-rejection from pairs of uniform and normal random variables.
213 See http://dl.acm.org/citation.cfm?id=358414
215 Args:
216 shape: A `Tensor`. Must be one of the following types: `int32`, `int64`.
217 1-D integer tensor. Shape of independent samples to draw from each
218 distribution described by the shape parameters given in alpha.
219 alpha: A `Tensor`. Must be one of the following types: `half`, `float32`, `float64`.
220 A tensor in which each scalar is a "shape" parameter describing the
221 associated gamma distribution.
222 seed: An optional `int`. Defaults to `0`.
223 If either `seed` or `seed2` are set to be non-zero, the random number
224 generator is seeded by the given seed. Otherwise, it is seeded by a
225 random seed.
226 seed2: An optional `int`. Defaults to `0`.
227 A second seed to avoid seed collision.
228 name: A name for the operation (optional).
230 Returns:
231 A `Tensor`. Has the same type as `alpha`.
232 """
233 _ctx = _context._context or _context.context()
234 tld = _ctx._thread_local_data
235 if tld.is_eager:
236 try:
237 _result = pywrap_tfe.TFE_Py_FastPathExecute(
238 _ctx, "RandomGamma", name, shape, alpha, "seed", seed, "seed2", seed2)
239 return _result
240 except _core._NotOkStatusException as e:
241 _ops.raise_from_not_ok_status(e, name)
242 except _core._FallbackException:
243 pass
244 try:
245 return random_gamma_eager_fallback(
246 shape, alpha, seed=seed, seed2=seed2, name=name, ctx=_ctx)
247 except _core._SymbolicException:
248 pass # Add nodes to the TensorFlow graph.
249 # Add nodes to the TensorFlow graph.
250 if seed is None:
251 seed = 0
252 seed = _execute.make_int(seed, "seed")
253 if seed2 is None:
254 seed2 = 0
255 seed2 = _execute.make_int(seed2, "seed2")
256 _, _, _op, _outputs = _op_def_library._apply_op_helper(
257 "RandomGamma", shape=shape, alpha=alpha, seed=seed, seed2=seed2,
258 name=name)
259 _result = _outputs[:]
260 if _execute.must_record_gradient():
261 _attrs = ("seed", _op._get_attr_int("seed"), "seed2",
262 _op._get_attr_int("seed2"), "S", _op._get_attr_type("S"), "T",
263 _op._get_attr_type("T"))
264 _inputs_flat = _op.inputs
265 _execute.record_gradient(
266 "RandomGamma", _inputs_flat, _attrs, _result)
267 _result, = _result
268 return _result
270RandomGamma = tf_export("raw_ops.RandomGamma")(_ops.to_raw_op(random_gamma))
273def random_gamma_eager_fallback(shape, alpha, seed, seed2, name, ctx):
274 if seed is None:
275 seed = 0
276 seed = _execute.make_int(seed, "seed")
277 if seed2 is None:
278 seed2 = 0
279 seed2 = _execute.make_int(seed2, "seed2")
280 _attr_S, (shape,) = _execute.args_to_matching_eager([shape], ctx, [_dtypes.int32, _dtypes.int64, ])
281 _attr_T, (alpha,) = _execute.args_to_matching_eager([alpha], ctx, [_dtypes.half, _dtypes.float32, _dtypes.float64, ])
282 _inputs_flat = [shape, alpha]
283 _attrs = ("seed", seed, "seed2", seed2, "S", _attr_S, "T", _attr_T)
284 _result = _execute.execute(b"RandomGamma", 1, inputs=_inputs_flat,
285 attrs=_attrs, ctx=ctx, name=name)
286 if _execute.must_record_gradient():
287 _execute.record_gradient(
288 "RandomGamma", _inputs_flat, _attrs, _result)
289 _result, = _result
290 return _result
293def random_gamma_grad(alpha, sample, name=None):
294 r"""Computes the derivative of a Gamma random sample w.r.t. `alpha`.
296 Args:
297 alpha: A `Tensor`. Must be one of the following types: `float32`, `float64`.
298 sample: A `Tensor`. Must have the same type as `alpha`.
299 name: A name for the operation (optional).
301 Returns:
302 A `Tensor`. Has the same type as `alpha`.
303 """
304 _ctx = _context._context or _context.context()
305 tld = _ctx._thread_local_data
306 if tld.is_eager:
307 try:
308 _result = pywrap_tfe.TFE_Py_FastPathExecute(
309 _ctx, "RandomGammaGrad", name, alpha, sample)
310 return _result
311 except _core._NotOkStatusException as e:
312 _ops.raise_from_not_ok_status(e, name)
313 except _core._FallbackException:
314 pass
315 try:
316 return random_gamma_grad_eager_fallback(
317 alpha, sample, name=name, ctx=_ctx)
318 except _core._SymbolicException:
319 pass # Add nodes to the TensorFlow graph.
320 # Add nodes to the TensorFlow graph.
321 _, _, _op, _outputs = _op_def_library._apply_op_helper(
322 "RandomGammaGrad", alpha=alpha, sample=sample, name=name)
323 _result = _outputs[:]
324 if _execute.must_record_gradient():
325 _attrs = ("T", _op._get_attr_type("T"))
326 _inputs_flat = _op.inputs
327 _execute.record_gradient(
328 "RandomGammaGrad", _inputs_flat, _attrs, _result)
329 _result, = _result
330 return _result
332RandomGammaGrad = tf_export("raw_ops.RandomGammaGrad")(_ops.to_raw_op(random_gamma_grad))
335def random_gamma_grad_eager_fallback(alpha, sample, name, ctx):
336 _attr_T, _inputs_T = _execute.args_to_matching_eager([alpha, sample], ctx, [_dtypes.float32, _dtypes.float64, ])
337 (alpha, sample) = _inputs_T
338 _inputs_flat = [alpha, sample]
339 _attrs = ("T", _attr_T)
340 _result = _execute.execute(b"RandomGammaGrad", 1, inputs=_inputs_flat,
341 attrs=_attrs, ctx=ctx, name=name)
342 if _execute.must_record_gradient():
343 _execute.record_gradient(
344 "RandomGammaGrad", _inputs_flat, _attrs, _result)
345 _result, = _result
346 return _result
349def random_poisson(shape, rate, seed=0, seed2=0, name=None):
350 r"""Use RandomPoissonV2 instead.
352 Args:
353 shape: A `Tensor`. Must be one of the following types: `int32`, `int64`.
354 rate: A `Tensor`. Must be one of the following types: `half`, `float32`, `float64`.
355 seed: An optional `int`. Defaults to `0`.
356 seed2: An optional `int`. Defaults to `0`.
357 name: A name for the operation (optional).
359 Returns:
360 A `Tensor`. Has the same type as `rate`.
361 """
362 _ctx = _context._context or _context.context()
363 tld = _ctx._thread_local_data
364 if tld.is_eager:
365 try:
366 _result = pywrap_tfe.TFE_Py_FastPathExecute(
367 _ctx, "RandomPoisson", name, shape, rate, "seed", seed, "seed2",
368 seed2)
369 return _result
370 except _core._NotOkStatusException as e:
371 _ops.raise_from_not_ok_status(e, name)
372 except _core._FallbackException:
373 pass
374 try:
375 return random_poisson_eager_fallback(
376 shape, rate, seed=seed, seed2=seed2, name=name, ctx=_ctx)
377 except _core._SymbolicException:
378 pass # Add nodes to the TensorFlow graph.
379 # Add nodes to the TensorFlow graph.
380 if seed is None:
381 seed = 0
382 seed = _execute.make_int(seed, "seed")
383 if seed2 is None:
384 seed2 = 0
385 seed2 = _execute.make_int(seed2, "seed2")
386 _, _, _op, _outputs = _op_def_library._apply_op_helper(
387 "RandomPoisson", shape=shape, rate=rate, seed=seed, seed2=seed2,
388 name=name)
389 _result = _outputs[:]
390 if _execute.must_record_gradient():
391 _attrs = ("seed", _op._get_attr_int("seed"), "seed2",
392 _op._get_attr_int("seed2"), "S", _op._get_attr_type("S"),
393 "dtype", _op._get_attr_type("dtype"))
394 _inputs_flat = _op.inputs
395 _execute.record_gradient(
396 "RandomPoisson", _inputs_flat, _attrs, _result)
397 _result, = _result
398 return _result
400RandomPoisson = tf_export("raw_ops.RandomPoisson")(_ops.to_raw_op(random_poisson))
403def random_poisson_eager_fallback(shape, rate, seed, seed2, name, ctx):
404 if seed is None:
405 seed = 0
406 seed = _execute.make_int(seed, "seed")
407 if seed2 is None:
408 seed2 = 0
409 seed2 = _execute.make_int(seed2, "seed2")
410 _attr_S, (shape,) = _execute.args_to_matching_eager([shape], ctx, [_dtypes.int32, _dtypes.int64, ])
411 _attr_dtype, (rate,) = _execute.args_to_matching_eager([rate], ctx, [_dtypes.half, _dtypes.float32, _dtypes.float64, ])
412 _inputs_flat = [shape, rate]
413 _attrs = ("seed", seed, "seed2", seed2, "S", _attr_S, "dtype", _attr_dtype)
414 _result = _execute.execute(b"RandomPoisson", 1, inputs=_inputs_flat,
415 attrs=_attrs, ctx=ctx, name=name)
416 if _execute.must_record_gradient():
417 _execute.record_gradient(
418 "RandomPoisson", _inputs_flat, _attrs, _result)
419 _result, = _result
420 return _result
423def random_poisson_v2(shape, rate, seed=0, seed2=0, dtype=_dtypes.int64, name=None):
424 r"""Outputs random values from the Poisson distribution(s) described by rate.
426 This op uses two algorithms, depending on rate. If rate >= 10, then
427 the algorithm by Hormann is used to acquire samples via
428 transformation-rejection.
429 See http://www.sciencedirect.com/science/article/pii/0167668793909974.
431 Otherwise, Knuth's algorithm is used to acquire samples via multiplying uniform
432 random variables.
433 See Donald E. Knuth (1969). Seminumerical Algorithms. The Art of Computer
434 Programming, Volume 2. Addison Wesley
436 Args:
437 shape: A `Tensor`. Must be one of the following types: `int32`, `int64`.
438 1-D integer tensor. Shape of independent samples to draw from each
439 distribution described by the shape parameters given in rate.
440 rate: A `Tensor`. Must be one of the following types: `half`, `float32`, `float64`, `int32`, `int64`.
441 A tensor in which each scalar is a "rate" parameter describing the
442 associated poisson distribution.
443 seed: An optional `int`. Defaults to `0`.
444 If either `seed` or `seed2` are set to be non-zero, the random number
445 generator is seeded by the given seed. Otherwise, it is seeded by a
446 random seed.
447 seed2: An optional `int`. Defaults to `0`.
448 A second seed to avoid seed collision.
449 dtype: An optional `tf.DType` from: `tf.half, tf.float32, tf.float64, tf.int32, tf.int64`. Defaults to `tf.int64`.
450 name: A name for the operation (optional).
452 Returns:
453 A `Tensor` of type `dtype`.
454 """
455 _ctx = _context._context or _context.context()
456 tld = _ctx._thread_local_data
457 if tld.is_eager:
458 try:
459 _result = pywrap_tfe.TFE_Py_FastPathExecute(
460 _ctx, "RandomPoissonV2", name, shape, rate, "seed", seed, "seed2",
461 seed2, "dtype", dtype)
462 return _result
463 except _core._NotOkStatusException as e:
464 _ops.raise_from_not_ok_status(e, name)
465 except _core._FallbackException:
466 pass
467 try:
468 return random_poisson_v2_eager_fallback(
469 shape, rate, seed=seed, seed2=seed2, dtype=dtype, name=name,
470 ctx=_ctx)
471 except _core._SymbolicException:
472 pass # Add nodes to the TensorFlow graph.
473 # Add nodes to the TensorFlow graph.
474 if seed is None:
475 seed = 0
476 seed = _execute.make_int(seed, "seed")
477 if seed2 is None:
478 seed2 = 0
479 seed2 = _execute.make_int(seed2, "seed2")
480 if dtype is None:
481 dtype = _dtypes.int64
482 dtype = _execute.make_type(dtype, "dtype")
483 _, _, _op, _outputs = _op_def_library._apply_op_helper(
484 "RandomPoissonV2", shape=shape, rate=rate, seed=seed, seed2=seed2,
485 dtype=dtype, name=name)
486 _result = _outputs[:]
487 if _execute.must_record_gradient():
488 _attrs = ("seed", _op._get_attr_int("seed"), "seed2",
489 _op._get_attr_int("seed2"), "S", _op._get_attr_type("S"), "R",
490 _op._get_attr_type("R"), "dtype", _op._get_attr_type("dtype"))
491 _inputs_flat = _op.inputs
492 _execute.record_gradient(
493 "RandomPoissonV2", _inputs_flat, _attrs, _result)
494 _result, = _result
495 return _result
497RandomPoissonV2 = tf_export("raw_ops.RandomPoissonV2")(_ops.to_raw_op(random_poisson_v2))
500def random_poisson_v2_eager_fallback(shape, rate, seed, seed2, dtype, name, ctx):
501 if seed is None:
502 seed = 0
503 seed = _execute.make_int(seed, "seed")
504 if seed2 is None:
505 seed2 = 0
506 seed2 = _execute.make_int(seed2, "seed2")
507 if dtype is None:
508 dtype = _dtypes.int64
509 dtype = _execute.make_type(dtype, "dtype")
510 _attr_S, (shape,) = _execute.args_to_matching_eager([shape], ctx, [_dtypes.int32, _dtypes.int64, ])
511 _attr_R, (rate,) = _execute.args_to_matching_eager([rate], ctx, [_dtypes.half, _dtypes.float32, _dtypes.float64, _dtypes.int32, _dtypes.int64, ], _dtypes.float64)
512 _inputs_flat = [shape, rate]
513 _attrs = ("seed", seed, "seed2", seed2, "S", _attr_S, "R", _attr_R, "dtype",
514 dtype)
515 _result = _execute.execute(b"RandomPoissonV2", 1, inputs=_inputs_flat,
516 attrs=_attrs, ctx=ctx, name=name)
517 if _execute.must_record_gradient():
518 _execute.record_gradient(
519 "RandomPoissonV2", _inputs_flat, _attrs, _result)
520 _result, = _result
521 return _result
524def random_shuffle(value, seed=0, seed2=0, name=None):
525 r"""Randomly shuffles a tensor along its first dimension.
527 The tensor is shuffled along dimension 0, such that each `value[j]` is mapped
528 to one and only one `output[i]`. For example, a mapping that might occur for a
529 3x2 tensor is:
531 ```
532 [[1, 2], [[5, 6],
533 [3, 4], ==> [1, 2],
534 [5, 6]] [3, 4]]
535 ```
537 Args:
538 value: A `Tensor`. The tensor to be shuffled.
539 seed: An optional `int`. Defaults to `0`.
540 If either `seed` or `seed2` are set to be non-zero, the random number
541 generator is seeded by the given seed. Otherwise, it is seeded by a
542 random seed.
543 seed2: An optional `int`. Defaults to `0`.
544 A second seed to avoid seed collision.
545 name: A name for the operation (optional).
547 Returns:
548 A `Tensor`. Has the same type as `value`.
549 """
550 _ctx = _context._context or _context.context()
551 tld = _ctx._thread_local_data
552 if tld.is_eager:
553 try:
554 _result = pywrap_tfe.TFE_Py_FastPathExecute(
555 _ctx, "RandomShuffle", name, value, "seed", seed, "seed2", seed2)
556 return _result
557 except _core._NotOkStatusException as e:
558 _ops.raise_from_not_ok_status(e, name)
559 except _core._FallbackException:
560 pass
561 try:
562 return random_shuffle_eager_fallback(
563 value, seed=seed, seed2=seed2, name=name, ctx=_ctx)
564 except _core._SymbolicException:
565 pass # Add nodes to the TensorFlow graph.
566 # Add nodes to the TensorFlow graph.
567 if seed is None:
568 seed = 0
569 seed = _execute.make_int(seed, "seed")
570 if seed2 is None:
571 seed2 = 0
572 seed2 = _execute.make_int(seed2, "seed2")
573 _, _, _op, _outputs = _op_def_library._apply_op_helper(
574 "RandomShuffle", value=value, seed=seed, seed2=seed2, name=name)
575 _result = _outputs[:]
576 if _execute.must_record_gradient():
577 _attrs = ("seed", _op._get_attr_int("seed"), "seed2",
578 _op._get_attr_int("seed2"), "T", _op._get_attr_type("T"))
579 _inputs_flat = _op.inputs
580 _execute.record_gradient(
581 "RandomShuffle", _inputs_flat, _attrs, _result)
582 _result, = _result
583 return _result
585RandomShuffle = tf_export("raw_ops.RandomShuffle")(_ops.to_raw_op(random_shuffle))
588def random_shuffle_eager_fallback(value, seed, seed2, name, ctx):
589 if seed is None:
590 seed = 0
591 seed = _execute.make_int(seed, "seed")
592 if seed2 is None:
593 seed2 = 0
594 seed2 = _execute.make_int(seed2, "seed2")
595 _attr_T, (value,) = _execute.args_to_matching_eager([value], ctx, [])
596 _inputs_flat = [value]
597 _attrs = ("seed", seed, "seed2", seed2, "T", _attr_T)
598 _result = _execute.execute(b"RandomShuffle", 1, inputs=_inputs_flat,
599 attrs=_attrs, ctx=ctx, name=name)
600 if _execute.must_record_gradient():
601 _execute.record_gradient(
602 "RandomShuffle", _inputs_flat, _attrs, _result)
603 _result, = _result
604 return _result
607def random_standard_normal(shape, dtype, seed=0, seed2=0, name=None):
608 r"""Outputs random values from a normal distribution.
610 The generated values will have mean 0 and standard deviation 1.
612 Args:
613 shape: A `Tensor`. Must be one of the following types: `int32`, `int64`.
614 The shape of the output tensor.
615 dtype: A `tf.DType` from: `tf.half, tf.bfloat16, tf.float32, tf.float64`.
616 The type of the output.
617 seed: An optional `int`. Defaults to `0`.
618 If either `seed` or `seed2` are set to be non-zero, the random number
619 generator is seeded by the given seed. Otherwise, it is seeded by a
620 random seed.
621 seed2: An optional `int`. Defaults to `0`.
622 A second seed to avoid seed collision.
623 name: A name for the operation (optional).
625 Returns:
626 A `Tensor` of type `dtype`.
627 """
628 _ctx = _context._context or _context.context()
629 tld = _ctx._thread_local_data
630 if tld.is_eager:
631 try:
632 _result = pywrap_tfe.TFE_Py_FastPathExecute(
633 _ctx, "RandomStandardNormal", name, shape, "seed", seed, "seed2",
634 seed2, "dtype", dtype)
635 return _result
636 except _core._NotOkStatusException as e:
637 _ops.raise_from_not_ok_status(e, name)
638 except _core._FallbackException:
639 pass
640 try:
641 return random_standard_normal_eager_fallback(
642 shape, seed=seed, seed2=seed2, dtype=dtype, name=name, ctx=_ctx)
643 except _core._SymbolicException:
644 pass # Add nodes to the TensorFlow graph.
645 # Add nodes to the TensorFlow graph.
646 dtype = _execute.make_type(dtype, "dtype")
647 if seed is None:
648 seed = 0
649 seed = _execute.make_int(seed, "seed")
650 if seed2 is None:
651 seed2 = 0
652 seed2 = _execute.make_int(seed2, "seed2")
653 _, _, _op, _outputs = _op_def_library._apply_op_helper(
654 "RandomStandardNormal", shape=shape, dtype=dtype, seed=seed,
655 seed2=seed2, name=name)
656 _result = _outputs[:]
657 if _execute.must_record_gradient():
658 _attrs = ("seed", _op._get_attr_int("seed"), "seed2",
659 _op._get_attr_int("seed2"), "dtype",
660 _op._get_attr_type("dtype"), "T", _op._get_attr_type("T"))
661 _inputs_flat = _op.inputs
662 _execute.record_gradient(
663 "RandomStandardNormal", _inputs_flat, _attrs, _result)
664 _result, = _result
665 return _result
667RandomStandardNormal = tf_export("raw_ops.RandomStandardNormal")(_ops.to_raw_op(random_standard_normal))
670def random_standard_normal_eager_fallback(shape, dtype, seed, seed2, name, ctx):
671 dtype = _execute.make_type(dtype, "dtype")
672 if seed is None:
673 seed = 0
674 seed = _execute.make_int(seed, "seed")
675 if seed2 is None:
676 seed2 = 0
677 seed2 = _execute.make_int(seed2, "seed2")
678 _attr_T, (shape,) = _execute.args_to_matching_eager([shape], ctx, [_dtypes.int32, _dtypes.int64, ])
679 _inputs_flat = [shape]
680 _attrs = ("seed", seed, "seed2", seed2, "dtype", dtype, "T", _attr_T)
681 _result = _execute.execute(b"RandomStandardNormal", 1, inputs=_inputs_flat,
682 attrs=_attrs, ctx=ctx, name=name)
683 if _execute.must_record_gradient():
684 _execute.record_gradient(
685 "RandomStandardNormal", _inputs_flat, _attrs, _result)
686 _result, = _result
687 return _result
690def random_uniform(shape, dtype, seed=0, seed2=0, name=None):
691 r"""Outputs random values from a uniform distribution.
693 The generated values follow a uniform distribution in the range `[0, 1)`. The
694 lower bound 0 is included in the range, while the upper bound 1 is excluded.
696 Args:
697 shape: A `Tensor`. Must be one of the following types: `int32`, `int64`.
698 The shape of the output tensor.
699 dtype: A `tf.DType` from: `tf.half, tf.bfloat16, tf.float32, tf.float64`.
700 The type of the output.
701 seed: An optional `int`. Defaults to `0`.
702 If either `seed` or `seed2` are set to be non-zero, the random number
703 generator is seeded by the given seed. Otherwise, it is seeded by a
704 random seed.
705 seed2: An optional `int`. Defaults to `0`.
706 A second seed to avoid seed collision.
707 name: A name for the operation (optional).
709 Returns:
710 A `Tensor` of type `dtype`.
711 """
712 _ctx = _context._context or _context.context()
713 tld = _ctx._thread_local_data
714 if tld.is_eager:
715 try:
716 _result = pywrap_tfe.TFE_Py_FastPathExecute(
717 _ctx, "RandomUniform", name, shape, "seed", seed, "seed2", seed2,
718 "dtype", dtype)
719 return _result
720 except _core._NotOkStatusException as e:
721 _ops.raise_from_not_ok_status(e, name)
722 except _core._FallbackException:
723 pass
724 try:
725 return random_uniform_eager_fallback(
726 shape, seed=seed, seed2=seed2, dtype=dtype, name=name, ctx=_ctx)
727 except _core._SymbolicException:
728 pass # Add nodes to the TensorFlow graph.
729 # Add nodes to the TensorFlow graph.
730 dtype = _execute.make_type(dtype, "dtype")
731 if seed is None:
732 seed = 0
733 seed = _execute.make_int(seed, "seed")
734 if seed2 is None:
735 seed2 = 0
736 seed2 = _execute.make_int(seed2, "seed2")
737 _, _, _op, _outputs = _op_def_library._apply_op_helper(
738 "RandomUniform", shape=shape, dtype=dtype, seed=seed, seed2=seed2,
739 name=name)
740 _result = _outputs[:]
741 if _execute.must_record_gradient():
742 _attrs = ("seed", _op._get_attr_int("seed"), "seed2",
743 _op._get_attr_int("seed2"), "dtype",
744 _op._get_attr_type("dtype"), "T", _op._get_attr_type("T"))
745 _inputs_flat = _op.inputs
746 _execute.record_gradient(
747 "RandomUniform", _inputs_flat, _attrs, _result)
748 _result, = _result
749 return _result
751RandomUniform = tf_export("raw_ops.RandomUniform")(_ops.to_raw_op(random_uniform))
754def random_uniform_eager_fallback(shape, dtype, seed, seed2, name, ctx):
755 dtype = _execute.make_type(dtype, "dtype")
756 if seed is None:
757 seed = 0
758 seed = _execute.make_int(seed, "seed")
759 if seed2 is None:
760 seed2 = 0
761 seed2 = _execute.make_int(seed2, "seed2")
762 _attr_T, (shape,) = _execute.args_to_matching_eager([shape], ctx, [_dtypes.int32, _dtypes.int64, ])
763 _inputs_flat = [shape]
764 _attrs = ("seed", seed, "seed2", seed2, "dtype", dtype, "T", _attr_T)
765 _result = _execute.execute(b"RandomUniform", 1, inputs=_inputs_flat,
766 attrs=_attrs, ctx=ctx, name=name)
767 if _execute.must_record_gradient():
768 _execute.record_gradient(
769 "RandomUniform", _inputs_flat, _attrs, _result)
770 _result, = _result
771 return _result
774def random_uniform_int(shape, minval, maxval, seed=0, seed2=0, name=None):
775 r"""Outputs random integers from a uniform distribution.
777 The generated values are uniform integers in the range `[minval, maxval)`.
778 The lower bound `minval` is included in the range, while the upper bound
779 `maxval` is excluded.
781 The random integers are slightly biased unless `maxval - minval` is an exact
782 power of two. The bias is small for values of `maxval - minval` significantly
783 smaller than the range of the output (either `2^32` or `2^64`).
785 Args:
786 shape: A `Tensor`. Must be one of the following types: `int32`, `int64`.
787 The shape of the output tensor.
788 minval: A `Tensor`. Must be one of the following types: `int32`, `int64`.
789 0-D. Inclusive lower bound on the generated integers.
790 maxval: A `Tensor`. Must have the same type as `minval`.
791 0-D. Exclusive upper bound on the generated integers.
792 seed: An optional `int`. Defaults to `0`.
793 If either `seed` or `seed2` are set to be non-zero, the random number
794 generator is seeded by the given seed. Otherwise, it is seeded by a
795 random seed.
796 seed2: An optional `int`. Defaults to `0`.
797 A second seed to avoid seed collision.
798 name: A name for the operation (optional).
800 Returns:
801 A `Tensor`. Has the same type as `minval`.
802 """
803 _ctx = _context._context or _context.context()
804 tld = _ctx._thread_local_data
805 if tld.is_eager:
806 try:
807 _result = pywrap_tfe.TFE_Py_FastPathExecute(
808 _ctx, "RandomUniformInt", name, shape, minval, maxval, "seed", seed,
809 "seed2", seed2)
810 return _result
811 except _core._NotOkStatusException as e:
812 _ops.raise_from_not_ok_status(e, name)
813 except _core._FallbackException:
814 pass
815 try:
816 return random_uniform_int_eager_fallback(
817 shape, minval, maxval, seed=seed, seed2=seed2, name=name, ctx=_ctx)
818 except _core._SymbolicException:
819 pass # Add nodes to the TensorFlow graph.
820 # Add nodes to the TensorFlow graph.
821 if seed is None:
822 seed = 0
823 seed = _execute.make_int(seed, "seed")
824 if seed2 is None:
825 seed2 = 0
826 seed2 = _execute.make_int(seed2, "seed2")
827 _, _, _op, _outputs = _op_def_library._apply_op_helper(
828 "RandomUniformInt", shape=shape, minval=minval, maxval=maxval,
829 seed=seed, seed2=seed2, name=name)
830 _result = _outputs[:]
831 if _execute.must_record_gradient():
832 _attrs = ("seed", _op._get_attr_int("seed"), "seed2",
833 _op._get_attr_int("seed2"), "Tout", _op._get_attr_type("Tout"),
834 "T", _op._get_attr_type("T"))
835 _inputs_flat = _op.inputs
836 _execute.record_gradient(
837 "RandomUniformInt", _inputs_flat, _attrs, _result)
838 _result, = _result
839 return _result
841RandomUniformInt = tf_export("raw_ops.RandomUniformInt")(_ops.to_raw_op(random_uniform_int))
844def random_uniform_int_eager_fallback(shape, minval, maxval, seed, seed2, name, ctx):
845 if seed is None:
846 seed = 0
847 seed = _execute.make_int(seed, "seed")
848 if seed2 is None:
849 seed2 = 0
850 seed2 = _execute.make_int(seed2, "seed2")
851 _attr_Tout, _inputs_Tout = _execute.args_to_matching_eager([minval, maxval], ctx, [_dtypes.int32, _dtypes.int64, ])
852 (minval, maxval) = _inputs_Tout
853 _attr_T, (shape,) = _execute.args_to_matching_eager([shape], ctx, [_dtypes.int32, _dtypes.int64, ])
854 _inputs_flat = [shape, minval, maxval]
855 _attrs = ("seed", seed, "seed2", seed2, "Tout", _attr_Tout, "T", _attr_T)
856 _result = _execute.execute(b"RandomUniformInt", 1, inputs=_inputs_flat,
857 attrs=_attrs, ctx=ctx, name=name)
858 if _execute.must_record_gradient():
859 _execute.record_gradient(
860 "RandomUniformInt", _inputs_flat, _attrs, _result)
861 _result, = _result
862 return _result
865def truncated_normal(shape, dtype, seed=0, seed2=0, name=None):
866 r"""Outputs random values from a truncated normal distribution.
868 The generated values follow a normal distribution with mean 0 and standard
869 deviation 1, except that values whose magnitude is more than 2 standard
870 deviations from the mean are dropped and re-picked.
872 Args:
873 shape: A `Tensor`. Must be one of the following types: `int32`, `int64`.
874 The shape of the output tensor.
875 dtype: A `tf.DType` from: `tf.half, tf.bfloat16, tf.float32, tf.float64`.
876 The type of the output.
877 seed: An optional `int`. Defaults to `0`.
878 If either `seed` or `seed2` are set to be non-zero, the random number
879 generator is seeded by the given seed. Otherwise, it is seeded by a
880 random seed.
881 seed2: An optional `int`. Defaults to `0`.
882 A second seed to avoid seed collision.
883 name: A name for the operation (optional).
885 Returns:
886 A `Tensor` of type `dtype`.
887 """
888 _ctx = _context._context or _context.context()
889 tld = _ctx._thread_local_data
890 if tld.is_eager:
891 try:
892 _result = pywrap_tfe.TFE_Py_FastPathExecute(
893 _ctx, "TruncatedNormal", name, shape, "seed", seed, "seed2", seed2,
894 "dtype", dtype)
895 return _result
896 except _core._NotOkStatusException as e:
897 _ops.raise_from_not_ok_status(e, name)
898 except _core._FallbackException:
899 pass
900 try:
901 return truncated_normal_eager_fallback(
902 shape, seed=seed, seed2=seed2, dtype=dtype, name=name, ctx=_ctx)
903 except _core._SymbolicException:
904 pass # Add nodes to the TensorFlow graph.
905 # Add nodes to the TensorFlow graph.
906 dtype = _execute.make_type(dtype, "dtype")
907 if seed is None:
908 seed = 0
909 seed = _execute.make_int(seed, "seed")
910 if seed2 is None:
911 seed2 = 0
912 seed2 = _execute.make_int(seed2, "seed2")
913 _, _, _op, _outputs = _op_def_library._apply_op_helper(
914 "TruncatedNormal", shape=shape, dtype=dtype, seed=seed, seed2=seed2,
915 name=name)
916 _result = _outputs[:]
917 if _execute.must_record_gradient():
918 _attrs = ("seed", _op._get_attr_int("seed"), "seed2",
919 _op._get_attr_int("seed2"), "dtype",
920 _op._get_attr_type("dtype"), "T", _op._get_attr_type("T"))
921 _inputs_flat = _op.inputs
922 _execute.record_gradient(
923 "TruncatedNormal", _inputs_flat, _attrs, _result)
924 _result, = _result
925 return _result
927TruncatedNormal = tf_export("raw_ops.TruncatedNormal")(_ops.to_raw_op(truncated_normal))
930def truncated_normal_eager_fallback(shape, dtype, seed, seed2, name, ctx):
931 dtype = _execute.make_type(dtype, "dtype")
932 if seed is None:
933 seed = 0
934 seed = _execute.make_int(seed, "seed")
935 if seed2 is None:
936 seed2 = 0
937 seed2 = _execute.make_int(seed2, "seed2")
938 _attr_T, (shape,) = _execute.args_to_matching_eager([shape], ctx, [_dtypes.int32, _dtypes.int64, ])
939 _inputs_flat = [shape]
940 _attrs = ("seed", seed, "seed2", seed2, "dtype", dtype, "T", _attr_T)
941 _result = _execute.execute(b"TruncatedNormal", 1, inputs=_inputs_flat,
942 attrs=_attrs, ctx=ctx, name=name)
943 if _execute.must_record_gradient():
944 _execute.record_gradient(
945 "TruncatedNormal", _inputs_flat, _attrs, _result)
946 _result, = _result
947 return _result