
class 	lowerCamelCase						:





     def __init__(self :       Optional[Any]  )		->		None:
         # numbermap keys are the number and its values are lists of indexes sorted
         # in ascending order
         snake_case						=   {}
         # indexmap keys are an index and it's values are the number at that index
         snake_case						=   {}





     def 						UpperCAmelCase(self :       List[str]							,       _A :       list | str | range							,       _A :       int  )		->		list[int]:
         if isinstance(_A							,       (range, str)  ):
             snake_case						=   list(_A  )
         elif not isinstance(_A							,       _A  ):
             raise TypeError(
                 "binary_search_delete() only accepts either a list, range or str"  )

         snake_case						=   0
         snake_case						=   len(_A  ) - 1

         while low <= high:
             snake_case						=   (low + high) // 2
             if array[mid] == item:
                 array.pop(_A  )
                 return array
             elif array[mid] < item:
                 snake_case						=   mid + 1
             else:
                 snake_case						=   mid - 1
         raise ValueError(
             "Either the item is not in the array or the array was unsorted"  )





     def 						UpperCAmelCase(self :       Any							,       _A :       list | str | range							,       _A :       int  )		->		list[int]:
         if isinstance(_A							,       (range, str)  ):
             snake_case						=   list(_A  )
         elif not isinstance(_A							,       _A  ):
             raise TypeError(
                 "binary_search_insert() only accepts either a list, range or str"  )

         snake_case						=   0
         snake_case						=   len(_A  ) - 1

         while low <= high:
             snake_case						=   (low + high) // 2
             if array[mid] == index:
                 # If the item already exists in the array,
                 # insert it after the existing item
                 array.insert(mid + 1							,       _A  )
                 return array
             elif array[mid] < index:
                 snake_case						=   mid + 1
             else:
                 snake_case						=   mid - 1

        # If the item doesn't exist in the array, insert it at the appropriate position
         array.insert(_A							,       _A  )
         return array





     def 						UpperCAmelCase(self :       Tuple							,       _A :       int							,       _A :       int  )		->		None:
         # Remove previous index
         if index in self.indexmap:
             snake_case						=   self.indexmap[index]
             if len(self.numbermap[n]  ) == 1:
                 del self.numbermap[n]
             else:
                 snake_case						=   self.binary_search_delete(self.numbermap[n]							,       _A  )

        # Set new index
         snake_case						=   number

         # Number not seen before or empty so insert number value
         if number not in self.numbermap:
             snake_case						=   [index]

         # Here we need to perform a binary search insertion in order to insert
         # The item in the correct place
         else:
             snake_case						=   self.binary_search_insert(
                 self.numbermap[number]							,       _A  )





     def 						UpperCAmelCase(self :       List[Any]							,       _A :       int  )		->		int:
         return self.numbermap.get(_A							,       [-1]  )[0]


if __name__ == "__main__":
   import doctest

   doctest.testmod()



import logging

# standard libraries
import sys

import numpy as np
import pytest  # type: ignore

# Custom/local libraries
from matrix import matrix_operation as matop

_A       =					[[12, 10], [3, 9]]
_A       =					[[3, 4], [7, 4]]
_A       =					[[3, 0, 2], [2, 0, -2], [0, 1, 1]]
_A       =					[[3, 0, -2], [2, 0, 2], [0, 1, 1]]
_A       =					[[3, 0, 2], [2, 0, -2], [0, 1, 1], [2, 0, -2]]
_A       =					[1]
_A       =					[2]

_A       =					logging.getLogger()
_A       =					logging.DEBUG
_A       =					logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)



@pytest.mark.mat_ops
@pytest.mark.parametrize(
    ("mat1", "mat2")					,						[(mat_a, mat_b), (mat_c, mat_d), (mat_d, mat_e), (mat_f, mat_h)]						)
