
"""simple docstring"""



import unittest

from transformers import AutoTokenizer, FalconConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
 import torch

 from transformers import (
     FalconForCausalLM,
     FalconForQuestionAnswering,
     FalconForSequenceClassification,
     FalconForTokenClassification,
     FalconModel,
 )




class 		a_    :







    def __init__(      self      :							Tuple  ,       __UpperCamelCase      :							str  ,       __UpperCamelCase      :							Union[str, Any]=3  ,       __UpperCamelCase      :							Optional[Any]=7  ,       __UpperCamelCase      :							Dict=True  ,       __UpperCamelCase      :							int=True  ,       __UpperCamelCase      :							Optional[Any]=False  ,       __UpperCamelCase      :							List[str]=True  ,       __UpperCamelCase      :							Dict=99  ,       __UpperCamelCase      :							int=32  ,       __UpperCamelCase      :							List[Any]=5  ,       __UpperCamelCase      :							str=4  ,       __UpperCamelCase      :							Union[str, Any]=37  ,       __UpperCamelCase      :							Optional[Any]="gelu"  ,       __UpperCamelCase      :							List[str]=0.1  ,       __UpperCamelCase      :							str=0.1  ,       __UpperCamelCase      :							Optional[Any]=5_12  ,       __UpperCamelCase      :							Tuple=16  ,       __UpperCamelCase      :							List[Any]=2  ,       __UpperCamelCase      :							Union[str, Any]=0.0_2  ,       __UpperCamelCase      :							Dict=3  ,       __UpperCamelCase      :							int=4  ,       __UpperCamelCase      :							int=None  ,       )		->int:






        '''simple docstring'''






        _UpperCAmelCase        = parent
        _UpperCAmelCase        = batch_size
        _UpperCAmelCase        = seq_length
        _UpperCAmelCase        = is_training
        _UpperCAmelCase        = use_input_mask
        _UpperCAmelCase        = use_token_type_ids
        _UpperCAmelCase        = use_labels
        _UpperCAmelCase        = vocab_size
        _UpperCAmelCase        = hidden_size
        _UpperCAmelCase        = num_hidden_layers
        _UpperCAmelCase        = num_attention_heads
        _UpperCAmelCase        = intermediate_size
        _UpperCAmelCase        = hidden_act
        _UpperCAmelCase        = hidden_dropout_prob
        _UpperCAmelCase        = attention_probs_dropout_prob
        _UpperCAmelCase        = max_position_embeddings
        _UpperCAmelCase        = type_vocab_size
        _UpperCAmelCase        = type_sequence_label_size
        _UpperCAmelCase        = initializer_range
        _UpperCAmelCase        = num_labels
        _UpperCAmelCase        = num_choices
        _UpperCAmelCase        = scope







    def   _snake_case       (      self      :							Union[str, Any]  )		->Optional[int]:






        '''simple docstring'''






        _UpperCAmelCase        = ids_tensor([self.batch_size, self.seq_length]  ,       self.vocab_size  )

        _UpperCAmelCase        = None
        if self.use_input_mask:
            _UpperCAmelCase        = random_attention_mask([self.batch_size, self.seq_length]  )

        _UpperCAmelCase        = None

        _UpperCAmelCase        = None
        _UpperCAmelCase        = None
        _UpperCAmelCase        = None
        if self.use_labels:
            _UpperCAmelCase        = ids_tensor([self.batch_size]  ,       self.type_sequence_label_size  )
            _UpperCAmelCase        = ids_tensor([self.batch_size, self.seq_length]  ,       self.num_labels  )
            _UpperCAmelCase        = ids_tensor([self.batch_size]  ,       self.num_choices  )

        _UpperCAmelCase        = self.get_config()

        return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels







    def   _snake_case       (      self      :							str  )		->str:






        '''simple docstring'''






        return FalconConfig(
            vocab_size=self.vocab_size  ,       hidden_size=self.hidden_size  ,       num_hidden_layers=self.num_hidden_layers  ,       num_attention_heads=self.num_attention_heads  ,       intermediate_size=self.intermediate_size  ,       hidden_act=self.hidden_act  ,       hidden_dropout_prob=self.hidden_dropout_prob  ,       attention_probs_dropout_prob=self.attention_probs_dropout_prob  ,       max_position_embeddings=self.max_position_embeddings  ,       type_vocab_size=self.type_vocab_size  ,       is_decoder=__UpperCamelCase  ,       initializer_range=self.initializer_range  ,       pad_token_id=1  ,       new_decoder_architecture=__UpperCamelCase  ,       )







    def   _snake_case       (      self      :							Tuple  ,       __UpperCamelCase      :							List[Any]  ,       __UpperCamelCase      :							Dict  ,       __UpperCamelCase      :							List[str]  ,       __UpperCamelCase      :							int  ,       __UpperCamelCase      :							Union[str, Any]  ,       __UpperCamelCase      :							str  ,       __UpperCamelCase      :							Optional[Any]  )		->Union[str, Any]:






        '''simple docstring'''






        _UpperCAmelCase        = FalconModel(config=__UpperCamelCase  )
        model.to(__UpperCamelCase  )
        model.eval()
        _UpperCAmelCase        = model(__UpperCamelCase  ,       attention_mask=__UpperCamelCase  )
        _UpperCAmelCase        = model(__UpperCamelCase  )
        self.parent.assertEqual(result.last_hidden_state.shape  ,       (self.batch_size, self.seq_length, self.hidden_size)  )







    def   _snake_case       (      self      :							Optional[Any]  ,       __UpperCamelCase      :							Tuple  ,       __UpperCamelCase      :							List[Any]  ,       __UpperCamelCase      :							Optional[int]  ,       __UpperCamelCase      :							int  ,       __UpperCamelCase      :							Optional[Any]  ,       __UpperCamelCase      :							str  ,       __UpperCamelCase      :							Dict  ,       __UpperCamelCase      :							Optional[Any]  ,       __UpperCamelCase      :							List[str]  ,       )		->Tuple:






        '''simple docstring'''






        _UpperCAmelCase        = True
        _UpperCAmelCase        = FalconModel(__UpperCamelCase  )
        model.to(__UpperCamelCase  )
        model.eval()
        _UpperCAmelCase        = model(
            __UpperCamelCase  ,       attention_mask=__UpperCamelCase  ,       encoder_hidden_states=__UpperCamelCase  ,       encoder_attention_mask=__UpperCamelCase  ,       )
        _UpperCAmelCase        = model(
            __UpperCamelCase  ,       attention_mask=__UpperCamelCase  ,       encoder_hidden_states=__UpperCamelCase  ,       )
        _UpperCAmelCase        = model(__UpperCamelCase  ,       attention_mask=__UpperCamelCase  )
        self.parent.assertEqual(result.last_hidden_state.shape  ,       (self.batch_size, self.seq_length, self.hidden_size)  )







    def   _snake_case       (      self      :							int  ,       __UpperCamelCase      :							Optional[int]  ,       __UpperCamelCase      :							Dict  ,       __UpperCamelCase      :							List[Any]  ,       __UpperCamelCase      :							Union[str, Any]  ,       __UpperCamelCase      :							Tuple  ,       __UpperCamelCase      :							Union[str, Any]  ,       __UpperCamelCase      :							Any  ,       __UpperCamelCase      :							List[Any]  ,       __UpperCamelCase      :							int  ,       )		->Union[str, Any]:






        '''simple docstring'''






        _UpperCAmelCase        = FalconForCausalLM(config=__UpperCamelCase  )
        model.to(__UpperCamelCase  )
        model.eval()
        _UpperCAmelCase        = model(__UpperCamelCase  ,       attention_mask=__UpperCamelCase  ,       labels=__UpperCamelCase  )
        self.parent.assertEqual(result.logits.shape  ,       (self.batch_size, self.seq_length, self.vocab_size)  )







    def   _snake_case       (      self      :							Dict  ,       __UpperCamelCase      :							List[str]  ,       __UpperCamelCase      :							Optional[Any]  ,       __UpperCamelCase      :							List[str]  ,       __UpperCamelCase      :							Union[str, Any]  ,       __UpperCamelCase      :							Tuple  ,       __UpperCamelCase      :							List[str]  ,       __UpperCamelCase      :							Optional[Any]  ,       __UpperCamelCase      :							Optional[Any]  ,       __UpperCamelCase      :							Any  ,       )		->Union[str, Any]:






        '''simple docstring'''






        _UpperCAmelCase        = True
        _UpperCAmelCase        = True
        _UpperCAmelCase        = FalconForCausalLM(config=__UpperCamelCase  )
        model.to(__UpperCamelCase  )
        model.eval()

        # first forward pass
        _UpperCAmelCase        = model(
            __UpperCamelCase  ,       attention_mask=__UpperCamelCase  ,       encoder_hidden_states=__UpperCamelCase  ,       encoder_attention_mask=__UpperCamelCase  ,       use_cache=__UpperCamelCase  ,       )
        _UpperCAmelCase        = outputs.past_key_values

        # create hypothetical multiple next token and extent to next_input_ids
        _UpperCAmelCase        = ids_tensor((self.batch_size, 3)  ,       config.vocab_size  )
        _UpperCAmelCase        = ids_tensor((self.batch_size, 3)  ,       vocab_size=2  )

        # append to next input_ids and
        _UpperCAmelCase        = torch.cat([input_ids, next_tokens]  ,       dim=-1  )
        _UpperCAmelCase        = torch.cat([input_mask, next_mask]  ,       dim=-1  )

        _UpperCAmelCase        = model(
            __UpperCamelCase  ,       attention_mask=__UpperCamelCase  ,       encoder_hidden_states=__UpperCamelCase  ,       encoder_attention_mask=__UpperCamelCase  ,       output_hidden_states=__UpperCamelCase  ,       )["""hidden_states"""][0]
        _UpperCAmelCase        = model(
            __UpperCamelCase  ,       attention_mask=__UpperCamelCase  ,       encoder_hidden_states=__UpperCamelCase  ,       encoder_attention_mask=__UpperCamelCase  ,       past_key_values=__UpperCamelCase  ,       output_hidden_states=__UpperCamelCase  ,       )["""hidden_states"""][0]

        # select random slice
        _UpperCAmelCase        = ids_tensor((1,)  ,       output_from_past.shape[-1]  ).item()
        _UpperCAmelCase        = output_from_no_past[:, -3:, random_slice_idx].detach()
        _UpperCAmelCase        = output_from_past[:, :, random_slice_idx].detach()

        self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]  )

        # test that outputs are equal for slice
        self.parent.assertTrue(torch.allclose(__UpperCamelCase  ,       __UpperCamelCase  ,       atol=1e-3  )  )







    def   _snake_case       (      self      :							List[str]  )		->str:






        '''simple docstring'''






        _UpperCAmelCase        = self.prepare_config_and_inputs()
        (
            (
            _UpperCAmelCase
        )     ,(
            _UpperCAmelCase
        )     ,(
            _UpperCAmelCase
        )     ,(
            _UpperCAmelCase
        )     ,(
            _UpperCAmelCase
        )     ,(
            _UpperCAmelCase
        )     ,(
            _UpperCAmelCase
        )     ,
        )        = config_and_inputs
        _UpperCAmelCase        = {"""input_ids""": input_ids, """attention_mask""": input_mask}
        return config, inputs_dict







