


'''simple docstring'''





from __future__ import annotations




class 				UpperCAmelCase			:


 def __init__(      self							:	Dict			,       __lowerCamelCase							:	list[list[int]] ):
    UpperCAmelCase__	:List[str]      =      TypeError(
        '''Matrices must be formed from a list of zero or more lists containing at '''
        '''least one and the same number of values, each of which must be of type '''
        '''int or float.''' )
    if len(__lowerCamelCase ) != 0:
       UpperCAmelCase__	:Any      =      len(rows[0] )
       if cols == 0:
          raise error
       for row in rows:
          if len(__lowerCamelCase ) != cols:
             raise error
          for value in row:
             if not isinstance(__lowerCamelCase			,       (int, float) ):
                raise error
       UpperCAmelCase__	:Optional[int]      =      rows
    else:
       UpperCAmelCase__	:Any      =      []


 def        __SCREAMING_SNAKE_CASE					(      self							:	Any ):
    return [[row[i] for row in self.rows] for i in range(len(self.rows[0] ) )]


 @property
 def        __SCREAMING_SNAKE_CASE					(      self							:	Tuple ):
    return len(self.rows )


 @property
 def        __SCREAMING_SNAKE_CASE					(      self							:	Tuple ):
    return len(self.rows[0] )


 @property
 def        __SCREAMING_SNAKE_CASE					(      self							:	str ):
    return (self.num_rows, self.num_columns)


 @property
 def        __SCREAMING_SNAKE_CASE					(      self							:	Optional[int] ):
    return self.order[0] == self.order[1]


 def        __SCREAMING_SNAKE_CASE					(      self							:	Union[str, Any] ):
    UpperCAmelCase__	:List[Any]      =      [
        [0 if column_num != row_num else 1 for column_num in range(self.num_rows )]
        for row_num in range(self.num_rows )
    ]
    return Matrix(__lowerCamelCase )


 def        __SCREAMING_SNAKE_CASE					(      self							:	Tuple ):
    if not self.is_square:
       return 0
    if self.order == (0, 0):
       return 1
    if self.order == (1, 1):
       return int(self.rows[0][0] )
    if self.order == (2, 2):
       return int(
           (self.rows[0][0] * self.rows[1][1])
           - (self.rows[0][1] * self.rows[1][0]) )
    else:
       return sum(
           self.rows[0][column] * self.cofactors().rows[0][column]
           for column in range(self.num_columns ) )


 def        __SCREAMING_SNAKE_CASE					(      self							:	Optional[Any] ):
    return bool(self.determinant() )


 def        __SCREAMING_SNAKE_CASE					(      self							:	Union[str, Any]			,       __lowerCamelCase							:	int			,       __lowerCamelCase							:	int ):
    UpperCAmelCase__	:List[Any]      =      [
        [
            self.rows[other_row][other_column]
            for other_column in range(self.num_columns )
            if other_column != column
        ]
        for other_row in range(self.num_rows )
        if other_row != row
    ]
    return Matrix(__lowerCamelCase ).determinant()


 def        __SCREAMING_SNAKE_CASE					(      self							:	Dict			,       __lowerCamelCase							:	int			,       __lowerCamelCase							:	int ):
    if (row + column) % 2 == 0:
       return self.get_minor(__lowerCamelCase			,       __lowerCamelCase )
    return -1 * self.get_minor(__lowerCamelCase			,       __lowerCamelCase )


 def        __SCREAMING_SNAKE_CASE					(      self							:	Dict ):
    return Matrix(
        [
            [self.get_minor(__lowerCamelCase			,       __lowerCamelCase ) for column in range(self.num_columns )]
            for row in range(self.num_rows )
        ] )


 def        __SCREAMING_SNAKE_CASE					(      self							:	Dict ):
    return Matrix(
        [
            [
                self.minors().rows[row][column]
                if (row + column) % 2 == 0
                else self.minors().rows[row][column] * -1
                for column in range(self.minors().num_columns )
            ]
            for row in range(self.minors().num_rows )
        ] )


 def        __SCREAMING_SNAKE_CASE					(      self							:	int ):
    UpperCAmelCase__	:Any      =      [
        [self.cofactors().rows[column][row] for column in range(self.num_columns )]
        for row in range(self.num_rows )
    ]
    return Matrix(__lowerCamelCase )


 def        __SCREAMING_SNAKE_CASE					(      self							:	List[str] ):
    UpperCAmelCase__	:int      =      self.determinant()
    if not determinant:
       raise TypeError('''Only matrices with a non-zero determinant have an inverse''' )
    return self.adjugate() * (1 / determinant)


 def __repr__(      self							:	Tuple ):
    return str(self.rows )


 def __str__(      self							:	int ):
    if self.num_rows == 0:
       return "[]"
    if self.num_rows == 1:
       return "[[" + ". ".join(str(self.rows[0] ) ) + "]]"
    return (
        "["
        + "\n ".join(
            [
                '''[''' + '''. '''.join([str(__lowerCamelCase ) for value in row] ) + '''.]'''
                for row in self.rows
            ] )
        + "]"
    )


 def        __SCREAMING_SNAKE_CASE					(      self							:	Dict			,       __lowerCamelCase							:	list[int]			,       __lowerCamelCase							:	int | None = None ):
    UpperCAmelCase__	:Union[str, Any]      =      TypeError('''Row must be a list containing all ints and/or floats''' )
    if not isinstance(__lowerCamelCase			,       __lowerCamelCase ):
       raise type_error
    for value in row:
       if not isinstance(__lowerCamelCase			,       (int, float) ):
          raise type_error
    if len(__lowerCamelCase ) != self.num_columns:
       raise ValueError(
           '''Row must be equal in length to the other rows in the matrix''' )
    if position is None:
       self.rows.append(__lowerCamelCase )
    else:
       UpperCAmelCase__	:Dict      =      self.rows[0:position] + [row] + self.rows[position:]


 def        __SCREAMING_SNAKE_CASE					(      self							:	Dict			,       __lowerCamelCase							:	list[int]			,       __lowerCamelCase							:	int | None = None ):
    UpperCAmelCase__	:Dict      =      TypeError(
        '''Column must be a list containing all ints and/or floats''' )
    if not isinstance(__lowerCamelCase			,       __lowerCamelCase ):
       raise type_error
    for value in column:
       if not isinstance(__lowerCamelCase			,       (int, float) ):
          raise type_error
    if len(__lowerCamelCase ) != self.num_rows:
       raise ValueError(
           '''Column must be equal in length to the other columns in the matrix''' )
    if position is None:
       UpperCAmelCase__	:List[Any]      =      [self.rows[i] + [column[i]] for i in range(self.num_rows )]
    else:
       UpperCAmelCase__	:Any      =      [
           self.rows[i][0:position] + [column[i]] + self.rows[i][position:]
           for i in range(self.num_rows )
       ]


 def __eq__(      self							:	Dict			,       __lowerCamelCase							:	object ):
    if not isinstance(__lowerCamelCase			,       __lowerCamelCase ):
       return NotImplemented
    return self.rows == other.rows


 def __ne__(      self							:	List[Any]			,       __lowerCamelCase							:	object ):
    return not self == other


 def __neg__(      self							:	Any ):
    return self * -1


 def __add__(      self							:	Dict			,       __lowerCamelCase							:	Matrix ):
    if self.order != other.order:
       raise ValueError('''Addition requires matrices of the same order''' )
    return Matrix(
        [
            [self.rows[i][j] + other.rows[i][j] for j in range(self.num_columns )]
            for i in range(self.num_rows )
        ] )


 def __sub__(      self							:	Union[str, Any]			,       __lowerCamelCase							:	Matrix ):
    if self.order != other.order:
       raise ValueError('''Subtraction requires matrices of the same order''' )
    return Matrix(
        [
            [self.rows[i][j] - other.rows[i][j] for j in range(self.num_columns )]
            for i in range(self.num_rows )
        ] )


 def __mul__(      self							:	Any			,       __lowerCamelCase							:	Matrix | int | float ):
    if isinstance(__lowerCamelCase			,       (int, float) ):
       return Matrix(
           [[int(element * other ) for element in row] for row in self.rows] )
    elif isinstance(__lowerCamelCase			,       __lowerCamelCase ):
       if self.num_columns != other.num_rows:
          raise ValueError(
              '''The number of columns in the first matrix must '''
              '''be equal to the number of rows in the second''' )
       return Matrix(
           [
               [Matrix.dot_product(__lowerCamelCase			,       __lowerCamelCase ) for column in other.columns()]
               for row in self.rows
           ] )
    else:
       raise TypeError(
           '''A Matrix can only be multiplied by an int, float, or another matrix''' )


 def __pow__(      self							:	str			,       __lowerCamelCase							:	int ):
    if not isinstance(__lowerCamelCase			,       __lowerCamelCase ):
       raise TypeError('''A Matrix can only be raised to the power of an int''' )
    if not self.is_square:
       raise ValueError('''Only square matrices can be raised to a power''' )
    if other == 0:
       return self.identity()
    if other < 0:
       if self.is_invertable():
          return self.inverse() ** (-other)
       raise ValueError(
           '''Only invertable matrices can be raised to a negative power''' )
    UpperCAmelCase__	:str      =      self
    for _ in range(other - 1 ):
       result *= self
    return result





 @classmethod
 def        __SCREAMING_SNAKE_CASE					(      cls							:	List[str]			,       __lowerCamelCase							:	list[int]			,       __lowerCamelCase							:	list[int] ):
    return sum(row[i] * column[i] for i in range(len(__lowerCamelCase ) ) )


