




import unittest

from .lib import (
    Matrix,
    Vector,
    axpy,
    square_zero_matrix,
    unit_basis_vector,
    zero_vector,
)






class  _lowerCAmelCase     (  unittest.TestCase	):

      def 	__magic_name__(   self		):
        lowerCAmelCase__				:  Union[str, Any]		       =     Vector([1, 2, 3]		)
        self.assertEqual(x.component(0		)      ,				1		)
        self.assertEqual(x.component(2		)      ,				3		)
        lowerCAmelCase__				:  Optional[int]		       =     Vector()

      def 	__magic_name__(   self		):
        lowerCAmelCase__				:  str		       =     Vector([0, 0, 0, 0, 0, 1]		)
        self.assertEqual(str(__UpperCAmelCase		)      ,				'''(0,0,0,0,0,1)'''		)

      def 	__magic_name__(   self		):
        lowerCAmelCase__				:  Tuple		       =     Vector([1, 2, 3, 4]		)
        self.assertEqual(len(__UpperCAmelCase		)      ,				4		)

      def 	__magic_name__(   self		):
        lowerCAmelCase__				:  int		       =     Vector([1, 2]		)
        lowerCAmelCase__				:  Tuple		       =     Vector([1, 2, 3, 4, 5]		)
        lowerCAmelCase__				:  Optional[int]		       =     Vector([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]		)
        lowerCAmelCase__				:  str		       =     Vector([1, -1, 1, -1, 2, -3, 4, -5]		)
        self.assertAlmostEqual(x.euclidean_length()      ,				2.236      ,				3		)
        self.assertAlmostEqual(y.euclidean_length()      ,				7.416      ,				3		)
        self.assertEqual(z.euclidean_length()      ,				0		)
        self.assertAlmostEqual(w.euclidean_length()      ,				7.616      ,				3		)

      def 	__magic_name__(   self		):
        lowerCAmelCase__				:  int		       =     Vector([1, 2, 3]		)
        lowerCAmelCase__				:  Union[str, Any]		       =     Vector([1, 1, 1]		)
        self.assertEqual((x + y).component(0		)      ,				2		)
        self.assertEqual((x + y).component(1		)      ,				3		)
        self.assertEqual((x + y).component(2		)      ,				4		)

      def 	__magic_name__(   self		):
        lowerCAmelCase__				:  List[Any]		       =     Vector([1, 2, 3]		)
        lowerCAmelCase__				:  Dict		       =     Vector([1, 1, 1]		)
        self.assertEqual((x - y).component(0		)      ,				0		)
        self.assertEqual((x - y).component(1		)      ,				1		)
        self.assertEqual((x - y).component(2		)      ,				2		)

      def 	__magic_name__(   self		):
        lowerCAmelCase__				:  Tuple		       =     Vector([1, 2, 3]		)
        lowerCAmelCase__				:  Any		       =     Vector([2, -1, 4]		)  # for test of dot product
        lowerCAmelCase__				:  Optional[int]		       =     Vector([1, -2, -1]		)
        self.assertEqual(str(x * 3.0		)      ,				'''(3.0,6.0,9.0)'''		)
        self.assertEqual((a * b)      ,				0		)

      def 	__magic_name__(   self		):
        self.assertEqual(str(zero_vector(10		)		).count('''0'''		)      ,				10		)

      def 	__magic_name__(   self		):
        self.assertEqual(str(unit_basis_vector(3      ,				1		)		)      ,				'''(0,1,0)'''		)

      def 	__magic_name__(   self		):
        lowerCAmelCase__				:  int		       =     Vector([1, 2, 3]		)
        lowerCAmelCase__				:  Optional[Any]		       =     Vector([1, 0, 1]		)
        self.assertEqual(str(axpy(2      ,				__UpperCAmelCase      ,				__UpperCAmelCase		)		)      ,				'''(3,4,7)'''		)

      def 	__magic_name__(   self		):
        lowerCAmelCase__				:  str		       =     Vector([1, 0, 0, 0, 0, 0]		)
        lowerCAmelCase__				:  Optional[Any]		       =     x.copy()
        self.assertEqual(str(__UpperCAmelCase		)      ,				str(__UpperCAmelCase		)		)

      def 	__magic_name__(   self		):
        lowerCAmelCase__				:  int		       =     Vector([1, 0, 0]		)
        x.change_component(0      ,				0		)
        x.change_component(1      ,				1		)
        self.assertEqual(str(__UpperCAmelCase		)      ,				'''(0,1,0)'''		)

      def 	__magic_name__(   self		):
        lowerCAmelCase__				:  Dict		       =     Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]      ,				3      ,				3		)
        self.assertEqual('''|1,2,3|\n|2,4,5|\n|6,7,8|\n'''      ,				str(__UpperCAmelCase		)		)

      def 	__magic_name__(   self		):
        lowerCAmelCase__				:  Tuple		       =     Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]      ,				3      ,				3		)
        lowerCAmelCase__				:  int		       =     [[-3, -14, -10], [-5, -10, -5], [-2, -1, 0]]
        for x in range(a.height()		):
          for y in range(a.width()		):
            self.assertEqual(minors[x][y]      ,				a.minor(__UpperCAmelCase      ,				__UpperCAmelCase		)		)

      def 	__magic_name__(   self		):
        lowerCAmelCase__				:  List[str]		       =     Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]      ,				3      ,				3		)
        lowerCAmelCase__				:  Any		       =     [[-3, 14, -10], [5, -10, 5], [-2, 1, 0]]
        for x in range(a.height()		):
          for y in range(a.width()		):
            self.assertEqual(cofactors[x][y]      ,				a.cofactor(__UpperCAmelCase      ,				__UpperCAmelCase		)		)

      def 	__magic_name__(   self		):
        lowerCAmelCase__				:  Tuple		       =     Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]      ,				3      ,				3		)
        self.assertEqual(-5      ,				a.determinant()		)

      def 	__magic_name__(   self		):
        lowerCAmelCase__				:  Optional[Any]		       =     Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]      ,				3      ,				3		)
        lowerCAmelCase__				:  Any		       =     Vector([1, 2, 3]		)
        self.assertEqual('''(14,32,50)'''      ,				str(a * x		)		)
        self.assertEqual('''|2,4,6|\n|8,10,12|\n|14,16,18|\n'''      ,				str(a * 2		)		)

      def 	__magic_name__(   self		):
        lowerCAmelCase__				:  str		       =     Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]      ,				3      ,				3		)
        a.change_component(0      ,				2      ,				5		)
        self.assertEqual('''|1,2,5|\n|2,4,5|\n|6,7,8|\n'''      ,				str(__UpperCAmelCase		)		)

      def 	__magic_name__(   self		):
        lowerCAmelCase__				:  Optional[Any]		       =     Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]      ,				3      ,				3		)
        self.assertEqual(7      ,				a.component(2      ,				1		)      ,				0.01		)

      def 	__magic_name__(   self		):
        lowerCAmelCase__				:  List[str]		       =     Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]      ,				3      ,				3		)
        lowerCAmelCase__				:  Union[str, Any]		       =     Matrix([[1, 2, 7], [2, 4, 5], [6, 7, 10]]      ,				3      ,				3		)
        self.assertEqual('''|2,4,10|\n|4,8,10|\n|12,14,18|\n'''      ,				str(a + b		)		)

      def 	__magic_name__(   self		):
        lowerCAmelCase__				:  List[str]		       =     Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]      ,				3      ,				3		)
        lowerCAmelCase__				:  List[Any]		       =     Matrix([[1, 2, 7], [2, 4, 5], [6, 7, 10]]      ,				3      ,				3		)
        self.assertEqual('''|0,0,-4|\n|0,0,0|\n|0,0,-2|\n'''      ,				str(a - b		)		)







      def 	__magic_name__(   self		):
        self.assertEqual(
            '''|0,0,0,0,0|\n|0,0,0,0,0|\n|0,0,0,0,0|\n|0,0,0,0,0|\n|0,0,0,0,0|\n'''      ,				str(square_zero_matrix(5		)		)      ,				)


