
import unittest

import numpy as np
import requests

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
    import torch

    from transformers.pytorch_utils import is_torch_greater_or_equal_than_1_11
else:
    lowerCamelCase_							=     False

if is_vision_available():
    from PIL import Image

    from transformers import PixaStructImageProcessor




class 	__A(				unittest.TestCase ):

  """simple docstring"""







  def __init__(self       ,			SCREAMING_SNAKE_CASE_       ,			SCREAMING_SNAKE_CASE_=7       ,			SCREAMING_SNAKE_CASE_=3       ,			SCREAMING_SNAKE_CASE_=18       ,			SCREAMING_SNAKE_CASE_=30       ,			SCREAMING_SNAKE_CASE_=4_00       ,			SCREAMING_SNAKE_CASE_=None       ,			SCREAMING_SNAKE_CASE_=True       ,			SCREAMING_SNAKE_CASE_=True       ,			SCREAMING_SNAKE_CASE_=None       ,			):
       UpperCamelCase__				=				size if size is not None else {'height': 20, 'width': 20}
       UpperCamelCase__				=				parent
       UpperCamelCase__				=				batch_size
       UpperCamelCase__				=				num_channels
       UpperCamelCase__				=				image_size
       UpperCamelCase__				=				min_resolution
       UpperCamelCase__				=				max_resolution
       UpperCamelCase__				=				size
       UpperCamelCase__				=				do_normalize
       UpperCamelCase__				=				do_convert_rgb
       UpperCamelCase__				=				[5_12, 10_24, 20_48, 40_96]
       UpperCamelCase__				=				patch_size if patch_size is not None else {'height': 16, 'width': 16}







  def        UpperCAmelCase_					(self						):
       return {"do_normalize": self.do_normalize, "do_convert_rgb": self.do_convert_rgb}







  def        UpperCAmelCase_					(self						):
       UpperCamelCase__				=				'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/australia.jpg'
       UpperCamelCase__				=				Image.open(requests.get(_UpperCAmelCase       ,			stream=_UpperCAmelCase						).raw						).convert("""RGB"""						)
       return raw_image






@unittest.skipIf(
    not is_torch_greater_or_equal_than_1_11				,      reason="""`Pix2StructImageProcessor` requires `torch>=1.11.0`."""				,      )
