

import logging

# standard libraries
import sys

import numpy as np
import pytest  # type: ignore

# Custom/local libraries
from matrix import matrix_operation as matop

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

lowercase_									=    logging.getLogger()
lowercase_									=    logging.DEBUG
lowercase_									=    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 		_snake_case(       SCREAMING_SNAKE_CASE__     :      str       ,     SCREAMING_SNAKE_CASE__     :      Optional[int] )				-> str:





    '''simple docstring'''






    if (np.array(SCREAMING_SNAKE_CASE__ )).shape < (2, 2) or (np.array(SCREAMING_SNAKE_CASE__ )).shape < (2, 2):
        with pytest.raises(SCREAMING_SNAKE_CASE__ ):
            logger.info(f'\n\t{test_addition.__name__} returned integer' )
            matop.add(SCREAMING_SNAKE_CASE__       ,     SCREAMING_SNAKE_CASE__ )
    elif (np.array(SCREAMING_SNAKE_CASE__ )).shape == (np.array(SCREAMING_SNAKE_CASE__ )).shape:
        logger.info(f'\n\t{test_addition.__name__} with same matrix dims' )
        A__        =  (np.array(SCREAMING_SNAKE_CASE__ ) + np.array(SCREAMING_SNAKE_CASE__ )).tolist()
        A__        =  matop.add(SCREAMING_SNAKE_CASE__       ,     SCREAMING_SNAKE_CASE__ )
        assert theo == act
    else:
        with pytest.raises(SCREAMING_SNAKE_CASE__ ):
            logger.info(f'\n\t{test_addition.__name__} with different matrix dims' )
            matop.add(SCREAMING_SNAKE_CASE__       ,     SCREAMING_SNAKE_CASE__ )
@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 		_snake_case(       SCREAMING_SNAKE_CASE__     :      List[Any]       ,     SCREAMING_SNAKE_CASE__     :      Any )				-> Dict:





    '''simple docstring'''






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





    '''simple docstring'''






    if (np.array(SCREAMING_SNAKE_CASE__ )).shape < (2, 2) or (np.array(SCREAMING_SNAKE_CASE__ )).shape < (2, 2):
        logger.info(f'\n\t{test_multiplication.__name__} returned integer' )
        with pytest.raises(SCREAMING_SNAKE_CASE__ ):
            matop.add(SCREAMING_SNAKE_CASE__       ,     SCREAMING_SNAKE_CASE__ )
    elif (np.array(SCREAMING_SNAKE_CASE__ )).shape == (np.array(SCREAMING_SNAKE_CASE__ )).shape:
        logger.info(f'\n\t{test_multiplication.__name__} meets dim requirements' )
        A__        =  (np.matmul(SCREAMING_SNAKE_CASE__       ,     SCREAMING_SNAKE_CASE__ )).tolist()
        A__        =  matop.multiply(SCREAMING_SNAKE_CASE__       ,     SCREAMING_SNAKE_CASE__ )
        assert theo == act
    else:
        with pytest.raises(SCREAMING_SNAKE_CASE__ ):
            logger.info(
                f'\n\t{test_multiplication.__name__} does not meet dim requirements' )
            assert matop.subtract(SCREAMING_SNAKE_CASE__       ,     SCREAMING_SNAKE_CASE__ )
@pytest.mark.mat_ops
def 		_snake_case(       )				-> Optional[int]:





    '''simple docstring'''






    A__        =  (3.5 * np.array(SCREAMING_SNAKE_CASE__ )).tolist()
    A__        =  matop.scalar_multiply(SCREAMING_SNAKE_CASE__       ,     3.5 )
    assert theo == act
@pytest.mark.mat_ops
def 		_snake_case(       )				-> Optional[Any]:





    '''simple docstring'''






    A__        =  (np.identity(5 )).tolist()
    A__        =  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 		_snake_case(       SCREAMING_SNAKE_CASE__     :      int )				-> str:





    '''simple docstring'''






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




import timeit


class 					A		:







    """simple docstring"""





    def __init__( self					:			Optional[int],lowercase_					:			Union[str, Any]						)->       List[str]:





        '''simple docstring'''







        if isinstance(lowercase_,lowercase_						):  # Initializes a matrix identical to the one provided.
            A__        =  arg
            A__        =  len(lowercase_						)
        else:  # Initializes a square matrix of the given size and set values to zero.
            A__        =  arg
            A__        =  [[0 for _ in range(self.n						)] for _ in range(self.n						)]


    def __mul__( self					:			Union[str, Any],lowercase_					:			List[Any]						)->       List[str]:





        '''simple docstring'''







        A__        =  Matrix(self.n						)
        for i in range(self.n						):
            for j in range(self.n						):
                for k in range(self.n						):
                    matrix.t[i][j] += self.t[i][k] * b.t[k][j]
        return matrix




def 		_snake_case(       SCREAMING_SNAKE_CASE__     :      List[Any]       ,     SCREAMING_SNAKE_CASE__     :      Optional[Any] )				-> Union[str, Any]:





    '''simple docstring'''






    A__        =  Matrix([[1, 0], [0, 1]] )
    while b > 0:
        if b & 1:
            matrix *= a
        a *= a
        b >>= 1
    return matrix
def 		_snake_case(       SCREAMING_SNAKE_CASE__     :      Optional[int]       ,     SCREAMING_SNAKE_CASE__     :      str       ,     SCREAMING_SNAKE_CASE__     :      Any )				-> List[str]:





    '''simple docstring'''






    if n == 1:
        return fa
    elif n == 2:
        return fa
    A__        =  Matrix([[1, 1], [1, 0]] )
    A__        =  modular_exponentiation(SCREAMING_SNAKE_CASE__       ,     n - 2 )
    return fa * matrix.t[0][0] + fa * matrix.t[0][1]
def 		_snake_case(       SCREAMING_SNAKE_CASE__     :      Dict       ,     SCREAMING_SNAKE_CASE__     :      Tuple       ,     SCREAMING_SNAKE_CASE__     :      Tuple )				-> Dict:





    '''simple docstring'''






    if n == 1:
        return fa
    elif n == 2:
        return fa

    A__        =  fa
    A__        =  fa
    n -= 2

    while n > 0:
        A__ ,		A__        =  fn_a + fn_a, fn_a
        n -= 1

    return fn_a
def 		_snake_case(       )				-> Optional[Any]:





    '''simple docstring'''






    A__        =  '\nfrom random import randint\nfrom __main__ import fibonacci_with_matrix_exponentiation\n'
    A__        =  'fibonacci_with_matrix_exponentiation(randint(1,70000), 1, 1)'
    A__        =  timeit.timeit(setup=SCREAMING_SNAKE_CASE__       ,     stmt=SCREAMING_SNAKE_CASE__       ,     number=100 )
    print('With matrix exponentiation the average execution time is '       ,     exec_time / 100 )
    return exec_time
def 		_snake_case(       )				-> Optional[int]:





    '''simple docstring'''






    A__        =  '\nfrom random import randint\nfrom __main__ import simple_fibonacci\n'
    A__        =  'simple_fibonacci(randint(1,70000), 1, 1)'
    A__        =  timeit.timeit(setup=SCREAMING_SNAKE_CASE__       ,     stmt=SCREAMING_SNAKE_CASE__       ,     number=100 )
    print(
        'Without matrix exponentiation the average execution time is '       ,     exec_time / 100 )
    return exec_time
def 		_snake_case(       )				-> Union[str, Any]:





    '''simple docstring'''






    matrix_exponentiation_time()
    simple_fibonacci_time()


if __name__ == "__main__":
     main()