if __name__ == "__main__":
     unittest.main()







def      __lowerCAmelCase			(					UpperCamelCase      )     ->	None:
  lowerCAmelCase__				:  Dict		       =     generate_pascal_triangle(UpperCamelCase      )
  for row_idx in range(UpperCamelCase      ):
    # Print left spaces
    for _ in range(num_rows - row_idx - 1      ):
      print(end=''' '''      )
    # Print row values
    for col_idx in range(row_idx + 1      ):
      if col_idx != row_idx:
        print(triangle[row_idx][col_idx]	,      end=''' '''      )
      else:
        print(triangle[row_idx][col_idx]	,      end=''''''      )
    print()



def      __lowerCAmelCase			(					UpperCamelCase      )     ->	list[list[int]]:

  if not isinstance(UpperCamelCase	,      UpperCamelCase      ):
    raise TypeError('''The input value of \'num_rows\' should be \'int\''''      )

  if num_rows == 0:
    return []
  elif num_rows < 0:
    raise ValueError(
        '''The input value of \'num_rows\' should be greater than or equal to 0'''      )

  lowerCAmelCase__				:  list[list[int]]		       =     []
  for current_row_idx in range(UpperCamelCase      ):
    lowerCAmelCase__				:  List[str]		       =     populate_current_row(UpperCamelCase	,      UpperCamelCase      )
    triangle.append(UpperCamelCase      )
  return triangle



