

"""simple docstring"""






import inspect
import unittest

import numpy as np

from tests.test_modeling_common import floats_tensor
from transformers import MaskaFormerConfig, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch

 from transformers import MaskaFormerForUniversalSegmentation, MaskaFormerModel

 if is_vision_available():
  from transformers import MaskaFormerImageProcessor

if is_vision_available():
 from PIL import Image







class       snake_case__  :







   def __init__(			self			: str			,  lowercase			: Any			,  lowercase			: Any=2			,  lowercase			: Optional[Any]=True			,  lowercase			: List[str]=False			,  lowercase			: List[str]=10			,  lowercase			: Optional[Any]=3			,  lowercase			: int=32 * 8			,  lowercase			: Tuple=32 * 8			,  lowercase			: Any=4			,  lowercase			: List[Any]=64			,  ):





        '''simple docstring'''



        UpperCAmelCase			:   int      =				parent
        UpperCAmelCase			:   Optional[int]      =				batch_size
        UpperCAmelCase			:   List[str]      =				is_training
        UpperCAmelCase			:   int      =				use_auxiliary_loss
        UpperCAmelCase			:   List[str]      =				num_queries
        UpperCAmelCase			:   Tuple      =				num_channels
        UpperCAmelCase			:   Any      =				min_size
        UpperCAmelCase			:   List[Any]      =				max_size
        UpperCAmelCase			:   List[str]      =				num_labels
        UpperCAmelCase			:   Optional[Any]      =				hidden_dim
        UpperCAmelCase			:   Any      =				hidden_dim







   def 			__lowerCAmelCase				(			self			: Any  ):





        '''simple docstring'''



        UpperCAmelCase			:   Any      =				floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]  ).to(
            _lowercase  )

        UpperCAmelCase			:   Union[str, Any]      =				torch.ones([self.batch_size, self.min_size, self.max_size]			,  device=_lowercase  )

        UpperCAmelCase			:   int      =				(
            torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size]			,  device=_lowercase  ) > 0.5
        ).float()
        UpperCAmelCase			:   Any      =				(torch.rand((self.batch_size, self.num_labels)			,  device=_lowercase  ) > 0.5).long()

        UpperCAmelCase			:   Optional[int]      =				self.get_config()
        return config, pixel_values, pixel_mask, mask_labels, class_labels







   def 			__lowerCAmelCase				(			self			: Dict  ):





        '''simple docstring'''



        UpperCAmelCase			:   Optional[Any]      =				MaskaFormerConfig(
            hidden_size=self.hidden_dim			,  )
        UpperCAmelCase			:   List[Any]      =				self.num_queries
        UpperCAmelCase			:   Union[str, Any]      =				self.num_labels

        UpperCAmelCase			:   Union[str, Any]      =				[1, 1, 1, 1]
        UpperCAmelCase			:   str      =				self.num_channels

        UpperCAmelCase			:   Any      =				64
        UpperCAmelCase			:   int      =				1_28
        UpperCAmelCase			:   Optional[Any]      =				self.hidden_dim
        UpperCAmelCase			:   Any      =				self.hidden_dim
        UpperCAmelCase			:   str      =				self.hidden_dim
        return config







   def 			__lowerCAmelCase				(			self			: Dict  ):





        '''simple docstring'''



        UpperCAmelCase			:   Tuple      =				self.prepare_config_and_inputs()
        UpperCAmelCase			:   Any      =				{"""pixel_values""": pixel_values, """pixel_mask""": pixel_mask}
        return config, inputs_dict







   def 			__lowerCAmelCase				(			self			: Optional[int]			,  lowercase			: List[str]			,  lowercase			: List[str]  ):





        '''simple docstring'''



        UpperCAmelCase			:   Tuple      =				output.encoder_hidden_states
        UpperCAmelCase			:   Dict      =				output.pixel_decoder_hidden_states
        UpperCAmelCase			:   List[str]      =				output.transformer_decoder_hidden_states

        self.parent.assertTrue(len(_lowercase  )			,  len(config.backbone_config.depths  )  )
        self.parent.assertTrue(len(_lowercase  )			,  len(config.backbone_config.depths  )  )
        self.parent.assertTrue(len(_lowercase  )			,  config.decoder_layers  )







   def 			__lowerCAmelCase				(			self			: Optional[int]			,  lowercase			: Optional[Any]			,  lowercase			: int			,  lowercase			: Dict			,  lowercase			: Tuple=False  ):





        '''simple docstring'''



        with torch.no_grad():
             UpperCAmelCase			:   Dict      =				MaskaFormerModel(config=_lowercase  )
             model.to(_lowercase  )
             model.eval()

             UpperCAmelCase			:   Optional[int]      =				model(pixel_values=_lowercase			,  pixel_mask=_lowercase  )
             UpperCAmelCase			:   Optional[Any]      =				model(_lowercase			,  output_hidden_states=_lowercase  )

        self.parent.assertEqual(
            output.transformer_decoder_last_hidden_state.shape			,  (self.batch_size, self.num_queries, self.hidden_dim)			,  )
        # let's ensure the other two hidden state exists
        self.parent.assertTrue(output.pixel_decoder_last_hidden_state is not None  )
        self.parent.assertTrue(output.encoder_last_hidden_state is not None  )

        if output_hidden_states:
             self.check_output_hidden_state(_lowercase			,  _lowercase  )







   def 			__lowerCAmelCase				(			self			: Optional[int]			,  lowercase			: Any			,  lowercase			: Optional[int]			,  lowercase			: Dict			,  lowercase			: List[str]			,  lowercase			: Optional[int]  ):





        '''simple docstring'''



        UpperCAmelCase			:   List[str]      =				MaskaFormerForUniversalSegmentation(config=_lowercase  )
        model.to(_lowercase  )
        model.eval()

        def comm_check_on_output(lowercase			: int  ):
             # let's still check that all the required stuff is there
             self.parent.assertTrue(result.transformer_decoder_last_hidden_state is not None  )
             self.parent.assertTrue(result.pixel_decoder_last_hidden_state is not None  )
             self.parent.assertTrue(result.encoder_last_hidden_state is not None  )
             # okay, now we need to check the logits shape
             # due to the encoder compression, masks have a //4 spatial size
             self.parent.assertEqual(
                 result.masks_queries_logits.shape			,  (self.batch_size, self.num_queries, self.min_size // 4, self.max_size // 4)			,  )
             # + 1 for null class
             self.parent.assertEqual(
                 result.class_queries_logits.shape			,  (self.batch_size, self.num_queries, self.num_labels + 1)  )

        with torch.no_grad():
             UpperCAmelCase			:   List[str]      =				model(pixel_values=_lowercase			,  pixel_mask=_lowercase  )
             UpperCAmelCase			:   List[Any]      =				model(_lowercase  )

             comm_check_on_output(_lowercase  )

             UpperCAmelCase			:   Optional[Any]      =				model(
                 pixel_values=_lowercase			,  pixel_mask=_lowercase			,  mask_labels=_lowercase			,  class_labels=_lowercase  )

        comm_check_on_output(_lowercase  )

        self.parent.assertTrue(result.loss is not None  )
        self.parent.assertEqual(result.loss.shape			,  torch.Size([1]  )  )







@require_torch
class       snake_case__  ( SCREAMING_SNAKE_CASE__					,  SCREAMING_SNAKE_CASE__					,  unittest.TestCase     ):
   SCREAMING_SNAKE_CASE__     				=						(MaskaFormerModel, MaskaFormerForUniversalSegmentation) if is_torch_available() else ()
   SCREAMING_SNAKE_CASE__     				=						{'''feature-extraction''': MaskaFormerModel} if is_torch_available() else {}

   SCREAMING_SNAKE_CASE__     				=						False
   SCREAMING_SNAKE_CASE__     				=						False
   SCREAMING_SNAKE_CASE__     				=						False
   SCREAMING_SNAKE_CASE__     				=						False







   def 			__lowerCAmelCase				(			self			: str  ):





        '''simple docstring'''



        UpperCAmelCase			:   Optional[Any]      =				MaskaFormerModelTester(self  )
        UpperCAmelCase			:   List[Any]      =				ConfigTester(self			,  config_class=_lowercase			,  has_text_modality=_lowercase  )







   def 			__lowerCAmelCase				(			self			: Optional[Any]  ):





        '''simple docstring'''



        self.config_tester.run_common_tests()







   def 			__lowerCAmelCase				(			self			: Optional[int]  ):





        '''simple docstring'''



        UpperCAmelCase			:   Dict      =				self.model_tester.prepare_config_and_inputs_for_common()
        self.model_tester.create_and_check_maskaformer_model(_lowercase			,  **_lowercase			,  output_hidden_states=_lowercase  )







   def 			__lowerCAmelCase				(			self			: List[str]  ):





        '''simple docstring'''



        UpperCAmelCase			:   Any      =				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_maskaformer_instance_segmentation_head_model(*_lowercase  )







   @unittest.skip(reason="Mask2Former does not use inputs_embeds"  )
   def 			__lowerCAmelCase				(			self			: str  ):





        '''simple docstring'''



        pass







   @unittest.skip(reason="Mask2Former does not have a get_input_embeddings method"  )
   def 			__lowerCAmelCase				(			self			: List[str]  ):





        '''simple docstring'''



        pass







   @unittest.skip(reason="Mask2Former is not a generative model"  )
   def 			__lowerCAmelCase				(			self			: Dict  ):





        '''simple docstring'''



        pass







   @unittest.skip(reason="Mask2Former does not use token embeddings"  )
   def 			__lowerCAmelCase				(			self			: Tuple  ):





        '''simple docstring'''



        pass







   @require_torch_multi_gpu
   @unittest.skip(
       reason="Mask2Former has some layers using `add_module` which doesn't work well with `nn.DataParallel`"  )
   def 			__lowerCAmelCase				(			self			: List[str]  ):





        '''simple docstring'''



        pass







   @unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."  )
   def 			__lowerCAmelCase				(			self			: List[Any]  ):





        '''simple docstring'''



        pass







   def 			__lowerCAmelCase				(			self			: int  ):





        '''simple docstring'''



        UpperCAmelCase			:   Dict      =				self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
             UpperCAmelCase			:   Any      =				model_class(_lowercase  )
             UpperCAmelCase			:   Any      =				inspect.signature(model.forward  )
             # signature.parameters is an OrderedDict => so arg_names order is deterministic
             UpperCAmelCase			:   str      =				[*signature.parameters.keys()]

             UpperCAmelCase			:   Tuple      =				["""pixel_values"""]
             self.assertListEqual(arg_names[:1]			,  _lowercase  )







   @slow
   def 			__lowerCAmelCase				(			self			: Union[str, Any]  ):





        '''simple docstring'''



        for model_name in ["facebook/mask2former-swin-small-coco-instance"]:
             UpperCAmelCase			:   Tuple      =				MaskaFormerModel.from_pretrained(_lowercase  )
             self.assertIsNotNone(_lowercase  )







   def 			__lowerCAmelCase				(			self			: Tuple  ):





        '''simple docstring'''



        UpperCAmelCase			:   Optional[int]      =				(self.model_tester.min_size,) * 2
        UpperCAmelCase			:   Union[str, Any]      =				{
            """pixel_values""": torch.randn((2, 3, *size)			,  device=_lowercase  ),
            """mask_labels""": torch.randn((2, 10, *size)			,  device=_lowercase  ),
            """class_labels""": torch.zeros(2			,  10			,  device=_lowercase  ).long(),
        }
        UpperCAmelCase			:   int      =				self.model_tester.get_config()

        UpperCAmelCase			:   int      =				MaskaFormerForUniversalSegmentation(_lowercase  ).to(_lowercase  )
        UpperCAmelCase			:   List[str]      =				model(**_lowercase  )
        self.assertTrue(outputs.loss is not None  )







   def 			__lowerCAmelCase				(			self			: List[Any]  ):





        '''simple docstring'''



        UpperCAmelCase			:   Tuple      =				self.model_tester.prepare_config_and_inputs_for_common()
        self.model_tester.create_and_check_maskaformer_model(_lowercase			,  **_lowercase			,  output_hidden_states=_lowercase  )







   def 			__lowerCAmelCase				(			self			: Optional[int]  ):





        '''simple docstring'''



        UpperCAmelCase			:   int      =				self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
             UpperCAmelCase			:   str      =				model_class(_lowercase  ).to(_lowercase  )
             UpperCAmelCase			:   Optional[int]      =				model(**_lowercase			,  output_attentions=_lowercase  )
             self.assertTrue(outputs.attentions is not None  )







   def 			__lowerCAmelCase				(			self			: int  ):





        '''simple docstring'''



        if not self.model_tester.is_training:
             return

        UpperCAmelCase			:   int      =				self.all_model_classes[1]
        UpperCAmelCase			:   Dict      =				self.model_tester.prepare_config_and_inputs()

        UpperCAmelCase			:   Optional[Any]      =				model_class(_lowercase  )
        model.to(_lowercase  )
        model.train()

        UpperCAmelCase			:   Optional[Any]      =				model(_lowercase			,  mask_labels=_lowercase			,  class_labels=_lowercase  ).loss
        loss.backward()







   def 			__lowerCAmelCase				(			self			: Tuple  ):





        '''simple docstring'''



        UpperCAmelCase			:   str      =				self.all_model_classes[1]
        UpperCAmelCase			:   Dict      =				self.model_tester.prepare_config_and_inputs()
        UpperCAmelCase			:   str      =				True
        UpperCAmelCase			:   List[str]      =				True

        UpperCAmelCase			:   str      =				model_class(_lowercase  ).to(_lowercase  )
        model.train()

        UpperCAmelCase			:   Dict      =				model(_lowercase			,  mask_labels=_lowercase			,  class_labels=_lowercase  )

        UpperCAmelCase			:   Optional[Any]      =				outputs.encoder_hidden_states[0]
        encoder_hidden_states.retain_grad()

        UpperCAmelCase			:   int      =				outputs.pixel_decoder_hidden_states[0]
        pixel_decoder_hidden_states.retain_grad()

        UpperCAmelCase			:   Optional[int]      =				outputs.transformer_decoder_hidden_states[0]
        transformer_decoder_hidden_states.retain_grad()

        UpperCAmelCase			:   Optional[int]      =				outputs.attentions[0]
        attentions.retain_grad()

        outputs.loss.backward(retain_graph=_lowercase  )

        self.assertIsNotNone(encoder_hidden_states.grad  )
        self.assertIsNotNone(pixel_decoder_hidden_states.grad  )
        self.assertIsNotNone(transformer_decoder_hidden_states.grad  )
        self.assertIsNotNone(attentions.grad  )

snake_case_   :   List[str]        =       1E-4



def   lowercase_	(    ):




     '''simple docstring'''






     UpperCAmelCase			:   str      =				Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"	)
     return image







@require_vision
@slow
class       snake_case__  ( unittest.TestCase     ):







   @cached_property
   def 			__lowerCAmelCase				(			self			: Optional[Any]  ):





        '''simple docstring'''



        return "facebook/mask2former-swin-small-coco-instance"







   @cached_property
   def 			__lowerCAmelCase				(			self			: int  ):





        '''simple docstring'''



        return MaskaFormerImageProcessor.from_pretrained(self.model_checkpoints  ) if is_vision_available() else None







   def 			__lowerCAmelCase				(			self			: Tuple  ):





        '''simple docstring'''



        UpperCAmelCase			:   Union[str, Any]      =				MaskaFormerModel.from_pretrained(self.model_checkpoints  ).to(_lowercase  )
        UpperCAmelCase			:   List[str]      =				self.default_image_processor
        UpperCAmelCase			:   List[str]      =				prepare_img()
        UpperCAmelCase			:   Any      =				image_processor(_lowercase			,  return_tensors="pt"  ).to(_lowercase  )
        UpperCAmelCase			:   List[Any]      =				inputs["""pixel_values"""].shape
        # check size is divisible by 32
        self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0  )
        # check size
        self.assertEqual(_lowercase			,  (1, 3, 3_84, 3_84)  )

        with torch.no_grad():
             UpperCAmelCase			:   Union[str, Any]      =				model(**_lowercase  )

        UpperCAmelCase			:   Optional[int]      =				torch.tensor(
            [[-0.2_7_9_0, -1.0_7_1_7, -1.1_6_6_8], [-0.5_1_2_8, -0.3_1_2_8, -0.4_9_8_7], [-0.5_8_3_2, 0.1_9_7_1, -0.0_1_9_7]]  ).to(_lowercase  )
        self.assertTrue(
            torch.allclose(
                outputs.encoder_last_hidden_state[0, 0, :3, :3]			,  _lowercase			,  atol=_lowercase  )  )

        UpperCAmelCase			:   List[str]      =				torch.tensor(
            [[0.8_9_7_3, 1.1_8_4_7, 1.1_7_7_6], [1.1_9_3_4, 1.5_0_4_0, 1.5_1_2_8], [1.1_1_5_3, 1.4_4_8_6, 1.4_9_5_1]]  ).to(_lowercase  )
        self.assertTrue(
            torch.allclose(
                outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]			,  _lowercase			,  atol=_lowercase  )  )

        UpperCAmelCase			:   List[str]      =				torch.tensor(
            [[2.1_1_5_2, 1.7_0_0_0, -0.8_6_0_3], [1.5_8_0_8, 1.8_0_0_4, -0.9_3_5_3], [1.6_0_4_3, 1.7_4_9_5, -0.5_9_9_9]]  ).to(_lowercase  )
        self.assertTrue(
            torch.allclose(
                outputs.transformer_decoder_last_hidden_state[0, :3, :3]			,  _lowercase			,  atol=_lowercase  )  )







   def 			__lowerCAmelCase				(			self			: List[str]  ):





        '''simple docstring'''



        UpperCAmelCase			:   Optional[Any]      =				MaskaFormerForUniversalSegmentation.from_pretrained(self.model_checkpoints  ).to(_lowercase  ).eval()
        UpperCAmelCase			:   str      =				self.default_image_processor
        UpperCAmelCase			:   Any      =				prepare_img()
        UpperCAmelCase			:   str      =				image_processor(_lowercase			,  return_tensors="pt"  ).to(_lowercase  )
        UpperCAmelCase			:   int      =				inputs["""pixel_values"""].shape
        # check size is divisible by 32
        self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0  )
        # check size
        self.assertEqual(_lowercase			,  (1, 3, 3_84, 3_84)  )

        with torch.no_grad():
             UpperCAmelCase			:   List[str]      =				model(**_lowercase  )
        # masks_queries_logits
        UpperCAmelCase			:   Tuple      =				outputs.masks_queries_logits
        self.assertEqual(
            masks_queries_logits.shape			,  (1, model.config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)  )
        UpperCAmelCase			:   Union[str, Any]      =				[
            [-8.7_8_3_9, -9.0_0_5_6, -8.8_1_2_1],
            [-7.4_1_0_4, -7.0_3_1_3, -6.5_4_0_1],
            [-6.6_1_0_5, -6.3_4_2_7, -6.4_6_7_5],
        ]
        UpperCAmelCase			:   int      =				torch.tensor(_lowercase  ).to(_lowercase  )
        self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]			,  _lowercase			,  atol=_lowercase  )  )
        # class_queries_logits
        UpperCAmelCase			:   Dict      =				outputs.class_queries_logits
        self.assertEqual(class_queries_logits.shape			,  (1, model.config.num_queries, model.config.num_labels + 1)  )
        UpperCAmelCase			:   int      =				torch.tensor(
            [
                [1.8_3_2_4, -8.0_8_3_5, -4.1_9_2_2],
                [0.8_4_5_0, -9.0_0_5_0, -3.6_0_5_3],
                [0.3_0_4_5, -7.7_2_9_3, -3.0_2_7_5],
            ]  ).to(_lowercase  )
        self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]			,  _lowercase			,  atol=_lowercase  )  )







   def 			__lowerCAmelCase				(			self			: Optional[Any]  ):





        '''simple docstring'''



        UpperCAmelCase			:   int      =				MaskaFormerForUniversalSegmentation.from_pretrained(self.model_checkpoints  ).to(_lowercase  ).eval()
        UpperCAmelCase			:   Union[str, Any]      =				self.default_image_processor

        UpperCAmelCase			:   List[Any]      =				image_processor(
            [np.zeros((3, 8_00, 13_33)  ), np.zeros((3, 8_00, 13_33)  )]			,  segmentation_maps=[np.zeros((3_84, 3_84)  ).astype(np.floataa  ), np.zeros((3_84, 3_84)  ).astype(np.floataa  )]			,  return_tensors="pt"			,  )

        UpperCAmelCase			:   List[Any]      =				inputs["""pixel_values"""].to(_lowercase  )
        UpperCAmelCase			:   Optional[int]      =				[el.to(_lowercase  ) for el in inputs["""mask_labels"""]]
        UpperCAmelCase			:   Any      =				[el.to(_lowercase  ) for el in inputs["""class_labels"""]]

        with torch.no_grad():
             UpperCAmelCase			:   Optional[Any]      =				model(**_lowercase  )

        self.assertTrue(outputs.loss is not None  )





