






'''simple docstring'''




# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import torch

from accelerate import PartialState
from accelerate.utils.operations import broadcast, gather, gather_object, pad_across_processes, reduce







def       __UpperCAmelCase						(  lowerCamelCase_)							->     Any:
		return (torch.arange(state.num_processes) + 1.0 + (state.num_processes * state.process_index)).to(state.device)







def       __UpperCAmelCase						(  lowerCamelCase_)							->     Optional[Any]:
		UpperCamelCase__				:					Optional[int]					=					create_tensor(lowerCamelCase_)
		UpperCamelCase__				:					List[Any]					=					gather(lowerCamelCase_)
		assert gathered_tensor.tolist() == list(range(1     ,      state.num_processes**2 + 1))







def       __UpperCAmelCase						(  lowerCamelCase_)							->     Dict:
		UpperCamelCase__				:					Dict					=					[state.process_index]
		UpperCamelCase__				:					Any					=					gather_object(lowerCamelCase_)
		assert len(lowerCamelCase_) == state.num_processes, f'{gathered_obj}, {len(lowerCamelCase_)} != {state.num_processes}'
		assert gathered_obj == list(range(state.num_processes)), f'{gathered_obj} != {list(range(state.num_processes))}'







def       __UpperCAmelCase						(  lowerCamelCase_)							->     int:
		UpperCamelCase__				:					Dict					=					create_tensor(lowerCamelCase_)
		UpperCamelCase__				:					Optional[Any]					=					broadcast(lowerCamelCase_)
		assert broadcasted_tensor.shape == torch.Size([state.num_processes])
		assert broadcasted_tensor.tolist() == list(range(1     ,      state.num_processes + 1))







def       __UpperCAmelCase						(  lowerCamelCase_)							->     str:
		# We need to pad the tensor with one more element if we are the main process
		# to ensure that we can pad
		if state.is_main_process:
				UpperCamelCase__				:					Optional[Any]					=					torch.arange(state.num_processes + 1).to(state.device)
		else:
				UpperCamelCase__				:					Any					=					torch.arange(state.num_processes).to(state.device)
		UpperCamelCase__				:					int					=					pad_across_processes(lowerCamelCase_)
		assert padded_tensor.shape == torch.Size([state.num_processes + 1])
		if not state.is_main_process:
				assert padded_tensor.tolist() == list(range(0     ,      state.num_processes)) + [0]







def       __UpperCAmelCase						(  lowerCamelCase_)							->     int:
		# For now runs on only two processes
		if state.num_processes != 2:
				return
		UpperCamelCase__				:					Dict					=					create_tensor(lowerCamelCase_)
		UpperCamelCase__				:					int					=					reduce(lowerCamelCase_     ,      'sum')
		UpperCamelCase__				:					Tuple					=					torch.tensor([4.0, 6]).to(state.device)
		assert torch.allclose(lowerCamelCase_     ,      lowerCamelCase_), f'{reduced_tensor} != {truth_tensor}'







def       __UpperCAmelCase						(  lowerCamelCase_)							->     Any:
		# For now runs on only two processes
		if state.num_processes != 2:
				return
		UpperCamelCase__				:					List[str]					=					create_tensor(lowerCamelCase_)
		UpperCamelCase__				:					List[str]					=					reduce(lowerCamelCase_     ,      'mean')
		UpperCamelCase__				:					List[Any]					=					torch.tensor([2.0, 3]).to(state.device)
		assert torch.allclose(lowerCamelCase_     ,      lowerCamelCase_), f'{reduced_tensor} != {truth_tensor}'







def       __UpperCAmelCase						(  lowerCamelCase_)							->     Any:
		# For xla_spawn (TPUs)
		main()







def       __UpperCAmelCase						(  )							->     Union[str, Any]:
		UpperCamelCase__				:					Any					=					PartialState()
		state.print(f'State: {state}')
		state.print('testing gather')
		test_gather(lowerCamelCase_)
		state.print('testing gather_object')
		test_gather_object(lowerCamelCase_)
		state.print('testing broadcast')
		test_broadcast(lowerCamelCase_)
		state.print('testing pad_across_processes')
		test_pad_across_processes(lowerCamelCase_)
		state.print('testing reduce_sum')
		test_reduce_sum(lowerCamelCase_)
		state.print('testing reduce_mean')
		test_reduce_mean(lowerCamelCase_)


if __name__ == "__main__":
		main()












'''simple docstring'''




import requests
from bsa import BeautifulSoup







def       __UpperCAmelCase						(  lowerCamelCase_ = "AAPL")							->     str:
		UpperCamelCase__				:					str					=					f'https://in.finance.yahoo.com/quote/{symbol}?s={symbol}'
		UpperCamelCase__				:					Optional[Any]					=					BeautifulSoup(requests.get(lowerCamelCase_).text     ,      'html.parser')
		UpperCamelCase__				:					Union[str, Any]					=					'My(6px) Pos(r) smartphone_Mt(6px)'
		return soup.find('div'     ,      class_=class_).find('span').text


if __name__ == "__main__":
		for symbol in "AAPL AMZN IBM GOOG MSFT ORCL".split():
				print(f'''Current {symbol:<4} stock price is {stock_price(symbol):>8}''')




