



from __future__ import annotations

import json

import requests
from bsa import BeautifulSoup
from fake_useragent import UserAgent

_lowerCAmelCase	:   List[str]    =   {"UserAgent": UserAgent().random}







def     UpperCAmelCase_		(					snake_case__					)	->     dict:



				"""simple docstring"""





				lowerCAmelCase__		  =  script.contents[0]
				lowerCAmelCase__		  =  json.loads(data[data.find('{"config"'					) : -1]					)
				return info["entry_data"]["ProfilePage"][0]["graphql"]["user"]


class 	__snake_case   :
		def __init__(							self    ,a_						):







						"""simple docstring"""
						lowerCAmelCase__		  =  f'https://www.instagram.com/{username}/'
						lowerCAmelCase__		  =  self.get_json()
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						lowerCAmelCase__		  =  requests.get(self.url    ,headers=a_						).text
						lowerCAmelCase__		  =  BeautifulSoup(a_    ,'html.parser'						).find_all('script'						)
						try:
										return extract_user_profile(scripts[4]						)
						except (json.decoder.JSONDecodeError, KeyError):
										return extract_user_profile(scripts[3]						)
		def __repr__(							self						):







						"""simple docstring"""
						return f'{self.__class__.__name__}(\'{self.username}\')'
		def __str__(							self						):







						"""simple docstring"""
						return f'{self.fullname} ({self.username}) is {self.biography}'
		@property
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						return self.user_data["username"]
		@property
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						return self.user_data["full_name"]
		@property
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						return self.user_data["biography"]
		@property
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						return self.user_data["business_email"]
		@property
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						return self.user_data["external_url"]
		@property
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						return self.user_data["edge_followed_by"]["count"]
		@property
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						return self.user_data["edge_follow"]["count"]
		@property
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						return self.user_data["edge_owner_to_timeline_media"]["count"]
		@property
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						return self.user_data["profile_pic_url_hd"]
		@property
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						return self.user_data["is_verified"]



		@property
		def 						SCREAMING_SNAKE_CASE_					(							self						):







						"""simple docstring"""
						return self.user_data["is_private"]







def     UpperCAmelCase_		(					snake_case__ = "github"					)	->     None:



				"""simple docstring"""





				import os

				if os.environ.get('CI'					):
								return  # test failing on GitHub Actions
				lowerCAmelCase__		  =  InstagramUser(snake_case__					)
				assert instagram_user.user_data
				assert isinstance(instagram_user.user_data    ,			snake_case__					)
				assert instagram_user.username == username
				if username != "github":
								return
				assert instagram_user.fullname == "GitHub"
				assert instagram_user.biography == "Built for developers."
				assert instagram_user.number_of_posts > 150
				assert instagram_user.number_of_followers > 120000
				assert instagram_user.number_of_followings > 15
				assert instagram_user.email == "support@github.com"
				assert instagram_user.website == "https://github.com/readme"
				assert instagram_user.profile_picture_url.startswith('https://instagram.'					)
				assert instagram_user.is_verified is True
				assert instagram_user.is_private is False


if __name__ == "__main__":
	import doctest

	doctest.testmod()
	_lowerCAmelCase	:   Optional[int]    =   InstagramUser("github")
	print(instagram_user)
	print(f"""{instagram_user.number_of_posts = }""")
	print(f"""{instagram_user.number_of_followers = }""")
	print(f"""{instagram_user.number_of_followings = }""")
	print(f"""{instagram_user.email = }""")
	print(f"""{instagram_user.website = }""")
	print(f"""{instagram_user.profile_picture_url = }""")
	print(f"""{instagram_user.is_verified = }""")
	print(f"""{instagram_user.is_private = }""")





import numpy as np







def     UpperCAmelCase_		(					snake_case__    ,			snake_case__    ,			snake_case__ = 1E-12    ,			snake_case__ = 100    ,			)	->     tuple[float, np.ndarray]:



				"""simple docstring"""





				assert np.shape(snake_case__					)[0] == np.shape(snake_case__					)[1]
				# Ensure proper dimensionality.
				assert np.shape(snake_case__					)[0] == np.shape(snake_case__					)[0]
				# Ensure inputs are either both complex or both real
				assert np.iscomplexobj(snake_case__					) == np.iscomplexobj(snake_case__					)
				lowerCAmelCase__		  =  np.iscomplexobj(snake_case__					)
				if is_complex:
								# Ensure complex input_matrix is Hermitian
								assert np.array_equal(snake_case__    ,			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__		  =  False
				lowerCAmelCase__		  =  0
				lowerCAmelCase__		  =  0
				lowerCAmelCase__		  =  1E12

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

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

								if error <= error_tol or iterations >= max_iterations:
												lowerCAmelCase__		  =  True

								lowerCAmelCase__		  =  lambda_

				if is_complex:
								lowerCAmelCase__		  =  np.real(lambda_					)

				return lambda_, vector







def     UpperCAmelCase_		(					)	->     None:



				"""simple docstring"""





				lowerCAmelCase__		  =  np.array([[41, 4, 20], [4, 26, 30], [20, 30, 50]]					)
				lowerCAmelCase__		  =  np.array([41, 4, 20]					)
				lowerCAmelCase__		  =  real_input_matrix.astype(np.complexaaa					)
				lowerCAmelCase__		  =  np.triu(1j * complex_input_matrix    ,			1					)
				complex_input_matrix += imag_matrix
				complex_input_matrix += -1 * imag_matrix.T
				lowerCAmelCase__		  =  np.array([41, 4, 20]					).astype(np.complexaaa					)

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

								# Our implementation.
								lowerCAmelCase__  ,   lowerCAmelCase__		  =  power_iteration(snake_case__    ,			snake_case__					)

								# Numpy implementation.

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


if __name__ == "__main__":
	import doctest

	doctest.testmod()
	test_power_iteration()
