

import logging

# standard libraries
import sys

import numpy as np
import pytest  # type: ignore

# Custom/local libraries
from matrix import matrix_operation as matop

lowerCAmelCase						:   Any										=    [[12, 10], [3, 9]]
lowerCAmelCase						:   Union[str, Any]										=    [[3, 4], [7, 4]]
lowerCAmelCase						:   str										=    [[3, 0, 2], [2, 0, -2], [0, 1, 1]]
lowerCAmelCase						:   List[str]										=    [[3, 0, -2], [2, 0, 2], [0, 1, 1]]
lowerCAmelCase						:   List[str]										=    [[3, 0, 2], [2, 0, -2], [0, 1, 1], [2, 0, -2]]
lowerCAmelCase						:   Optional[int]										=    [1]
lowerCAmelCase						:   Any										=    [2]

lowerCAmelCase						:   List[str]										=    logging.getLogger()
lowerCAmelCase						:   List[str]										=    logging.DEBUG
lowerCAmelCase						:   List[Any]										=    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    (      __UpperCamelCase     :		Optional[Any]   ,       __UpperCamelCase     :		str ):
      if (np.array(__UpperCamelCase )).shape < (2, 2) or (np.array(__UpperCamelCase )).shape < (2, 2):
            with pytest.raises(__UpperCamelCase ):
                  logger.info(F'''\n\t{test_addition.__name__} returned integer''' )
                  matop.add(__UpperCamelCase   ,       __UpperCamelCase )
      elif (np.array(__UpperCamelCase )).shape == (np.array(__UpperCamelCase )).shape:
            logger.info(F'''\n\t{test_addition.__name__} with same matrix dims''' )
            snake_case__					=   (np.array(__UpperCamelCase ) + np.array(__UpperCamelCase )).tolist()
            snake_case__					=   matop.add(__UpperCamelCase   ,       __UpperCamelCase )
            assert theo == act
      else:
            with pytest.raises(__UpperCamelCase ):
                  logger.info(F'''\n\t{test_addition.__name__} with different matrix dims''' )
                  matop.add(__UpperCamelCase   ,       __UpperCamelCase )





@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    (      __UpperCamelCase     :		Optional[Any]   ,       __UpperCamelCase     :		Optional[int] ):
      if (np.array(__UpperCamelCase )).shape < (2, 2) or (np.array(__UpperCamelCase )).shape < (2, 2):
            with pytest.raises(__UpperCamelCase ):
                  logger.info(F'''\n\t{test_subtraction.__name__} returned integer''' )
                  matop.subtract(__UpperCamelCase   ,       __UpperCamelCase )
      elif (np.array(__UpperCamelCase )).shape == (np.array(__UpperCamelCase )).shape:
            logger.info(F'''\n\t{test_subtraction.__name__} with same matrix dims''' )
            snake_case__					=   (np.array(__UpperCamelCase ) - np.array(__UpperCamelCase )).tolist()
            snake_case__					=   matop.subtract(__UpperCamelCase   ,       __UpperCamelCase )
            assert theo == act
      else:
            with pytest.raises(__UpperCamelCase ):
                  logger.info(F'''\n\t{test_subtraction.__name__} with different matrix dims''' )
                  assert matop.subtract(__UpperCamelCase   ,       __UpperCamelCase )





@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    (      __UpperCamelCase     :		Optional[Any]   ,       __UpperCamelCase     :		Tuple ):
      if (np.array(__UpperCamelCase )).shape < (2, 2) or (np.array(__UpperCamelCase )).shape < (2, 2):
            logger.info(F'''\n\t{test_multiplication.__name__} returned integer''' )
            with pytest.raises(__UpperCamelCase ):
                  matop.add(__UpperCamelCase   ,       __UpperCamelCase )
      elif (np.array(__UpperCamelCase )).shape == (np.array(__UpperCamelCase )).shape:
            logger.info(F'''\n\t{test_multiplication.__name__} meets dim requirements''' )
            snake_case__					=   (np.matmul(__UpperCamelCase   ,       __UpperCamelCase )).tolist()
            snake_case__					=   matop.multiply(__UpperCamelCase   ,       __UpperCamelCase )
            assert theo == act
      else:
            with pytest.raises(__UpperCamelCase ):
                  logger.info(
                      F'''\n\t{test_multiplication.__name__} does not meet dim requirements''' )
                  assert matop.subtract(__UpperCamelCase   ,       __UpperCamelCase )





@pytest.mark.mat_ops
def 			_lowercase    (      ):
      snake_case__					=   (3.5 * np.array(__UpperCamelCase )).tolist()
      snake_case__					=   matop.scalar_multiply(__UpperCamelCase   ,       3.5 )
      assert theo == act





@pytest.mark.mat_ops
def 			_lowercase    (      ):
      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    (      __UpperCamelCase     :		List[str] ):
      if (np.array(__UpperCamelCase )).shape < (2, 2):
            with pytest.raises(__UpperCamelCase ):
                  logger.info(F'''\n\t{test_transpose.__name__} returned integer''' )
                  matop.transpose(__UpperCamelCase )
      else:
            snake_case__					=   (np.transpose(__UpperCamelCase )).tolist()
            snake_case__					=   matop.transpose(__UpperCamelCase   ,       return_map=__UpperCamelCase )
            assert theo == act









lowerCAmelCase						:   Optional[Any]										=    1000





def 			_lowercase    (      __UpperCamelCase     :		float ):
      return x * x





def 			_lowercase    (      __UpperCamelCase     :		int   ,       __UpperCamelCase     :		float   ,       __UpperCamelCase     :		float   ,       __UpperCamelCase     :		int = 4 ):
      assert callable(
          __UpperCamelCase ), F'''the function(object) passed should be callable your input : {function}'''
      assert isinstance(__UpperCamelCase   ,       (float, int) ), F'''a should be float or integer your input : {a}'''
      assert isinstance(function(__UpperCamelCase )   ,       (float, int) ), (
          "the function should return integer or float return type of your function, "
          F'''{type(__UpperCamelCase )}'''
      )
      assert isinstance(__UpperCamelCase   ,       (float, int) ), F'''b should be float or integer your input : {b}'''
      assert (
          isinstance(__UpperCamelCase   ,       __UpperCamelCase ) and precision > 0
      ), F'''precision should be positive integer your input : {precision}'''

      # just applying the formula of simpson for approximate integration written in
      # mentioned article in first comment of this file and above this function

      snake_case__					=   (b - a) / N_STEPS
      snake_case__					=   function(__UpperCamelCase ) + function(__UpperCamelCase )

      for i in range(1   ,       __UpperCamelCase ):
            snake_case__					=   a + h * i
            result += function(__UpperCamelCase ) * (4 if i % 2 else 2)

      result *= h / 3
      return round(__UpperCamelCase   ,       __UpperCamelCase )


if __name__ == "__main__":
       import doctest

       doctest.testmod()






