code: def test_translation():
      x = np.array(
          [
              [0, 0, 0, 0],
              [0, 1, 0, 0],
              [0, 0, 0, 0],
          ]
      )
      x_up = np.array(
          [
              [0, 1, 0, 0],
              [0, 0, 0, 0],
              [0, 0, 0, 0],
          ]
      )
      x_dn = np.array(
          [
              [0, 0, 0, 0],
              [0, 0, 0, 0],
              [0, 1, 0, 0],
          ]
      )
      x_left = np.array(
          [
              [0, 0, 0, 0],
              [1, 0, 0, 0],
              [0, 0, 0, 0],
          ]
      )
      x_right = np.array(
          [
              [0, 0, 0, 0],
              [0, 0, 1, 0],
              [0, 0, 0, 0],
          ]
      )
  
      # Channels first
      x_test = np.expand_dims(x, 0)
  
      # Horizontal translation
      assert np.alltrue(
          x_left
          == np.squeeze(
              affine_transformations.apply_affine_transform(
                  x_test, tx=1
              )
          )
      )
      assert np.alltrue(
          x_right
          == np.squeeze(
              affine_transformations.apply_affine_transform(
                  x_test, tx=-1
              )
          )
      )
  
      # change axes: x<->y
      assert np.alltrue(
          x_left
          == np.squeeze(
              affine_transformations.apply_affine_transform(
                  x_test, ty=1, row_axis=2, col_axis=1
              )
          )
      )
      assert np.alltrue(
          x_right
          == np.squeeze(
              affine_transformations.apply_affine_transform(
                  x_test, ty=-1, row_axis=2, col_axis=1
              )
          )
      )
  
      # Vertical translation
      assert np.alltrue(
          x_up
          == np.squeeze(
              affine_transformations.apply_affine_transform(
                  x_test, ty=1
              )
          )
      )
      assert np.alltrue(
          x_dn
          == np.squeeze(
              affine_transformations.apply_affine_transform(
                  x_test, ty=-1
              )
          )
      )
  
      # change axes: x<->y
      assert np.alltrue(
          x_up
          == np.squeeze(
              affine_transformations.apply_affine_transform(
                  x_test, tx=1, row_axis=2, col_axis=1
              )
          )
      )
      assert np.alltrue(
          x_dn
          == np.squeeze(
              affine_transformations.apply_affine_transform(
                  x_test, tx=-1, row_axis=2, col_axis=1
              )
          )
      )
  
      # Channels last
      x_test = np.expand_dims(x, -1)
  
      # Horizontal translation
      assert np.alltrue(
          x_left
          == np.squeeze(
              affine_transformations.apply_affine_transform(
                  x_test, tx=1, row_axis=0, col_axis=1, channel_axis=2
              )
          )
      )
      assert np.alltrue(
          x_right
          == np.squeeze(
              affine_transformations.apply_affine_transform(
                  x_test, tx=-1, row_axis=0, col_axis=1, channel_axis=2
              )
          )
      )
  
      # change axes: x<->y
      assert np.alltrue(
          x_left
          == np.squeeze(
              affine_transformations.apply_affine_transform(
                  x_test, ty=1, row_axis=1, col_axis=0, channel_axis=2
              )
          )
      )
      assert np.alltrue(
          x_right
          == np.squeeze(
              affine_transformations.apply_affine_transform(
                  x_test, ty=-1, row_axis=1, col_axis=0, channel_axis=2
              )
          )
      )
  
      # Vertical translation
      assert np.alltrue(
          x_up
          == np.squeeze(
              affine_transformations.apply_affine_transform(
                  x_test, ty=1, row_axis=0, col_axis=1, channel_axis=2
              )
          )
      )
      assert np.alltrue(
          x_dn
          == np.squeeze(
              affine_transformations.apply_affine_transform(
                  x_test, ty=-1, row_axis=0, col_axis=1, channel_axis=2
              )
          )
      )
  
      # change axes: x<->y
      assert np.alltrue(
          x_up
          == np.squeeze(
              affine_transformations.apply_affine_transform(
                  x_test, tx=1, row_axis=1, col_axis=0, channel_axis=2
              )
          )
      )
      assert np.alltrue(
          x_dn
          == np.squeeze(
              affine_transformations.apply_affine_transform(
                  x_test, tx=-1, row_axis=1, col_axis=0, channel_axis=2
              )
          )
      )
  
file_path: keras-preprocessing/tests/image/affine_transformations_test.py
imports: import numpy
  import pytest
  from keras_preprocessing.image import affine_transformations
label_desc: Use image node_id 4 for calling a global function with example usage: test_translation() without return types