if __name__ == "__main__":
    import doctest

    doctest.testmod()







'''simple docstring'''





from multiprocessing import Lock, Pipe, Process

# lock used to ensure that two processes do not access a pipe at the same time
__lowerCamelCase												=						Lock()


def        a__     (					UpperCamelCase_						:      str,   UpperCamelCase_						:      Any,   UpperCamelCase_						:      Any,   UpperCamelCase_						:      int,   UpperCamelCase_						:      Union[str, Any],   UpperCamelCase_						:      List[str],   UpperCamelCase_						:      Optional[int]						):
   global process_lock

   # we perform n swaps since after n swaps we know we are sorted
   # we *could* stop early if we are sorted already, but it takes as long to
   # find out we are sorted as it does to sort the list with this algorithm
   for i in range(0,   10						):
      if (i + position) % 2 == 0 and r_send is not None:
         # send your value to your right neighbor
         process_lock.acquire()
         r_send[1].send(UpperCamelCase_						)
         process_lock.release()

         # receive your right neighbor's value
         process_lock.acquire()
         UpperCAmelCase__	:Union[str, Any]      =      rr_cv[0].recv()
         process_lock.release()

         # take the lower value since you are on the left
         UpperCAmelCase__	:List[Any]      =      min(UpperCamelCase_,   UpperCamelCase_						)
      elif (i + position) % 2 != 0 and l_send is not None:
         # send your value to your left neighbor
         process_lock.acquire()
         l_send[1].send(UpperCamelCase_						)
         process_lock.release()

         # receive your left neighbor's value
         process_lock.acquire()
         UpperCAmelCase__	:List[str]      =      lr_cv[0].recv()
         process_lock.release()

         # take the higher value since you are on the right
         UpperCAmelCase__	:List[Any]      =      max(UpperCamelCase_,   UpperCamelCase_						)
    # after all swaps are performed, send the values back to main
   result_pipe[1].send(UpperCamelCase_						)