@require_torch
@require_vision
class 	__A(				a__				,      unittest.TestCase ):

  """simple docstring"""
  SCREAMING_SNAKE_CASE__			    =			PixaStructImageProcessor if is_vision_available() else None







  def        UpperCAmelCase_					(self						):
       UpperCamelCase__				=				PixaStructImageProcessingTester(self						)







  @property
  def        UpperCAmelCase_					(self						):
       return self.image_processor_tester.prepare_image_processor_dict()







  def        UpperCAmelCase_					(self						):
       UpperCamelCase__				=				self.image_processing_class(**self.image_processor_dict						)
       self.assertTrue(hasattr(_UpperCAmelCase       ,			"""do_normalize"""						)						)
       self.assertTrue(hasattr(_UpperCAmelCase       ,			"""do_convert_rgb"""						)						)







  def        UpperCAmelCase_					(self						):
       UpperCamelCase__				=				self.image_processor_tester.prepare_dummy_image()

       UpperCamelCase__				=				self.image_processing_class(**self.image_processor_dict						)
       UpperCamelCase__				=				20_48

       UpperCamelCase__				=				image_processor(_UpperCAmelCase       ,			return_tensors="""pt"""       ,			max_patches=_UpperCAmelCase						)
       self.assertTrue(torch.allclose(inputs.flattened_patches.mean()       ,			torch.tensor(0.0606						)       ,			atol=1E-3       ,			rtol=1E-3						)						)







  def        UpperCAmelCase_					(self						):
       UpperCamelCase__				=				self.image_processing_class(**self.image_processor_dict						)
       # create random PIL images
       UpperCamelCase__				=				prepare_image_inputs(self.image_processor_tester       ,			equal_resolution=_UpperCAmelCase						)
       for image in image_inputs:
            self.assertIsInstance(_UpperCAmelCase       ,			Image.Image						)

       # Test not batched input
       UpperCamelCase__				=				(
           (self.image_processor_tester.patch_size['height'] * self.image_processor_tester.patch_size['width'])
           * self.image_processor_tester.num_channels
       ) + 2

       for max_patch in self.image_processor_tester.max_patches:
            # Test not batched input
            UpperCamelCase__				=				image_processor(
                image_inputs[0]       ,			return_tensors="""pt"""       ,			max_patches=_UpperCAmelCase						).flattened_patches
            self.assertEqual(
                encoded_images.shape       ,			(1, max_patch, expected_hidden_dim)       ,			)

            # Test batched
            UpperCamelCase__				=				image_processor(
                _UpperCAmelCase       ,			return_tensors="""pt"""       ,			max_patches=_UpperCAmelCase						).flattened_patches
            self.assertEqual(
                encoded_images.shape       ,			(self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)       ,			)







  def        UpperCAmelCase_					(self						):
       UpperCamelCase__				=				self.image_processing_class(**self.image_processor_dict						)
       # create random PIL images
       UpperCamelCase__				=				prepare_image_inputs(self.image_processor_tester       ,			equal_resolution=_UpperCAmelCase						)
       for image in image_inputs:
            self.assertIsInstance(_UpperCAmelCase       ,			Image.Image						)

       # Test not batched input
       UpperCamelCase__				=				(
           (self.image_processor_tester.patch_size['height'] * self.image_processor_tester.patch_size['width'])
           * self.image_processor_tester.num_channels
       ) + 2

       UpperCamelCase__				=				True

       for max_patch in self.image_processor_tester.max_patches:
            # Test not batched input
            with self.assertRaises(_UpperCAmelCase						):
                 UpperCamelCase__				=				image_processor(
                     image_inputs[0]       ,			return_tensors="""pt"""       ,			max_patches=_UpperCAmelCase						).flattened_patches

            UpperCamelCase__				=				'Hello'

            UpperCamelCase__				=				image_processor(
                image_inputs[0]       ,			return_tensors="""pt"""       ,			max_patches=_UpperCAmelCase       ,			header_text=_UpperCAmelCase						).flattened_patches
            self.assertEqual(
                encoded_images.shape       ,			(1, max_patch, expected_hidden_dim)       ,			)

            # Test batched
            UpperCamelCase__				=				image_processor(
                _UpperCAmelCase       ,			return_tensors="""pt"""       ,			max_patches=_UpperCAmelCase       ,			header_text=_UpperCAmelCase						).flattened_patches
            self.assertEqual(
                encoded_images.shape       ,			(self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)       ,			)







  def        UpperCAmelCase_					(self						):
       UpperCamelCase__				=				self.image_processing_class(**self.image_processor_dict						)
       # create random numpy tensors
       UpperCamelCase__				=				prepare_image_inputs(self.image_processor_tester       ,			equal_resolution=_UpperCAmelCase       ,			numpify=_UpperCAmelCase						)
       for image in image_inputs:
            self.assertIsInstance(_UpperCAmelCase       ,			np.ndarray						)

       UpperCamelCase__				=				(
           (self.image_processor_tester.patch_size['height'] * self.image_processor_tester.patch_size['width'])
           * self.image_processor_tester.num_channels
       ) + 2

       for max_patch in self.image_processor_tester.max_patches:
            # Test not batched input
            UpperCamelCase__				=				image_processor(
                image_inputs[0]       ,			return_tensors="""pt"""       ,			max_patches=_UpperCAmelCase						).flattened_patches
            self.assertEqual(
                encoded_images.shape       ,			(1, max_patch, expected_hidden_dim)       ,			)

            # Test batched
            UpperCamelCase__				=				image_processor(
                _UpperCAmelCase       ,			return_tensors="""pt"""       ,			max_patches=_UpperCAmelCase						).flattened_patches
            self.assertEqual(
                encoded_images.shape       ,			(self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)       ,			)







  def        UpperCAmelCase_					(self						):
       UpperCamelCase__				=				self.image_processing_class(**self.image_processor_dict						)
       # create random PyTorch tensors
       UpperCamelCase__				=				prepare_image_inputs(self.image_processor_tester       ,			equal_resolution=_UpperCAmelCase       ,			torchify=_UpperCAmelCase						)
       for image in image_inputs:
            self.assertIsInstance(_UpperCAmelCase       ,			torch.Tensor						)

       # Test not batched input
       UpperCamelCase__				=				(
           (self.image_processor_tester.patch_size['height'] * self.image_processor_tester.patch_size['width'])
           * self.image_processor_tester.num_channels
       ) + 2

       for max_patch in self.image_processor_tester.max_patches:
            # Test not batched input
            UpperCamelCase__				=				image_processor(
                image_inputs[0]       ,			return_tensors="""pt"""       ,			max_patches=_UpperCAmelCase						).flattened_patches
            self.assertEqual(
                encoded_images.shape       ,			(1, max_patch, expected_hidden_dim)       ,			)

            # Test batched
            UpperCamelCase__				=				image_processor(
                _UpperCAmelCase       ,			return_tensors="""pt"""       ,			max_patches=_UpperCAmelCase						).flattened_patches
            self.assertEqual(
                encoded_images.shape       ,			(self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)       ,			)






