



'''simple docstring'''





from cva import COLOR_BGR2GRAY, cvtColor, imread, imshow, waitKey
from numpy import array, dot, pad, ravel, uinta, zeros
def 		_a   (  lowerCamelCase_					,						lowerCamelCase_							):
   snake_case  ,    snake_case   :							List[str]						  =image.shape
   snake_case   :							str						  =cols - block_size[1] + 1
   snake_case   :							List[str]						  =rows - block_size[0] + 1
   snake_case   :							Tuple						  =zeros((dst_height * dst_width, block_size[1] * block_size[0])							)
   snake_case   :							str						  =0
   for i in range(0					,						lowerCamelCase_							):
      for j in range(0					,						lowerCamelCase_							):
         snake_case   :							Optional[int]						  =ravel(image[i : i + block_size[0], j : j + block_size[1]]							)
         snake_case   :							str						  =window
         row += 1

   return image_array
def 		_a   (  lowerCamelCase_					,						lowerCamelCase_							):
   snake_case  ,    snake_case   :							List[Any]						  =image.shape[0], image.shape[1]
   snake_case   :							str						  =filter_kernel.shape[0]
   snake_case   :							List[str]						  =k_size // 2
   # Pads image with the edge values of array.
   snake_case   :							str						  =pad(lowerCamelCase_					,						lowerCamelCase_					,						mode='''edge'''							)

   # im2col, turn the k_size*k_size pixels into a row and np.vstack all rows
   snake_case   :							List[Any]						  =imacol(lowerCamelCase_					,						(k_size, k_size)							)

   #  turn the kernel into shape(k*k, 1)
   snake_case   :							Dict						  =ravel(lowerCamelCase_							)
   # reshape and get the dst image
   snake_case   :							Tuple						  =dot(lowerCamelCase_					,						lowerCamelCase_							).reshape(lowerCamelCase_					,						lowerCamelCase_							)
   return dst


if __name__ == "__main__":
      # read original image
      A			:   int			=      imread(r"""../image_data/lena.jpg""")
      # turn image in gray scale value
      A			:   str			=      cvtColor(img, COLOR_BGR2GRAY)
      # Laplace operator
      A			:   Union[str, Any]			=      array([[0, 1, 0], [1, -4, 1], [0, 1, 0]])
      A			:   Any			=      img_convolve(gray, Laplace_kernel).astype(uinta)
      imshow("""Laplacian""", out)
      waitKey(0)










'''simple docstring'''





import os
import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device


if is_torch_available():
      import torch

      from transformers import GPTaLMHeadModel





@require_torch
@require_sentencepiece
@require_tokenizers
class 							lowerCAmelCase_		(	unittest.TestCase						):





    @slow
    @unittest.skip('''Model is not available.'''     )
    def 					__snake_case       (    self    :    List[Any]     ):



       '''simple docstring'''







       snake_case   :							Any						  ='''nvidia/megatron-gpt2-345m/'''
       if "MYDIR" in os.environ:
          snake_case   :							Any						  =os.path.join(os.environ['''MYDIR'''],    _snake_case     )
       snake_case   :							Optional[Any]						  =GPTaLMHeadModel.from_pretrained(_snake_case     )
       model.to(_snake_case     )
       model.half()

       snake_case   :							int						  =torch.tensor(
           [[101, 7_110, 1_005, 1_056, 2_023, 11_333, 17_413, 1_029, 102]],    device=_snake_case,    dtype=torch.long,    )

       with torch.no_grad():
          snake_case   :							Dict						  =model(_snake_case     ).logits

       snake_case   :							Dict						  =torch.Size((1, 9, 50_257)     )
       self.assertEqual(output.shape,    _snake_case     )

       snake_case   :							str						  =torch.tensor(
           [
               4.9414,
               -0.2920,
               -1.2148,
               -4.0273,
               -0.5161,
               -5.2109,
               -1.2412,
               -1.8301,
               -1.7734,
               -4.7148,
               -0.2317,
               -1.0811,
               -2.1777,
               0.4141,
               -3.7969,
               -4.0586,
               -2.5332,
               -3.3809,
               4.3867,
           ],    device=_snake_case,    dtype=torch.half,    )

       for i in range(19     ):
          snake_case  ,    snake_case   :							Tuple						  =8 * i // 17, 2_792 * i  # along the diagonal
          snake_case  ,    snake_case   :							List[str]						  =output[0, r, c], expected_diag[i]
          snake_case   :							Optional[int]						  =f'''row={r} col={c} computed={computed} expected={expected}'''
          self.assertAlmostEqual(_snake_case,    _snake_case,    delta=1E-4,    msg=_snake_case     )