def        a__     (					UpperCamelCase_						:      int						):
   UpperCAmelCase__	:List[str]      =      []
   UpperCAmelCase__	:Any      =      []
   # initialize the list of pipes where the values will be retrieved
   for _ in arr:
      result_pipe.append(Pipe()						)
   # creates the processes
   # the first and last process only have one neighbor so they are made outside
   # of the loop
   UpperCAmelCase__	:str      =      Pipe()
   UpperCAmelCase__	:Dict      =      Pipe()
   process_array_.append(
       Process(
           target=UpperCamelCase_,   args=(0, arr[0], None, temp_rs, None, temp_rr, result_pipe[0]),   )						)
   UpperCAmelCase__	:Optional[Any]      =      temp_rs
   UpperCAmelCase__	:Any      =      temp_rr

   for i in range(1,   len(UpperCamelCase_						) - 1						):
      UpperCAmelCase__	:Optional[int]      =      Pipe()
      UpperCAmelCase__	:List[str]      =      Pipe()
      process_array_.append(
          Process(
              target=UpperCamelCase_,   args=(i, arr[i], temp_ls, temp_rs, temp_lr, temp_rr, result_pipe[i]),   )						)
      UpperCAmelCase__	:Optional[Any]      =      temp_rs
      UpperCAmelCase__	:str      =      temp_rr

   process_array_.append(
       Process(
           target=UpperCamelCase_,   args=(
               len(UpperCamelCase_						) - 1,
               arr[len(UpperCamelCase_						) - 1],
               temp_ls,
               None,
               temp_lr,
               None,
               result_pipe[len(UpperCamelCase_						) - 1],
           ),   )						)

   # start the processes
   for p in process_array_:
      p.start()

   # wait for the processes to end and write their values to the list
   for p in range(0,   len(UpperCamelCase_						)						):
      UpperCAmelCase__	:List[str]      =      result_pipe[p][0].recv()
      process_array_[p].join()
   return arr


def        a__     (					):
   UpperCAmelCase__	:Optional[Any]      =      list(range(10,   0,   -1						)						)
   print('''Initial List'''						)
   print(*UpperCamelCase_						)
   UpperCAmelCase__	:str      =      odd_even_transposition(UpperCamelCase_						)
   print('''Sorted List\n'''						)
   print(*UpperCamelCase_						)


if __name__ == "__main__":
    main()