"""simple docstring"""






from __future__ import annotations

snake_case_   :   str        =       list[list[int]]

# assigning initial values to the grid
snake_case_   :   Matrix        =       [
    [3, 0, 6, 5, 0, 8, 4, 0, 0],
    [5, 2, 0, 0, 0, 0, 0, 0, 0],
    [0, 8, 7, 0, 0, 0, 0, 3, 1],
    [0, 0, 3, 0, 1, 0, 0, 8, 0],
    [9, 0, 0, 8, 6, 3, 0, 0, 5],
    [0, 5, 0, 0, 9, 0, 6, 0, 0],
    [1, 3, 0, 0, 0, 0, 2, 5, 0],
    [0, 0, 0, 0, 0, 0, 0, 7, 4],
    [0, 0, 5, 2, 0, 6, 3, 0, 0],
]

# a grid with no solution
snake_case_   :   Matrix        =       [
    [5, 0, 6, 5, 0, 8, 4, 0, 3],
    [5, 2, 0, 0, 0, 0, 0, 0, 2],
    [1, 8, 7, 0, 0, 0, 0, 3, 1],
    [0, 0, 3, 0, 1, 0, 0, 8, 0],
    [9, 0, 0, 8, 6, 3, 0, 0, 5],
    [0, 5, 0, 0, 9, 0, 6, 0, 0],
    [1, 3, 0, 0, 0, 0, 2, 5, 0],
    [0, 0, 0, 0, 0, 0, 0, 7, 4],
    [0, 0, 5, 2, 0, 6, 3, 0, 0],
]



