




import numpy as np



def      __lowerCAmelCase			(					UpperCamelCase	,      UpperCamelCase	,      UpperCamelCase = 1E-12	,      UpperCamelCase = 100	,      )     ->	tuple[float, np.ndarray]:
  assert np.shape(UpperCamelCase      )[0] == np.shape(UpperCamelCase      )[1]
  # Ensure proper dimensionality.
  assert np.shape(UpperCamelCase      )[0] == np.shape(UpperCamelCase      )[0]
  # Ensure inputs are either both complex or both real
  assert np.iscomplexobj(UpperCamelCase      ) == np.iscomplexobj(UpperCamelCase      )
  lowerCAmelCase__				:  Tuple		       =     np.iscomplexobj(UpperCamelCase      )
  if is_complex:
    # Ensure complex input_matrix is Hermitian
    assert np.array_equal(UpperCamelCase	,      input_matrix.conj().T      )

  # Set convergence to False. Will define convergence when we exceed max_iterations
  # or when we have small changes from one iteration to next.

  lowerCAmelCase__				:  Optional[Any]		       =     False
  lowerCAmelCase__				:  Dict		       =     0
  lowerCAmelCase__				:  List[str]		       =     0
  lowerCAmelCase__				:  Tuple		       =     1E12

  while not convergence:
    # Multiple matrix by the vector.
    lowerCAmelCase__				:  Union[str, Any]		       =     np.dot(UpperCamelCase	,      UpperCamelCase      )
    # Normalize the resulting output vector.
    lowerCAmelCase__				:  Tuple		       =     w / np.linalg.norm(UpperCamelCase      )
    # Find rayleigh quotient
    # (faster than usual b/c we know vector is normalized already)
    lowerCAmelCase__				:  Union[str, Any]		       =     vector.conj().T if is_complex else vector.T
    lowerCAmelCase__				:  str		       =     np.dot(UpperCamelCase	,      np.dot(UpperCamelCase	,      UpperCamelCase      )      )

    # Check convergence.
    lowerCAmelCase__				:  Optional[Any]		       =     np.abs(lambda_ - lambda_previous      ) / lambda_
    iterations += 1

    if error <= error_tol or iterations >= max_iterations:
      lowerCAmelCase__				:  Optional[int]		       =     True

    lowerCAmelCase__				:  List[str]		       =     lambda_

  if is_complex:
    lowerCAmelCase__				:  Union[str, Any]		       =     np.real(lambda_      )

  return lambda_, vector



def      __lowerCAmelCase			(					)     ->	None:
  lowerCAmelCase__				:  Union[str, Any]		       =     np.array([[41, 4, 20], [4, 26, 30], [20, 30, 50]]      )
  lowerCAmelCase__				:  Tuple		       =     np.array([41, 4, 20]      )
  lowerCAmelCase__				:  List[str]		       =     real_input_matrix.astype(np.complexaaa      )
  lowerCAmelCase__				:  List[str]		       =     np.triu(1j * complex_input_matrix	,      1      )
  complex_input_matrix += imag_matrix
  complex_input_matrix += -1 * imag_matrix.T
  lowerCAmelCase__				:  Dict		       =     np.array([41, 4, 20]      ).astype(np.complexaaa      )

  for problem_type in ["real", "complex"]:
    if problem_type == "real":
      lowerCAmelCase__				:  Optional[Any]		       =     real_input_matrix
      lowerCAmelCase__				:  List[str]		       =     real_vector
    elif problem_type == "complex":
      lowerCAmelCase__				:  str		       =     complex_input_matrix
      lowerCAmelCase__				:  List[str]		       =     complex_vector

    # Our implementation.
    lowerCAmelCase__       ,			lowerCAmelCase__				:  Optional[Any]		       =     power_iteration(UpperCamelCase	,      UpperCamelCase      )

    # Numpy implementation.

    # Get eigenvalues and eigenvectors using built-in numpy
    # eigh (eigh used for symmetric or hermetian matrices).
    lowerCAmelCase__       ,			lowerCAmelCase__				:  Optional[Any]		       =     np.linalg.eigh(UpperCamelCase      )
    # Last eigenvalue is the maximum one.
    lowerCAmelCase__				:  Union[str, Any]		       =     eigen_values[-1]
    # Last column in this matrix is eigenvector corresponding to largest eigenvalue.
    lowerCAmelCase__				:  Dict		       =     eigen_vectors[:, -1]

    # Check our implementation and numpy gives close answers.
    assert np.abs(eigen_value - eigen_value_max      ) <= 1E-6
    # Take absolute values element wise of each eigenvector.
    # as they are only unique to a minus sign.
    assert np.linalg.norm(np.abs(UpperCamelCase      ) - np.abs(UpperCamelCase      )      ) <= 1E-6


if __name__ == "__main__":
     import doctest

     doctest.testmod()
     test_power_iteration()







lowerCAmelCase_					    = 6_55_21



def      __lowerCAmelCase			(					UpperCamelCase      )     ->	int:
  lowerCAmelCase__				:  List[str]		       =     1
  lowerCAmelCase__				:  List[Any]		       =     0
  for plain_chr in plain_text:
    lowerCAmelCase__				:  Union[str, Any]		       =     (a + ord(UpperCamelCase      )) % MOD_ADLER
    lowerCAmelCase__				:  Optional[Any]		       =     (b + a) % MOD_ADLER
  return (b << 16) | a

