Gets the difference x[1:] - x[:-1].
(x)
| 1854 | |
| 1855 | # pylint: disable=line-too-long |
| 1856 | def _get_diff_for_monotonic_comparison(x): |
| 1857 | """Gets the difference x[1:] - x[:-1].""" |
| 1858 | x = array_ops.reshape(x, [-1]) |
| 1859 | if not is_numeric_tensor(x): |
| 1860 | raise TypeError('Expected x to be numeric, instead found: %s' % x) |
| 1861 | |
| 1862 | # If x has less than 2 elements, there is nothing to compare. So return []. |
| 1863 | is_shorter_than_two = math_ops.less(array_ops.size(x), 2) |
| 1864 | short_result = lambda: ops.convert_to_tensor([], dtype=x.dtype) |
| 1865 | |
| 1866 | # With 2 or more elements, return x[1:] - x[:-1] |
| 1867 | s_len = array_ops.shape(x) - 1 |
| 1868 | diff = lambda: array_ops.strided_slice(x, [1], [1] + s_len)- array_ops.strided_slice(x, [0], s_len) |
| 1869 | return control_flow_ops.cond(is_shorter_than_two, short_result, diff) |
| 1870 | |
| 1871 | |
| 1872 | @tf_export( |
no test coverage detected