import unittest
from dataclasses import dataclass
from typing import List, Union

import numpy as np
import PIL.Image

from diffusers.utils.outputs import BaseOutput



@dataclass
class    lowercase_    (     __snake_case		):
							_lowerCamelCase						=		42




class    lowercase_    (     unittest.TestCase		):



							def        UpperCamelCase       (						self				):
													_snake_case						:     int				=    CustomOutput(images=np.random.rand(1      ,				3      ,				4      ,				4				)				)

													# check every way of getting the attribute
													assert isinstance(outputs.images      ,				np.ndarray				)
													assert outputs.images.shape == (1, 3, 4, 4)
													assert isinstance(outputs["images"]      ,				np.ndarray				)
													assert outputs["images"].shape == (1, 3, 4, 4)
													assert isinstance(outputs[0]      ,				np.ndarray				)
													assert outputs[0].shape == (1, 3, 4, 4)

													# test with a non-tensor attribute
													_snake_case						:     List[str]				=    CustomOutput(images=[PIL.Image.new("RGB"      ,				(4, 4)				)]				)

													# check every way of getting the attribute
													assert isinstance(outputs.images      ,				lowercase_				)
													assert isinstance(outputs.images[0]      ,				PIL.Image.Image				)
													assert isinstance(outputs["images"]      ,				lowercase_				)
													assert isinstance(outputs["images"][0]      ,				PIL.Image.Image				)
													assert isinstance(outputs[0]      ,				lowercase_				)
													assert isinstance(outputs[0][0]      ,				PIL.Image.Image				)



							def        UpperCamelCase       (						self				):
													# test output reinitialization with a `dict` for compatibility with `accelerate`
													_snake_case						:     Optional[Any]				=    CustomOutput({"images": np.random.rand(1      ,				3      ,				4      ,				4				)}				)

													# check every way of getting the attribute
													assert isinstance(outputs.images      ,				np.ndarray				)
													assert outputs.images.shape == (1, 3, 4, 4)
													assert isinstance(outputs["images"]      ,				np.ndarray				)
													assert outputs["images"].shape == (1, 3, 4, 4)
													assert isinstance(outputs[0]      ,				np.ndarray				)
													assert outputs[0].shape == (1, 3, 4, 4)

													# test with a non-tensor attribute
													_snake_case						:     Tuple				=    CustomOutput({"images": [PIL.Image.new("RGB"      ,				(4, 4)				)]}				)

													# check every way of getting the attribute
													assert isinstance(outputs.images      ,				lowercase_				)
													assert isinstance(outputs.images[0]      ,				PIL.Image.Image				)
													assert isinstance(outputs["images"]      ,				lowercase_				)
													assert isinstance(outputs["images"][0]      ,				PIL.Image.Image				)
													assert isinstance(outputs[0]      ,				lowercase_				)
													assert isinstance(outputs[0][0]      ,				PIL.Image.Image				)





def 							_UpperCAmelCase     (UpperCamelCase_       :       int					,			UpperCamelCase_       :       Optional[int]				):
				'''simple docstring'''
				_lowerCAmelCase			:			Dict        =					len(UpperCamelCase_				)
				# Create a stack and push index of fist element to it
				_lowerCAmelCase			:			Tuple        =					[]
				st.append(0				)

				# Span value of first element is always 1
				_lowerCAmelCase			:			List[Any]        =					1

				# Calculate span values for rest of the elements
				for i in range(1					,			UpperCamelCase_				):
								# Pop elements from stack while stack is not
								# empty and top of stack is smaller than price[i]
								while len(UpperCamelCase_				) > 0 and price[st[0]] <= price[i]:
												st.pop()

								# If stack becomes empty, then price[i] is greater
								# than all elements on left of it, i.e. price[0],
								# price[1], ..price[i-1]. Else the price[i]  is
								# greater than elements after top of stack
								_lowerCAmelCase			:			Union[str, Any]        =					i + 1 if len(UpperCamelCase_				) <= 0 else (i - st[0])

								# Push this element to stack
								st.append(UpperCamelCase_				)




def 							_UpperCAmelCase     (UpperCamelCase_       :       Dict					,			UpperCamelCase_       :       Union[str, Any]				):
				'''simple docstring'''
				for i in range(0					,			UpperCamelCase_				):
								print(arr[i]					,			end=""" """				)


# Driver program to test above function
_lowerCamelCase					:     Union[str, Any]					  =  [1_0, 4, 5, 9_0, 1_2_0, 8_0]
_lowerCamelCase					:     List[Any]					  =  [0 for i in range(len(price) + 1)]

# Fill the span values in array S[]
calculation_span(price, S)





print_array(S, len(price))

