


import numpy as np


def        _UpperCamelCase							(      lowercase__    ,       lowercase__    ,       lowercase__ = 1e-12    ,       lowercase__ = 100    ,       ):
						assert np.shape(lowercase__      )[0] == np.shape(lowercase__      )[1]
						# Ensure proper dimensionality.
						assert np.shape(lowercase__      )[0] == np.shape(lowercase__      )[0]
						# Ensure inputs are either both complex or both real
						assert np.iscomplexobj(lowercase__      ) == np.iscomplexobj(lowercase__      )
						__SCREAMING_SNAKE_CASE						:     Optional[int]					=		np.iscomplexobj(lowercase__      )
						if is_complex:
												# Ensure complex input_matrix is Hermitian
												assert np.array_equal(lowercase__    ,       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.

						__SCREAMING_SNAKE_CASE						:     Dict					=		False
						__SCREAMING_SNAKE_CASE						:     Optional[int]					=		0
						__SCREAMING_SNAKE_CASE						:     Any					=		0
						__SCREAMING_SNAKE_CASE						:     Dict					=		1e12

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

												# Check convergence.
												__SCREAMING_SNAKE_CASE						:     int					=		np.abs(lambda_ - lambda_previous      ) / lambda_
												iterations += 1

												if error <= error_tol or iterations >= max_iterations:
																		__SCREAMING_SNAKE_CASE						:     Optional[Any]					=		True

												__SCREAMING_SNAKE_CASE						:     Tuple					=		lambda_

						if is_complex:
												__SCREAMING_SNAKE_CASE						:     Tuple					=		np.real(lambda_      )

						return lambda_, vector


def        _UpperCamelCase							(      ):
						__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		np.array([[41, 4, 20], [4, 26, 30], [20, 30, 50]]      )
						__SCREAMING_SNAKE_CASE						:     Tuple					=		np.array([41, 4, 20]      )
						__SCREAMING_SNAKE_CASE						:     Tuple					=		real_input_matrix.astype(np.complexaaa      )
						__SCREAMING_SNAKE_CASE						:     str					=		np.triu(1J * complex_input_matrix    ,       1      )
						complex_input_matrix += imag_matrix
						complex_input_matrix += -1 * imag_matrix.T
						__SCREAMING_SNAKE_CASE						:     Union[str, Any]					=		np.array([41, 4, 20]      ).astype(np.complexaaa      )

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

												# Our implementation.
												__SCREAMING_SNAKE_CASE			,			__SCREAMING_SNAKE_CASE						:     int					=		power_iteration(lowercase__    ,       lowercase__      )

												# Numpy implementation.

												# Get eigenvalues and eigenvectors using built-in numpy
												# eigh (eigh used for symmetric or hermetian matrices).
												__SCREAMING_SNAKE_CASE			,			__SCREAMING_SNAKE_CASE						:     Optional[int]					=		np.linalg.eigh(lowercase__      )
												# Last eigenvalue is the maximum one.
												__SCREAMING_SNAKE_CASE						:     List[str]					=		eigen_values[-1]
												# Last column in this matrix is eigenvector corresponding to largest eigenvalue.
												__SCREAMING_SNAKE_CASE						:     Optional[int]					=		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(lowercase__      ) - np.abs(lowercase__      )      ) <= 1e-6


if __name__ == "__main__":
						import doctest

						doctest.testmod()
						test_power_iteration()




from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_speech_available,
    is_tf_available,
    is_torch_available,
)


SCREAMING_SNAKE_CASE       :      List[str]												= {
    "configuration_speech_to_text": ["SPEECH_TO_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP", "Speech2TextConfig"],
    "processing_speech_to_text": ["Speech2TextProcessor"],
}

try:
 if not is_sentencepiece_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 SCREAMING_SNAKE_CASE       :      Union[str, Any]												= ["Speech2TextTokenizer"]

try:
 if not is_speech_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 SCREAMING_SNAKE_CASE       :      int												= ["Speech2TextFeatureExtractor"]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 SCREAMING_SNAKE_CASE       :      Optional[Any]												= [
     "TF_SPEECH_TO_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST",
     "TFSpeech2TextForConditionalGeneration",
     "TFSpeech2TextModel",
     "TFSpeech2TextPreTrainedModel",
 ]

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 SCREAMING_SNAKE_CASE       :      str												= [
     "SPEECH_TO_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST",
     "Speech2TextForConditionalGeneration",
     "Speech2TextModel",
     "Speech2TextPreTrainedModel",
 ]


if TYPE_CHECKING:
 from .configuration_speech_to_text import SPEECH_TO_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP, SpeechaTextConfig
 from .processing_speech_to_text import SpeechaTextProcessor

 try:
  if not is_sentencepiece_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .tokenization_speech_to_text import SpeechaTextTokenizer

 try:
  if not is_speech_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .feature_extraction_speech_to_text import SpeechaTextFeatureExtractor

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_speech_to_text import (
      TF_SPEECH_TO_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFSpeechaTextForConditionalGeneration,
      TFSpeechaTextModel,
      TFSpeechaTextPreTrainedModel,
  )

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_speech_to_text import (
      SPEECH_TO_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST,
      SpeechaTextForConditionalGeneration,
      SpeechaTextModel,
      SpeechaTextPreTrainedModel,
  )

else:
 import sys

 SCREAMING_SNAKE_CASE       :      Optional[Any]												= _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)