def      __lowerCAmelCase			(					UpperCamelCase	,      UpperCamelCase      )     ->	list[int]:
  lowerCAmelCase__				:  Optional[Any]		       =     [-1] * (current_row_idx + 1)
  # first and last elements of current row are equal to 1
  lowerCAmelCase__       ,			lowerCAmelCase__				:  int		       =     1, 1
  for current_col_idx in range(1	,      UpperCamelCase      ):
    calculate_current_element(
        UpperCamelCase	,      UpperCamelCase	,      UpperCamelCase	,      UpperCamelCase      )
  return current_row



def      __lowerCAmelCase			(					UpperCamelCase	,      UpperCamelCase	,      UpperCamelCase	,      UpperCamelCase	,      )     ->	None:
  lowerCAmelCase__				:  Optional[int]		       =     triangle[current_row_idx - 1][current_col_idx - 1]
  lowerCAmelCase__				:  List[str]		       =     triangle[current_row_idx - 1][current_col_idx]
  lowerCAmelCase__				:  List[Any]		       =     above_to_left_elt + above_to_right_elt



def      __lowerCAmelCase			(					UpperCamelCase      )     ->	list[list[int]]:

  if not isinstance(UpperCamelCase	,      UpperCamelCase      ):
    raise TypeError('''The input value of \'num_rows\' should be \'int\''''      )

  if num_rows == 0:
    return []
  elif num_rows < 0:
    raise ValueError(
        '''The input value of \'num_rows\' should be greater than or equal to 0'''      )

  lowerCAmelCase__				:  list[list[int]]		       =     [[1]]

  for row_index in range(1	,      UpperCamelCase      ):
    lowerCAmelCase__				:  Optional[int]		       =     [0] + result[-1] + [0]
    lowerCAmelCase__				:  List[str]		       =     row_index + 1
    # Calculate the number of distinct elements in a row
    lowerCAmelCase__				:  Tuple		       =     sum(divmod(UpperCamelCase	,      2      )      )
    lowerCAmelCase__				:  Tuple		       =     [
        temp_row[i - 1] + temp_row[i] for i in range(1	,      distinct_elements + 1      )
    ]
    lowerCAmelCase__				:  int		       =     row_first_half[: (row_index + 1) // 2]
    row_second_half.reverse()
    lowerCAmelCase__				:  Dict		       =     row_first_half + row_second_half
    result.append(UpperCamelCase      )

  return result



def      __lowerCAmelCase			(					)     ->	None:
  from collections.abc import Callable
  from timeit import timeit

  def benchmark_a_function(UpperCamelCase	,      UpperCamelCase      ) -> None:
    lowerCAmelCase__				:  Tuple		       =     F"""{func.__name__}({value})"""
    lowerCAmelCase__				:  Dict		       =     timeit(F"""__main__.{call}"""	,      setup='''import __main__'''      )
    # print(f"{call:38} = {func(value)} -- {timing:.4f} seconds")
    print(F"""{call:38} -- {timing:.4f} seconds"""      )

  for value in range(15      ):  # (1, 7, 14):
    for func in (generate_pascal_triangle, generate_pascal_triangle_optimized):
      benchmark_a_function(UpperCamelCase	,      UpperCamelCase      )
    print()


if __name__ == "__main__":
     import doctest

     doctest.testmod()
     benchmark()