@unittest.skipIf(
    not is_torch_greater_or_equal_than_1_11				,      reason="""`Pix2StructImageProcessor` requires `torch>=1.11.0`."""				,      )
@require_torch
@require_vision
class 	__A(				a__				,      unittest.TestCase ):

  """simple docstring"""
  SCREAMING_SNAKE_CASE__			    =			PixaStructImageProcessor if is_vision_available() else None







  def        UpperCAmelCase_					(self						):
       UpperCamelCase__				=				PixaStructImageProcessingTester(self       ,			num_channels=4						)
       UpperCamelCase__				=				3







  @property
  def        UpperCAmelCase_					(self						):
       return self.image_processor_tester.prepare_image_processor_dict()







  def        UpperCAmelCase_					(self						):
       UpperCamelCase__				=				self.image_processing_class(**self.image_processor_dict						)
       self.assertTrue(hasattr(_UpperCAmelCase       ,			"""do_normalize"""						)						)
       self.assertTrue(hasattr(_UpperCAmelCase       ,			"""do_convert_rgb"""						)						)







  def        UpperCAmelCase_					(self						):
       UpperCamelCase__				=				self.image_processing_class(**self.image_processor_dict						)
       # create random PIL images
       UpperCamelCase__				=				prepare_image_inputs(self.image_processor_tester       ,			equal_resolution=_UpperCAmelCase						)
       for image in image_inputs:
            self.assertIsInstance(_UpperCAmelCase       ,			Image.Image						)

       # Test not batched input
       UpperCamelCase__				=				(
           (self.image_processor_tester.patch_size['height'] * self.image_processor_tester.patch_size['width'])
           * (self.image_processor_tester.num_channels - 1)
       ) + 2

       for max_patch in self.image_processor_tester.max_patches:
            # Test not batched input
            UpperCamelCase__				=				image_processor(
                image_inputs[0]       ,			return_tensors="""pt"""       ,			max_patches=_UpperCAmelCase						).flattened_patches
            self.assertEqual(
                encoded_images.shape       ,			(1, max_patch, expected_hidden_dim)       ,			)

            # Test batched
            UpperCamelCase__				=				image_processor(
                _UpperCAmelCase       ,			return_tensors="""pt"""       ,			max_patches=_UpperCAmelCase						).flattened_patches
            self.assertEqual(
                encoded_images.shape       ,			(self.image_processor_tester.batch_size, max_patch, expected_hidden_dim)       ,			)