def   lowercase_	(    _lowercase       :		Matrix							,      _lowercase       :		int							,      _lowercase       :		int							,      _lowercase       :		int	):




					'''simple docstring'''






					for i in range(9	):
										if grid[row][i] == n or grid[i][column] == n:
															return False

					for i in range(3	):
										for j in range(3	):
															if grid[(row - row % 3) + i][(column - column % 3) + j] == n:
																				return False

					return True



def   lowercase_	(    _lowercase       :		Matrix	):




					'''simple docstring'''






					for i in range(9	):
										for j in range(9	):
															if grid[i][j] == 0:
																				return i, j
					return None



def   lowercase_	(    _lowercase       :		Matrix	):




					'''simple docstring'''






					if location := find_empty_location(_lowercase	):
										UpperCAmelCase      ,							UpperCAmelCase			:   List[str]      =				location
					else:
										# If the location is ``None``, then the grid is solved.
										return grid

					for digit in range(1							,      10	):
										if is_safe(_lowercase							,      _lowercase							,      _lowercase							,      _lowercase	):
															UpperCAmelCase			:   int      =				digit

															if sudoku(_lowercase	) is not None:
																				return grid

															UpperCAmelCase			:   Optional[Any]      =				0

					return None



def   lowercase_	(    _lowercase       :		Matrix	):




					'''simple docstring'''






					for row in grid:
										for cell in row:
															print(_lowercase							,      end=" "	)
										print()


if __name__ == "__main__":
	# make a copy of grid so that you can compare with the unmodified grid
	for example_grid in (initial_grid, no_solution):
		print("""\nExample grid:\n""" + """=""" * 2_0)
		print_solution(example_grid)
		print("""\nExample grid solution:""")
		snake_case_   :   Dict        =       sudoku(example_grid)
		if solution is not None:
			print_solution(solution)
		else:
			print("""Cannot find a solution.""")


