Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow/python/ops/gen_manip_ops.py: 35%
49 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 roll(input, shift, axis, name=None):
25 r"""Rolls the elements of a tensor along an axis.
27 The elements are shifted positively (towards larger indices) by the offset of
28 `shift` along the dimension of `axis`. Negative `shift` values will shift
29 elements in the opposite direction. Elements that roll passed the last position
30 will wrap around to the first and vice versa. Multiple shifts along multiple
31 axes may be specified.
33 For example:
35 ```
36 # 't' is [0, 1, 2, 3, 4]
37 roll(t, shift=2, axis=0) ==> [3, 4, 0, 1, 2]
39 # shifting along multiple dimensions
40 # 't' is [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]
41 roll(t, shift=[1, -2], axis=[0, 1]) ==> [[7, 8, 9, 5, 6], [2, 3, 4, 0, 1]]
43 # shifting along the same axis multiple times
44 # 't' is [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]
45 roll(t, shift=[2, -3], axis=[1, 1]) ==> [[1, 2, 3, 4, 0], [6, 7, 8, 9, 5]]
46 ```
48 Args:
49 input: A `Tensor`.
50 shift: A `Tensor`. Must be one of the following types: `int32`, `int64`.
51 Dimension must be 0-D or 1-D. `shift[i]` specifies the number of places by which
52 elements are shifted positively (towards larger indices) along the dimension
53 specified by `axis[i]`. Negative shifts will roll the elements in the opposite
54 direction.
55 axis: A `Tensor`. Must be one of the following types: `int32`, `int64`.
56 Dimension must be 0-D or 1-D. `axis[i]` specifies the dimension that the shift
57 `shift[i]` should occur. If the same axis is referenced more than once, the
58 total shift for that axis will be the sum of all the shifts that belong to that
59 axis.
60 name: A name for the operation (optional).
62 Returns:
63 A `Tensor`. Has the same type as `input`.
64 """
65 _ctx = _context._context or _context.context()
66 tld = _ctx._thread_local_data
67 if tld.is_eager:
68 try:
69 _result = pywrap_tfe.TFE_Py_FastPathExecute(
70 _ctx, "Roll", name, input, shift, axis)
71 return _result
72 except _core._NotOkStatusException as e:
73 _ops.raise_from_not_ok_status(e, name)
74 except _core._FallbackException:
75 pass
76 try:
77 return roll_eager_fallback(
78 input, shift, axis, name=name, ctx=_ctx)
79 except _core._SymbolicException:
80 pass # Add nodes to the TensorFlow graph.
81 # Add nodes to the TensorFlow graph.
82 _, _, _op, _outputs = _op_def_library._apply_op_helper(
83 "Roll", input=input, shift=shift, axis=axis, name=name)
84 _result = _outputs[:]
85 if _execute.must_record_gradient():
86 _attrs = ("T", _op._get_attr_type("T"), "Tshift",
87 _op._get_attr_type("Tshift"), "Taxis",
88 _op._get_attr_type("Taxis"))
89 _inputs_flat = _op.inputs
90 _execute.record_gradient(
91 "Roll", _inputs_flat, _attrs, _result)
92 _result, = _result
93 return _result
95Roll = tf_export("raw_ops.Roll")(_ops.to_raw_op(roll))
98def roll_eager_fallback(input, shift, axis, name, ctx):
99 _attr_T, (input,) = _execute.args_to_matching_eager([input], ctx, [])
100 _attr_Tshift, (shift,) = _execute.args_to_matching_eager([shift], ctx, [_dtypes.int32, _dtypes.int64, ])
101 _attr_Taxis, (axis,) = _execute.args_to_matching_eager([axis], ctx, [_dtypes.int32, _dtypes.int64, ])
102 _inputs_flat = [input, shift, axis]
103 _attrs = ("T", _attr_T, "Tshift", _attr_Tshift, "Taxis", _attr_Taxis)
104 _result = _execute.execute(b"Roll", 1, inputs=_inputs_flat, attrs=_attrs,
105 ctx=ctx, name=name)
106 if _execute.must_record_gradient():
107 _execute.record_gradient(
108 "Roll", _inputs_flat, _attrs, _result)
109 _result, = _result
110 return _result