'''simple docstring'''




import os
import tempfile
import unittest

import numpy as np

from diffusers.utils import is_flax_available
from diffusers.utils.testing_utils import require_flax, slow


if is_flax_available():
  import jax
  import jax.numpy as jnp
  from flax.jax_utils import replicate
  from flax.training.common_utils import shard

  from diffusers import FlaxDDIMScheduler, FlaxDiffusionPipeline, FlaxStableDiffusionPipeline


@require_flax
class  SCREAMING_SNAKE_CASE    (unittest.TestCase							):


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          with tempfile.TemporaryDirectory() as tmpdirname:
               # pipeline has Flax weights
               __A						: Union[str, Any]      =       FlaxDiffusionPipeline.from_pretrained(
                   'hf-internal-testing/tiny-stable-diffusion-pipe'						,	safety_checker=_UpperCAmelCase						,	cache_dir=_UpperCAmelCase)

               __A						: Optional[Any]      =       [t[-1] for t in os.walk(os.path.join(_UpperCAmelCase						,	os.listdir(_UpperCAmelCase)[0]						,	'snapshots'))]
               __A						: int      =       [item for sublist in all_root_files for item in sublist]

               # None of the downloaded files should be a PyTorch file even if we have some here:
               # https://huggingface.co/hf-internal-testing/tiny-stable-diffusion-pipe/blob/main/unet/diffusion_pytorch_model.bin
               assert not any(f.endswith('.bin') for f in files)