def 		lowercase_     (  A__					,						A__						)				->				Dict:
    """simple docstring"""

    if (np.array(A__						)).shape < (2, 2) or (np.array(A__						)).shape < (2, 2):
        with pytest.raises(A__						):
            logger.info(F'\n\t{test_addition.__name__} returned integer'						)
            matop.add(A__					,						A__						)
    elif (np.array(A__						)).shape == (np.array(A__						)).shape:
        logger.info(F'\n\t{test_addition.__name__} with same matrix dims'						)
        snake_case						=   (np.array(A__						) + np.array(A__						)).tolist()
        snake_case						=   matop.add(A__					,						A__						)
        assert theo == act
    else:
        with pytest.raises(A__						):
            logger.info(F'\n\t{test_addition.__name__} with different matrix dims'						)
            matop.add(A__					,						A__						)



@pytest.mark.mat_ops
@pytest.mark.parametrize(
    ("mat1", "mat2")					,						[(mat_a, mat_b), (mat_c, mat_d), (mat_d, mat_e), (mat_f, mat_h)]						)
def 		lowercase_     (  A__					,						A__						)				->				List[Any]:
    """simple docstring"""

    if (np.array(A__						)).shape < (2, 2) or (np.array(A__						)).shape < (2, 2):
        with pytest.raises(A__						):
            logger.info(F'\n\t{test_subtraction.__name__} returned integer'						)
            matop.subtract(A__					,						A__						)
    elif (np.array(A__						)).shape == (np.array(A__						)).shape:
        logger.info(F'\n\t{test_subtraction.__name__} with same matrix dims'						)
        snake_case						=   (np.array(A__						) - np.array(A__						)).tolist()
        snake_case						=   matop.subtract(A__					,						A__						)
        assert theo == act
    else:
        with pytest.raises(A__						):
            logger.info(F'\n\t{test_subtraction.__name__} with different matrix dims'						)
            assert matop.subtract(A__					,						A__						)



@pytest.mark.mat_ops
@pytest.mark.parametrize(
    ("mat1", "mat2")					,						[(mat_a, mat_b), (mat_c, mat_d), (mat_d, mat_e), (mat_f, mat_h)]						)
def 		lowercase_     (  A__					,						A__						)				->				Union[str, Any]:
    """simple docstring"""

    if (np.array(A__						)).shape < (2, 2) or (np.array(A__						)).shape < (2, 2):
        logger.info(F'\n\t{test_multiplication.__name__} returned integer'						)
        with pytest.raises(A__						):
            matop.add(A__					,						A__						)
    elif (np.array(A__						)).shape == (np.array(A__						)).shape:
        logger.info(F'\n\t{test_multiplication.__name__} meets dim requirements'						)
        snake_case						=   (np.matmul(A__					,						A__						)).tolist()
        snake_case						=   matop.multiply(A__					,						A__						)
        assert theo == act
    else:
        with pytest.raises(A__						):
            logger.info(
                F'\n\t{test_multiplication.__name__} does not meet dim requirements'						)
            assert matop.subtract(A__					,						A__						)



@pytest.mark.mat_ops
def 		lowercase_     (  )				->				int:
    """simple docstring"""

    snake_case						=   (3.5 * np.array(A__						)).tolist()
    snake_case						=   matop.scalar_multiply(A__					,						3.5						)
    assert theo == act



@pytest.mark.mat_ops
def 		lowercase_     (  )				->				Any:
    """simple docstring"""

    snake_case						=   (np.identity(5						)).tolist()
    snake_case						=   matop.identity(5						)
    assert theo == act





@pytest.mark.mat_ops
@pytest.mark.parametrize("mat"					,						[mat_a, mat_b, mat_c, mat_d, mat_e, mat_f]						)
def 		lowercase_     (  A__						)				->				List[str]:
    """simple docstring"""

    if (np.array(A__						)).shape < (2, 2):
        with pytest.raises(A__						):
            logger.info(F'\n\t{test_transpose.__name__} returned integer'						)
            matop.transpose(A__						)
    else:
        snake_case						=   (np.transpose(A__						)).tolist()
        snake_case						=   matop.transpose(A__					,						return_map=A__						)
        assert theo == act