@require_torch
class 		a_    (			_UpperCAmelCase  ,    _UpperCAmelCase  ,    _UpperCAmelCase  ,    unittest.TestCase						):
    a   :					Union[str, Any]			     =					(
        (
            FalconModel,
            FalconForCausalLM,
            FalconForSequenceClassification,
            FalconForTokenClassification,
            FalconForQuestionAnswering,
        )
        if is_torch_available()
        else ()
    )
    a   :					List[str]			     =					(FalconForCausalLM,) if is_torch_available() else ()
    a   :					List[str]			     =					(
        {
            'feature-extraction': FalconModel,
            'text-classification': FalconForSequenceClassification,
            'text-generation': FalconForCausalLM,
            'question-answering': FalconForQuestionAnswering,
            'token-classification': FalconForTokenClassification,
            'zero-shot': FalconForSequenceClassification,
        }
        if is_torch_available()
        else {}
    )
    a   :					Any			     =					False
    a   :					Dict			     =					False







    def   _snake_case       (      self      :							Union[str, Any]  )		->Any:






        '''simple docstring'''






        _UpperCAmelCase        = FalconModelTester(self  )
        _UpperCAmelCase        = ConfigTester(self  ,       config_class=__UpperCamelCase  ,       hidden_size=37  )







    def   _snake_case       (      self      :							List[Any]  )		->List[str]:






        '''simple docstring'''






        self.config_tester.run_common_tests()







    def   _snake_case       (      self      :							Optional[Any]  )		->Optional[Any]:






        '''simple docstring'''






        _UpperCAmelCase        = self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*__UpperCamelCase  )







    def   _snake_case       (      self      :							int  )		->Optional[Any]:






        '''simple docstring'''






        _UpperCAmelCase     ,*_UpperCAmelCase        = self.model_tester.prepare_config_and_inputs()
        for alibi in [True, False]:
            _UpperCAmelCase        = alibi
            self.model_tester.create_and_check_model(__UpperCamelCase  ,       *__UpperCamelCase  )







    def   _snake_case       (      self      :							List[str]  )		->Optional[int]:






        '''simple docstring'''






        _UpperCAmelCase     ,_UpperCAmelCase        = self.model_tester.prepare_config_and_inputs_for_common()
        _UpperCAmelCase        = 3
        _UpperCAmelCase        = input_dict["""input_ids"""]
        _UpperCAmelCase        = input_ids.ne(1  ).to(__UpperCamelCase  )
        _UpperCAmelCase        = ids_tensor([self.model_tester.batch_size]  ,       self.model_tester.type_sequence_label_size  )
        _UpperCAmelCase        = FalconForSequenceClassification(__UpperCamelCase  )
        model.to(__UpperCamelCase  )
        model.eval()
        _UpperCAmelCase        = model(__UpperCamelCase  ,       attention_mask=__UpperCamelCase  ,       labels=__UpperCamelCase  )
        self.assertEqual(result.logits.shape  ,       (self.model_tester.batch_size, self.model_tester.num_labels)  )







    def   _snake_case       (      self      :							List[Any]  )		->List[Any]:






        '''simple docstring'''






        _UpperCAmelCase     ,_UpperCAmelCase        = self.model_tester.prepare_config_and_inputs_for_common()
        _UpperCAmelCase        = 3
        _UpperCAmelCase        = """single_label_classification"""
        _UpperCAmelCase        = input_dict["""input_ids"""]
        _UpperCAmelCase        = input_ids.ne(1  ).to(__UpperCamelCase  )
        _UpperCAmelCase        = ids_tensor([self.model_tester.batch_size]  ,       self.model_tester.type_sequence_label_size  )
        _UpperCAmelCase        = FalconForSequenceClassification(__UpperCamelCase  )
        model.to(__UpperCamelCase  )
        model.eval()
        _UpperCAmelCase        = model(__UpperCamelCase  ,       attention_mask=__UpperCamelCase  ,       labels=__UpperCamelCase  )
        self.assertEqual(result.logits.shape  ,       (self.model_tester.batch_size, self.model_tester.num_labels)  )







    def   _snake_case       (      self      :							List[str]  )		->Optional[Any]:






        '''simple docstring'''






        _UpperCAmelCase     ,_UpperCAmelCase        = self.model_tester.prepare_config_and_inputs_for_common()
        _UpperCAmelCase        = input_dict["""input_ids"""]
        _UpperCAmelCase        = FalconForCausalLM(__UpperCamelCase  )
        model.to(__UpperCamelCase  )
        model.eval()
        _UpperCAmelCase        = model(__UpperCamelCase  ,       use_cache=__UpperCamelCase  )
        _UpperCAmelCase        = input_ids.shape[0]
        _UpperCAmelCase        = model._convert_to_rw_cache(result.past_key_values  )
        _UpperCAmelCase        = model._convert_cache_to_standard_format(__UpperCamelCase  ,       __UpperCamelCase  )
        for layer in range(len(__UpperCamelCase  )  ):
            for tensor_idx in range(2  ):
                self.assertTrue(rw_cache[layer][tensor_idx].ndim == 3  )
                self.assertTrue(result.past_key_values[layer][tensor_idx].ndim == 4  )
                self.assertTrue(
                    torch.all(result.past_key_values[layer][tensor_idx] == standard_cache[layer][tensor_idx]  )  )







    def   _snake_case       (      self      :							Optional[int]  )		->Union[str, Any]:






        '''simple docstring'''






        _UpperCAmelCase     ,_UpperCAmelCase        = self.model_tester.prepare_config_and_inputs_for_common()
        _UpperCAmelCase        = 3
        _UpperCAmelCase        = """multi_label_classification"""
        _UpperCAmelCase        = input_dict["""input_ids"""]
        _UpperCAmelCase        = input_ids.ne(1  ).to(__UpperCamelCase  )
        _UpperCAmelCase        = ids_tensor(
            [self.model_tester.batch_size, config.num_labels]  ,       self.model_tester.type_sequence_label_size  ).to(torch.float  )
        _UpperCAmelCase        = FalconForSequenceClassification(__UpperCamelCase  )
        model.to(__UpperCamelCase  )
        model.eval()
        _UpperCAmelCase        = model(__UpperCamelCase  ,       attention_mask=__UpperCamelCase  ,       labels=__UpperCamelCase  )
        self.assertEqual(result.logits.shape  ,       (self.model_tester.batch_size, self.model_tester.num_labels)  )







    def   _snake_case       (      self      :							int  )		->Union[str, Any]:






        '''simple docstring'''






        for model_class in self.all_generative_model_classes:
            _UpperCAmelCase     ,_UpperCAmelCase        = self.model_tester.prepare_config_and_inputs_for_common()

            # If it doesn't support cache, pass the test
            if not hasattr(__UpperCamelCase  ,       """use_cache"""  ):
                return

            _UpperCAmelCase        = model_class(__UpperCamelCase  ).to(__UpperCamelCase  )
            if "use_cache" not in inputs:
                _UpperCAmelCase        = True
            _UpperCAmelCase        = model(**__UpperCamelCase  )

            # If "past_key_values" is not returned, pass the test (e.g. RWKV uses a different cache name and format)
            if "past_key_values" not in outputs:
                return

            _UpperCAmelCase        = (
                getattr(__UpperCamelCase  ,       """decoder_layers"""  ,       __UpperCamelCase  )
                or getattr(__UpperCamelCase  ,       """num_decoder_layers"""  ,       __UpperCamelCase  )
                or config.num_hidden_layers
            )
            _UpperCAmelCase        = getattr(__UpperCamelCase  ,       """num_kv_heads"""  ,       config.num_attention_heads  )
            _UpperCAmelCase        = getattr(__UpperCamelCase  ,       """d_model"""  ,       config.hidden_size  )
            _UpperCAmelCase        = embed_dim // num_attention_heads

            _UpperCAmelCase        = outputs["""past_key_values"""]
            self.assertEqual(len(__UpperCamelCase  )  ,       __UpperCamelCase  )

            _UpperCAmelCase     ,_UpperCAmelCase        = inputs["""input_ids"""].shape
            for i in range(__UpperCamelCase  ):
                if config.new_decoder_architecture:
                    _UpperCAmelCase        = config.num_attention_heads
                elif config.multi_query:
                    _UpperCAmelCase        = 1
                self.assertEqual(len(past_kv[0]  )  ,       2  )  # K V for the decoder = 2
                self.assertEqual(
                    past_kv[i][0].shape  ,       (batch_size, num_attention_heads, seq_length, per_head_embed_dim)  )
                self.assertEqual(
                    past_kv[i][1].shape  ,       (batch_size, num_attention_heads, seq_length, per_head_embed_dim)  )







