mirror of
https://github.com/tensorflow/tensorflow.git
synced 2026-10-26 00:09:51 +08:00
Merge pull request #129183 from MaddipatlaChetan24:patch-72
PiperOrigin-RevId: 1004288413
This commit is contained in:
commit
3f385c823d
2 files changed
+21
No files matched your search
@@ -1204,6 +1204,11 @@ def moveaxis(a, source, destination): # pylint: disable=missing-docstring
|
||||
and builtins.all(isinstance(x, (int, np.integer)) for x in source)
|
||||
and builtins.all(isinstance(x, (int, np.integer)) for x in destination)
|
||||
):
|
||||
# NumPy rejects a repeated axis in `source` or `destination`.
|
||||
if len(set(source)) != len(source):
|
||||
raise ValueError('repeated axis in `source` argument')
|
||||
if len(set(destination)) != len(destination):
|
||||
raise ValueError('repeated axis in `destination` argument')
|
||||
perm = [i for i in range(a_rank) if i not in source]
|
||||
for dest, src in sorted(zip(destination, source)):
|
||||
assert dest <= len(perm)
|
||||
|
||||
@@ -1577,6 +1577,22 @@ class ArrayMethodsTest(test.TestCase):
|
||||
np_array_ops.moveaxis(a, -8, 0)
|
||||
with self.assertRaisesRegex(ValueError, 'out of bounds'):
|
||||
np_array_ops.moveaxis(a, 0, 8)
|
||||
with self.assertRaisesRegex(
|
||||
ValueError, 'repeated axis in `source` argument'
|
||||
):
|
||||
np_array_ops.moveaxis(a, (0, 0), (1, 2))
|
||||
with self.assertRaisesRegex(
|
||||
ValueError, 'repeated axis in `source` argument'
|
||||
):
|
||||
np_array_ops.moveaxis(a, (0, -6), (1, 2))
|
||||
with self.assertRaisesRegex(
|
||||
ValueError, 'repeated axis in `destination` argument'
|
||||
):
|
||||
np_array_ops.moveaxis(a, (0, 1), (2, 2))
|
||||
with self.assertRaisesRegex(
|
||||
ValueError, 'repeated axis in `destination` argument'
|
||||
):
|
||||
np_array_ops.moveaxis(a, (0, 1), (2, -4))
|
||||
|
||||
def testFlip(self):
|
||||
np.random.seed(0)
|
||||
|
||||
Reference in new issue
Block a user