@slow
@require_flax
class  SCREAMING_SNAKE_CASE    (unittest.TestCase							):


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A ,__A						: Optional[int]      =       FlaxStableDiffusionPipeline.from_pretrained(
              'hf-internal-testing/tiny-stable-diffusion-pipe'						,	safety_checker=_UpperCAmelCase)

          __A						: Dict      =       (
              'A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'
              ' field, close up, split lighting, cinematic'
          )

          __A						: Optional[Any]      =       jax.random.PRNGKey(0)
          __A						: int      =       4

          __A						: Tuple      =       jax.device_count()
          __A						: Union[str, Any]      =       num_samples * [prompt]
          __A						: Tuple      =       pipeline.prepare_inputs(_UpperCAmelCase)

          # shard inputs and rng
          __A						: str      =       replicate(_UpperCAmelCase)
          __A						: Tuple      =       jax.random.split(_UpperCAmelCase						,	_UpperCAmelCase)
          __A						: Union[str, Any]      =       shard(_UpperCAmelCase)

          __A						: Union[str, Any]      =       pipeline(_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	jit=_UpperCAmelCase).images

          assert images.shape == (num_samples, 1, 64, 64, 3)
          if jax.device_count() == 8:
               assert np.abs(np.abs(images[0, 0, :2, :2, -2:]						,	dtype=np.floataa).sum() - 4.1514745) < 1e-3
               assert np.abs(np.abs(_UpperCAmelCase						,	dtype=np.floataa).sum() - 49947.875) < 5e-1

          __A						: List[str]      =       pipeline.numpy_to_pil(np.asarray(images.reshape((num_samples,) + images.shape[-3:])))
          assert len(_UpperCAmelCase) == num_samples


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A ,__A						: str      =       FlaxStableDiffusionPipeline.from_pretrained(
              'CompVis/stable-diffusion-v1-4'						,	revision='flax'						,	safety_checker=_UpperCAmelCase)

          __A						: List[Any]      =       (
              'A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'
              ' field, close up, split lighting, cinematic'
          )

          __A						: Tuple      =       jax.random.PRNGKey(0)
          __A						: Any      =       50

          __A						: str      =       jax.device_count()
          __A						: Union[str, Any]      =       num_samples * [prompt]
          __A						: List[str]      =       pipeline.prepare_inputs(_UpperCAmelCase)

          # shard inputs and rng
          __A						: Dict      =       replicate(_UpperCAmelCase)
          __A						: Optional[Any]      =       jax.random.split(_UpperCAmelCase						,	_UpperCAmelCase)
          __A						: int      =       shard(_UpperCAmelCase)

          __A						: Tuple      =       pipeline(_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	jit=_UpperCAmelCase).images

          assert images.shape == (num_samples, 1, 512, 512, 3)
          if jax.device_count() == 8:
               assert np.abs((np.abs(images[0, 0, :2, :2, -2:]						,	dtype=np.floataa).sum() - 0.05652401)) < 1e-3
               assert np.abs((np.abs(_UpperCAmelCase						,	dtype=np.floataa).sum() - 2383808.2)) < 5e-1


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A ,__A						: List[str]      =       FlaxStableDiffusionPipeline.from_pretrained(
              'CompVis/stable-diffusion-v1-4'						,	revision='bf16'						,	dtype=jnp.bfloataa						,	safety_checker=_UpperCAmelCase)

          __A						: List[Any]      =       (
              'A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'
              ' field, close up, split lighting, cinematic'
          )

          __A						: str      =       jax.random.PRNGKey(0)
          __A						: Any      =       50

          __A						: Optional[int]      =       jax.device_count()
          __A						: int      =       num_samples * [prompt]
          __A						: Optional[int]      =       pipeline.prepare_inputs(_UpperCAmelCase)

          # shard inputs and rng
          __A						: Optional[int]      =       replicate(_UpperCAmelCase)
          __A						: List[str]      =       jax.random.split(_UpperCAmelCase						,	_UpperCAmelCase)
          __A						: Dict      =       shard(_UpperCAmelCase)

          __A						: str      =       pipeline(_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	jit=_UpperCAmelCase).images

          assert images.shape == (num_samples, 1, 512, 512, 3)
          if jax.device_count() == 8:
               assert np.abs((np.abs(images[0, 0, :2, :2, -2:]						,	dtype=np.floataa).sum() - 0.04003906)) < 1e-3
               assert np.abs((np.abs(_UpperCAmelCase						,	dtype=np.floataa).sum() - 2373516.75)) < 5e-1


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A ,__A						: Optional[Any]      =       FlaxStableDiffusionPipeline.from_pretrained(
              'CompVis/stable-diffusion-v1-4'						,	revision='bf16'						,	dtype=jnp.bfloataa)

          __A						: Union[str, Any]      =       (
              'A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'
              ' field, close up, split lighting, cinematic'
          )

          __A						: Any      =       jax.random.PRNGKey(0)
          __A						: List[str]      =       50

          __A						: Optional[int]      =       jax.device_count()
          __A						: List[Any]      =       num_samples * [prompt]
          __A						: List[Any]      =       pipeline.prepare_inputs(_UpperCAmelCase)

          # shard inputs and rng
          __A						: Union[str, Any]      =       replicate(_UpperCAmelCase)
          __A						: Optional[Any]      =       jax.random.split(_UpperCAmelCase						,	_UpperCAmelCase)
          __A						: List[str]      =       shard(_UpperCAmelCase)

          __A						: int      =       pipeline(_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	jit=_UpperCAmelCase).images

          assert images.shape == (num_samples, 1, 512, 512, 3)
          if jax.device_count() == 8:
               assert np.abs((np.abs(images[0, 0, :2, :2, -2:]						,	dtype=np.floataa).sum() - 0.04003906)) < 1e-3
               assert np.abs((np.abs(_UpperCAmelCase						,	dtype=np.floataa).sum() - 2373516.75)) < 5e-1


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						: List[Any]      =       FlaxDDIMScheduler(
              beta_start=0.00085						,	beta_end=0.012						,	beta_schedule='scaled_linear'						,	set_alpha_to_one=_UpperCAmelCase						,	steps_offset=1						,	)

          __A ,__A						: Any      =       FlaxStableDiffusionPipeline.from_pretrained(
              'CompVis/stable-diffusion-v1-4'						,	revision='bf16'						,	dtype=jnp.bfloataa						,	scheduler=_UpperCAmelCase						,	safety_checker=_UpperCAmelCase						,	)
          __A						: Optional[Any]      =       scheduler.create_state()

          __A						: Any      =       scheduler_state

          __A						: List[str]      =       (
              'A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'
              ' field, close up, split lighting, cinematic'
          )

          __A						: Union[str, Any]      =       jax.random.PRNGKey(0)
          __A						: Optional[int]      =       50

          __A						: Optional[Any]      =       jax.device_count()
          __A						: Any      =       num_samples * [prompt]
          __A						: Optional[Any]      =       pipeline.prepare_inputs(_UpperCAmelCase)

          # shard inputs and rng
          __A						: int      =       replicate(_UpperCAmelCase)
          __A						: Any      =       jax.random.split(_UpperCAmelCase						,	_UpperCAmelCase)
          __A						: Tuple      =       shard(_UpperCAmelCase)

          __A						: Union[str, Any]      =       pipeline(_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	jit=_UpperCAmelCase).images

          assert images.shape == (num_samples, 1, 512, 512, 3)
          if jax.device_count() == 8:
               assert np.abs((np.abs(images[0, 0, :2, :2, -2:]						,	dtype=np.floataa).sum() - 0.045043945)) < 1e-3
               assert np.abs((np.abs(_UpperCAmelCase						,	dtype=np.floataa).sum() - 2347693.5)) < 5e-1


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						: Dict      =       (
              'A cinematic film still of Morgan Freeman starring as Jimi Hendrix, portrait, 40mm lens, shallow depth of'
              ' field, close up, split lighting, cinematic'
          )

          __A						: int      =       jax.device_count()
          __A						: List[Any]      =       num_samples * [prompt]
          __A						: List[Any]      =       jax.random.split(jax.random.PRNGKey(0)						,	_UpperCAmelCase)

          __A ,__A						: Tuple      =       FlaxStableDiffusionPipeline.from_pretrained(
              'CompVis/stable-diffusion-v1-4'						,	revision='bf16'						,	dtype=jnp.bfloataa						,	safety_checker=_UpperCAmelCase						,	)

          __A						: str      =       replicate(_UpperCAmelCase)
          __A						: str      =       pipeline.prepare_inputs(_UpperCAmelCase)
          __A						: str      =       shard(_UpperCAmelCase)
          __A						: int      =       pipeline(_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	jit=_UpperCAmelCase).images
          assert images.shape == (num_samples, 1, 512, 512, 3)
          __A						: Any      =       images[2, 0, 256, 10:17, 1]

          # With memory efficient attention
          __A ,__A						: str      =       FlaxStableDiffusionPipeline.from_pretrained(
              'CompVis/stable-diffusion-v1-4'						,	revision='bf16'						,	dtype=jnp.bfloataa						,	safety_checker=_UpperCAmelCase						,	use_memory_efficient_attention=_UpperCAmelCase						,	)

          __A						: Any      =       replicate(_UpperCAmelCase)
          __A						: List[Any]      =       pipeline.prepare_inputs(_UpperCAmelCase)
          __A						: Optional[Any]      =       shard(_UpperCAmelCase)
          __A						: List[Any]      =       pipeline(_UpperCAmelCase						,	_UpperCAmelCase						,	_UpperCAmelCase						,	jit=_UpperCAmelCase).images
          assert images_eff.shape == (num_samples, 1, 512, 512, 3)
          __A						: List[Any]      =       images[2, 0, 256, 10:17, 1]

          # I checked the results visually and they are very similar. However, I saw that the max diff is `1` and the `sum`
          # over the 8 images is exactly `256`, which is very suspicious. Testing a random slice for now.
          assert abs(slice_eff - slice).max() < 1e-2