@require_torch
class 		a_    (			unittest.TestCase						):







    @slow
    def   _snake_case       (      self      :							Optional[Any]  )		->int:






        '''simple docstring'''






        _UpperCAmelCase        = AutoTokenizer.from_pretrained("""Rocketknight1/falcon-rw-1b"""  )
        _UpperCAmelCase        = FalconForCausalLM.from_pretrained("""Rocketknight1/falcon-rw-1b"""  )
        model.eval()
        model.to(__UpperCamelCase  )
        _UpperCAmelCase        = tokenizer("""My favorite food is"""  ,       return_tensors="""pt"""  ).to(__UpperCamelCase  )

        _UpperCAmelCase        = (
            """My favorite food is pizza. I love it so much that I have a pizza party every year for my birthday."""
        )

        _UpperCAmelCase        = model.generate(**__UpperCamelCase  ,       do_sample=__UpperCamelCase  ,       max_new_tokens=19  )
        _UpperCAmelCase        = tokenizer.batch_decode(__UpperCamelCase  )[0]

        self.assertEqual(__UpperCamelCase  ,       __UpperCamelCase  )







    @slow
    def   _snake_case       (      self      :							List[Any]  )		->Tuple:






        '''simple docstring'''






        for repo in ["Rocketknight1/tiny-random-falcon-7b", "Rocketknight1/tiny-random-falcon-40b"]:
            _UpperCAmelCase        = AutoTokenizer.from_pretrained(__UpperCamelCase  )
            _UpperCAmelCase        = FalconForCausalLM.from_pretrained(__UpperCamelCase  )
            model.eval()
            model.to(__UpperCamelCase  )
            _UpperCAmelCase        = tokenizer("""My favorite food is"""  ,       return_tensors="""pt"""  ).to(__UpperCamelCase  )

            # We just test that these run without errors - the models are randomly initialized
            # and so the actual text outputs will be garbage
            model.generate(**__UpperCamelCase  ,       do_sample=__UpperCamelCase  ,       max_new_tokens=4  )
            model.generate(**__UpperCamelCase  ,       do_sample=__UpperCamelCase  ,       max_new_tokens=4  )
            model.generate(**__UpperCamelCase  ,       num_beams=2  ,       max_new_tokens=4  )







    @slow
    def   _snake_case       (      self      :							List[str]  )		->Any:






        '''simple docstring'''






        with torch.no_grad():
            for repo in [
                "Rocketknight1/falcon-rw-1b",
                "Rocketknight1/tiny-random-falcon-7b",
                "Rocketknight1/tiny-random-falcon-40b",
            ]:
                _UpperCAmelCase        = AutoTokenizer.from_pretrained(__UpperCamelCase  )
                _UpperCAmelCase        = FalconForCausalLM.from_pretrained(__UpperCamelCase  )
                model.eval()
                model.to(device=__UpperCamelCase  )
                _UpperCAmelCase        = tokenizer("""My favorite food is"""  ,       return_tensors="""pt"""  ).to(__UpperCamelCase  )

                # Test results are the same with and without cache
                _UpperCAmelCase        = model.generate(**__UpperCamelCase  ,       do_sample=__UpperCamelCase  ,       max_new_tokens=20  ,       use_cache=__UpperCamelCase  )
                _UpperCAmelCase        = model.generate(**__UpperCamelCase  ,       do_sample=__UpperCamelCase  ,       max_new_tokens=20  ,       use_cache=__UpperCamelCase  )
                self.assertTrue((outputs_cache - outputs_no_cache).sum().item() == 0  )

"""simple docstring"""



import cva
import numpy as np




class 		a_    :







    def __init__(      self      :							Optional[Any]  ,       __UpperCamelCase      :							float  ,       __UpperCamelCase      :							int  )		->Dict:






        '''simple docstring'''






        if k in (0.0_4, 0.0_6):
            _UpperCAmelCase        = k
            _UpperCAmelCase        = window_size
        else:
            raise ValueError("""invalid k value"""  )







    def __str__(      self      :							Tuple  )		->str:






        '''simple docstring'''






        return str(self.k  )







    def   _snake_case       (      self      :							str  ,       __UpperCamelCase      :							str  )		->tuple[cva.Mat, list[list[int]]]:






        '''simple docstring'''






        _UpperCAmelCase        = cva.imread(__UpperCamelCase  ,       0  )
        _UpperCAmelCase     ,_UpperCAmelCase        = img.shape
        _UpperCAmelCase        = []
        _UpperCAmelCase        = img.copy()
        _UpperCAmelCase        = cva.cvtColor(__UpperCamelCase  ,       cva.COLOR_GRAY2RGB  )
        _UpperCAmelCase     ,_UpperCAmelCase        = np.gradient(__UpperCamelCase  )
        _UpperCAmelCase        = dx**2
        _UpperCAmelCase        = dy**2
        _UpperCAmelCase        = dx * dy
        _UpperCAmelCase        = 0.0_4
        _UpperCAmelCase        = self.window_size // 2
        for y in range(__UpperCamelCase  ,       h - offset  ):
            for x in range(__UpperCamelCase  ,       w - offset  ):
                _UpperCAmelCase        = ixx[
                    y - offset : y + offset + 1, x - offset : x + offset + 1
                ].sum()
                _UpperCAmelCase        = iyy[
                    y - offset : y + offset + 1, x - offset : x + offset + 1
                ].sum()
                _UpperCAmelCase        = ixy[
                    y - offset : y + offset + 1, x - offset : x + offset + 1
                ].sum()

                _UpperCAmelCase        = (wxx * wyy) - (wxy**2)
                _UpperCAmelCase        = wxx + wyy
                _UpperCAmelCase        = det - k * (trace**2)
                # Can change the value
                if r > 0.5:
                    corner_list.append([x, y, r]  )
                    color_img.itemset((y, x, 0)  ,       0  )
                    color_img.itemset((y, x, 1)  ,       0  )
                    color_img.itemset((y, x, 2)  ,       2_55  )
        return color_img, corner_list


if __name__ == "__main__":
 a       :						List[Any]       		=		HarrisCorner(0.04, 3)
 a		,			a       :						List[Any]       		=		edge_detect.detect('''path_to_image''')
 cva.imwrite('''detect.png''', color_img)