

'''simple docstring'''
import gc
import random
import tempfile
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import AutoencoderKL, DDIMScheduler, LMSDiscreteScheduler, PNDMScheduler, UNetaDConditionModel
from diffusers.pipelines.stable_diffusion_safe import StableDiffusionPipelineSafe as StableDiffusionPipeline
from diffusers.utils import floats_tensor, nightly, torch_device
from diffusers.utils.testing_utils import require_torch_gpu


class        a__  (							unittest.TestCase  ):


   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      super().tearDown()
      gc.collect()
      torch.cuda.empty_cache()


   @property
   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      _lowercase      :				Tuple      					=       1
      _lowercase      :				Optional[Any]      					=       3
      _lowercase      :				int      					=       (32, 32)

      _lowercase      :				Optional[int]      					=       floats_tensor((batch_size, num_channels) + sizes      ,    rng=random.Random(0  )  ).to(_UpperCamelCase  )
      return image


   @property
   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      torch.manual_seed(0  )
      _lowercase      :				Tuple      					=       UNetaDConditionModel(
          block_out_channels=(32, 64)      ,    layers_per_block=2      ,    sample_size=32      ,    in_channels=4      ,    out_channels=4      ,    down_block_types=("DownBlock2D", "CrossAttnDownBlock2D")      ,    up_block_types=("CrossAttnUpBlock2D", "UpBlock2D")      ,    cross_attention_dim=32      ,    )
      return model


   @property
   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      torch.manual_seed(0  )
      _lowercase      :				Union[str, Any]      					=       AutoencoderKL(
          block_out_channels=[32, 64]      ,    in_channels=3      ,    out_channels=3      ,    down_block_types=["DownEncoderBlock2D", "DownEncoderBlock2D"]      ,    up_block_types=["UpDecoderBlock2D", "UpDecoderBlock2D"]      ,    latent_channels=4      ,    )
      return model


   @property
   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      torch.manual_seed(0  )
      _lowercase      :				List[str]      					=       CLIPTextConfig(
          bos_token_id=0      ,    eos_token_id=2      ,    hidden_size=32      ,    intermediate_size=37      ,    layer_norm_eps=1E-0_5      ,    num_attention_heads=4      ,    num_hidden_layers=5      ,    pad_token_id=1      ,    vocab_size=1000      ,    )
      return CLIPTextModel(_UpperCamelCase  )


   @property
   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      def extract(*_UpperCamelCase      ,    **_UpperCamelCase  ):


         class        a__  :


            def __init__(			self  ):





               """simple docstring"""





               _lowercase      :				Any      					=       torch.ones([0]  )






            def 						_lowerCamelCase       (			self      ,    _UpperCamelCase  ):





               """simple docstring"""





               self.pixel_values.to(_UpperCamelCase  )
               return self




         return Out()

      return extract


   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      _lowercase      :				Tuple      					=       "cpu"  # ensure determinism for the device-dependent torch.Generator
      _lowercase      :				Dict      					=       self.dummy_cond_unet
      _lowercase      :				Dict      					=       DDIMScheduler(
          beta_start=0.0_0_0_8_5      ,    beta_end=0.0_1_2      ,    beta_schedule="scaled_linear"      ,    clip_sample=_UpperCamelCase      ,    set_alpha_to_one=_UpperCamelCase      ,    )

      _lowercase      :				str      					=       self.dummy_vae
      _lowercase      :				Dict      					=       self.dummy_text_encoder
      _lowercase      :				Optional[int]      					=       CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip"  )

      # make sure here that pndm scheduler skips prk
      _lowercase      :				str      					=       StableDiffusionPipeline(
          unet=_UpperCamelCase      ,    scheduler=_UpperCamelCase      ,    vae=_UpperCamelCase      ,    text_encoder=_UpperCamelCase      ,    tokenizer=_UpperCamelCase      ,    safety_checker=_UpperCamelCase      ,    feature_extractor=self.dummy_extractor      ,    )
      _lowercase      :				str      					=       sd_pipe.to(_UpperCamelCase  )
      sd_pipe.set_progress_bar_config(disable=_UpperCamelCase  )

      _lowercase      :				Any      					=       "A painting of a squirrel eating a burger"

      _lowercase      :				Tuple      					=       torch.Generator(device=_UpperCamelCase  ).manual_seed(0  )
      _lowercase      :				Union[str, Any]      					=       sd_pipe([prompt]      ,    generator=_UpperCamelCase      ,    guidance_scale=6.0      ,    num_inference_steps=2      ,    output_type="np"  )
      _lowercase      :				Any      					=       output.images

      _lowercase      :				List[str]      					=       torch.Generator(device=_UpperCamelCase  ).manual_seed(0  )
      _lowercase      :				Tuple      					=       sd_pipe(
          [prompt]      ,    generator=_UpperCamelCase      ,    guidance_scale=6.0      ,    num_inference_steps=2      ,    output_type="np"      ,    return_dict=_UpperCamelCase      ,    )[0]

      _lowercase      :				int      					=       image[0, -3:, -3:, -1]
      _lowercase      :				List[Any]      					=       image_from_tuple[0, -3:, -3:, -1]

      assert image.shape == (1, 64, 64, 3)
      _lowercase      :				List[Any]      					=       np.array([0.5_7_5_6, 0.6_1_1_8, 0.5_0_0_5, 0.5_0_4_1, 0.5_4_7_1, 0.4_7_2_6, 0.4_9_7_6, 0.4_8_6_5, 0.4_8_6_4]  )

      assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1E-2
      assert np.abs(image_from_tuple_slice.flatten() - expected_slice  ).max() < 1E-2


   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      _lowercase      :				List[Any]      					=       "cpu"  # ensure determinism for the device-dependent torch.Generator
      _lowercase      :				Optional[int]      					=       self.dummy_cond_unet
      _lowercase      :				Optional[Any]      					=       PNDMScheduler(skip_prk_steps=_UpperCamelCase  )
      _lowercase      :				int      					=       self.dummy_vae
      _lowercase      :				Tuple      					=       self.dummy_text_encoder
      _lowercase      :				int      					=       CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip"  )

      # make sure here that pndm scheduler skips prk
      _lowercase      :				Tuple      					=       StableDiffusionPipeline(
          unet=_UpperCamelCase      ,    scheduler=_UpperCamelCase      ,    vae=_UpperCamelCase      ,    text_encoder=_UpperCamelCase      ,    tokenizer=_UpperCamelCase      ,    safety_checker=_UpperCamelCase      ,    feature_extractor=self.dummy_extractor      ,    )
      _lowercase      :				str      					=       sd_pipe.to(_UpperCamelCase  )
      sd_pipe.set_progress_bar_config(disable=_UpperCamelCase  )

      _lowercase      :				List[str]      					=       "A painting of a squirrel eating a burger"
      _lowercase      :				List[str]      					=       torch.Generator(device=_UpperCamelCase  ).manual_seed(0  )
      _lowercase      :				int      					=       sd_pipe([prompt]      ,    generator=_UpperCamelCase      ,    guidance_scale=6.0      ,    num_inference_steps=2      ,    output_type="np"  )

      _lowercase      :				List[Any]      					=       output.images

      _lowercase      :				Optional[int]      					=       torch.Generator(device=_UpperCamelCase  ).manual_seed(0  )
      _lowercase      :				int      					=       sd_pipe(
          [prompt]      ,    generator=_UpperCamelCase      ,    guidance_scale=6.0      ,    num_inference_steps=2      ,    output_type="np"      ,    return_dict=_UpperCamelCase      ,    )[0]

      _lowercase      :				Any      					=       image[0, -3:, -3:, -1]
      _lowercase      :				int      					=       image_from_tuple[0, -3:, -3:, -1]

      assert image.shape == (1, 64, 64, 3)
      _lowercase      :				Any      					=       np.array([0.5_1_2_5, 0.5_7_1_6, 0.4_8_2_8, 0.5_0_6_0, 0.5_6_5_0, 0.4_7_6_8, 0.5_1_8_5, 0.4_8_9_5, 0.4_9_9_3]  )

      assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1E-2
      assert np.abs(image_from_tuple_slice.flatten() - expected_slice  ).max() < 1E-2


   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      _lowercase      :				Optional[Any]      					=       StableDiffusionPipeline.from_pretrained(
          "hf-internal-testing/tiny-stable-diffusion-lms-pipe"      ,    safety_checker=_UpperCamelCase  )
      assert isinstance(_UpperCamelCase      ,    _UpperCamelCase  )
      assert isinstance(pipe.scheduler      ,    _UpperCamelCase  )
      assert pipe.safety_checker is None

      _lowercase      :				Optional[int]      					=       pipe("example prompt"      ,    num_inference_steps=2  ).images[0]
      assert image is not None

      # check that there's no error when saving a pipeline with one of the models being None
      with tempfile.TemporaryDirectory() as tmpdirname:
         pipe.save_pretrained(_UpperCamelCase  )
         _lowercase      :				List[Any]      					=       StableDiffusionPipeline.from_pretrained(_UpperCamelCase  )

      # sanity check that the pipeline still works
      assert pipe.safety_checker is None
      _lowercase      :				Tuple      					=       pipe("example prompt"      ,    num_inference_steps=2  ).images[0]
      assert image is not None






   @unittest.skipIf(torch_device != "cuda"      ,    "This test requires a GPU"  )
   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      _lowercase      :				Optional[int]      					=       self.dummy_cond_unet
      _lowercase      :				Union[str, Any]      					=       PNDMScheduler(skip_prk_steps=_UpperCamelCase  )
      _lowercase      :				Union[str, Any]      					=       self.dummy_vae
      _lowercase      :				List[str]      					=       self.dummy_text_encoder
      _lowercase      :				Union[str, Any]      					=       CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip"  )

      # put models in fp16
      _lowercase      :				Any      					=       unet.half()
      _lowercase      :				str      					=       vae.half()
      _lowercase      :				Any      					=       bert.half()

      # make sure here that pndm scheduler skips prk
      _lowercase      :				List[str]      					=       StableDiffusionPipeline(
          unet=_UpperCamelCase      ,    scheduler=_UpperCamelCase      ,    vae=_UpperCamelCase      ,    text_encoder=_UpperCamelCase      ,    tokenizer=_UpperCamelCase      ,    safety_checker=_UpperCamelCase      ,    feature_extractor=self.dummy_extractor      ,    )
      _lowercase      :				List[Any]      					=       sd_pipe.to(_UpperCamelCase  )
      sd_pipe.set_progress_bar_config(disable=_UpperCamelCase  )

      _lowercase      :				Any      					=       "A painting of a squirrel eating a burger"
      _lowercase      :				Any      					=       sd_pipe([prompt]      ,    num_inference_steps=2      ,    output_type="np"  ).images

      assert image.shape == (1, 64, 64, 3)




@nightly
@require_torch_gpu
class        a__  (							unittest.TestCase  ):


   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      super().tearDown()
      gc.collect()
      torch.cuda.empty_cache()


   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      _lowercase      :				Union[str, Any]      					=       StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5"      ,    safety_checker=_UpperCamelCase  )
      _lowercase      :				Optional[Any]      					=       LMSDiscreteScheduler.from_config(sd_pipe.scheduler.config  )
      _lowercase      :				Union[str, Any]      					=       sd_pipe.to(_UpperCamelCase  )
      sd_pipe.set_progress_bar_config(disable=_UpperCamelCase  )

      _lowercase      :				Any      					=       (
          "portrait of girl with smokey eyes makeup in abandoned hotel, grange clothes, redshift, wide high angle"
          " coloured polaroid photograph with flash, kodak film, hyper real, stunning moody cinematography, with"
          " anamorphic lenses, by maripol, fallen angels by wong kar - wai, style of suspiria and neon demon and"
          " children from bahnhof zoo, detailed "
      )
      _lowercase      :				Union[str, Any]      					=       4003660346
      _lowercase      :				Dict      					=       7

      # without safety guidance (sld_guidance_scale = 0)
      _lowercase      :				Union[str, Any]      					=       torch.manual_seed(_UpperCamelCase  )
      _lowercase      :				List[Any]      					=       sd_pipe(
          [prompt]      ,    generator=_UpperCamelCase      ,    guidance_scale=_UpperCamelCase      ,    num_inference_steps=50      ,    output_type="np"      ,    width=512      ,    height=512      ,    sld_guidance_scale=0      ,    )

      _lowercase      :				int      					=       output.images
      _lowercase      :				int      					=       image[0, -3:, -3:, -1]
      _lowercase      :				Tuple      					=       [0.2_2_7_8, 0.2_2_3_1, 0.2_2_4_9, 0.2_3_3_3, 0.2_3_0_3, 0.1_8_8_5, 0.2_2_7_3, 0.2_1_4_4, 0.2_1_7_6]

      assert image.shape == (1, 512, 512, 3)

      assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1E-2

      # without safety guidance (strong configuration)
      _lowercase      :				Any      					=       torch.manual_seed(_UpperCamelCase  )
      _lowercase      :				int      					=       sd_pipe(
          [prompt]      ,    generator=_UpperCamelCase      ,    guidance_scale=_UpperCamelCase      ,    num_inference_steps=50      ,    output_type="np"      ,    width=512      ,    height=512      ,    sld_guidance_scale=2000      ,    sld_warmup_steps=7      ,    sld_threshold=0.0_2_5      ,    sld_momentum_scale=0.5      ,    sld_mom_beta=0.7      ,    )

      _lowercase      :				Optional[Any]      					=       output.images
      _lowercase      :				List[str]      					=       image[0, -3:, -3:, -1]
      _lowercase      :				Optional[int]      					=       [0.2_3_8_3, 0.2_2_7_6, 0.2_3_6, 0.2_1_9_2, 0.2_1_8_6, 0.2_0_5_3, 0.1_9_7_1, 0.1_9_0_1, 0.1_7_1_9]

      assert image.shape == (1, 512, 512, 3)

      assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1E-2


   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      _lowercase      :				int      					=       StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5"      ,    safety_checker=_UpperCamelCase  )
      _lowercase      :				int      					=       LMSDiscreteScheduler.from_config(sd_pipe.scheduler.config  )
      _lowercase      :				int      					=       sd_pipe.to(_UpperCamelCase  )
      sd_pipe.set_progress_bar_config(disable=_UpperCamelCase  )

      _lowercase      :				Any      					=       "padme amidala taking a bath artwork, safe for work, no nudity"
      _lowercase      :				Tuple      					=       2734971755
      _lowercase      :				Union[str, Any]      					=       7

      _lowercase      :				str      					=       torch.manual_seed(_UpperCamelCase  )
      _lowercase      :				Optional[Any]      					=       sd_pipe(
          [prompt]      ,    generator=_UpperCamelCase      ,    guidance_scale=_UpperCamelCase      ,    num_inference_steps=50      ,    output_type="np"      ,    width=512      ,    height=512      ,    sld_guidance_scale=0      ,    )

      _lowercase      :				Optional[int]      					=       output.images
      _lowercase      :				List[Any]      					=       image[0, -3:, -3:, -1]
      _lowercase      :				Optional[Any]      					=       [0.3_5_0_2, 0.3_6_2_2, 0.3_3_9_6, 0.3_6_4_2, 0.3_4_7_8, 0.3_3_1_8, 0.3_5, 0.3_3_4_8, 0.3_2_9_7]

      assert image.shape == (1, 512, 512, 3)

      assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1E-2

      _lowercase      :				List[Any]      					=       torch.manual_seed(_UpperCamelCase  )
      _lowercase      :				Optional[Any]      					=       sd_pipe(
          [prompt]      ,    generator=_UpperCamelCase      ,    guidance_scale=_UpperCamelCase      ,    num_inference_steps=50      ,    output_type="np"      ,    width=512      ,    height=512      ,    sld_guidance_scale=2000      ,    sld_warmup_steps=7      ,    sld_threshold=0.0_2_5      ,    sld_momentum_scale=0.5      ,    sld_mom_beta=0.7      ,    )

      _lowercase      :				int      					=       output.images
      _lowercase      :				Any      					=       image[0, -3:, -3:, -1]
      _lowercase      :				str      					=       [0.5_5_3_1, 0.5_2_0_6, 0.4_8_9_5, 0.5_1_5_6, 0.5_1_8_2, 0.4_7_5_1, 0.4_8_0_2, 0.4_8_0_3, 0.4_4_4_3]

      assert image.shape == (1, 512, 512, 3)

      assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1E-2






   def 						_lowerCamelCase       (			self  ):





      """simple docstring"""





      _lowercase      :				Tuple      					=       StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5"  )
      _lowercase      :				int      					=       sd_pipe.to(_UpperCamelCase  )
      sd_pipe.set_progress_bar_config(disable=_UpperCamelCase  )

      _lowercase      :				int      					=       (
          "the four horsewomen of the apocalypse, painting by tom of finland, gaston bussiere, craig mullins, j. c."
          " leyendecker"
      )
      _lowercase      :				List[str]      					=       1044355234
      _lowercase      :				Tuple      					=       12

      _lowercase      :				Union[str, Any]      					=       torch.manual_seed(_UpperCamelCase  )
      _lowercase      :				List[str]      					=       sd_pipe(
          [prompt]      ,    generator=_UpperCamelCase      ,    guidance_scale=_UpperCamelCase      ,    num_inference_steps=50      ,    output_type="np"      ,    width=512      ,    height=512      ,    sld_guidance_scale=0      ,    )

      _lowercase      :				int      					=       output.images
      _lowercase      :				Any      					=       image[0, -3:, -3:, -1]
      _lowercase      :				Dict      					=       np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]  )

      assert image.shape == (1, 512, 512, 3)

      assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1E-7

      _lowercase      :				int      					=       torch.manual_seed(_UpperCamelCase  )
      _lowercase      :				Tuple      					=       sd_pipe(
          [prompt]      ,    generator=_UpperCamelCase      ,    guidance_scale=_UpperCamelCase      ,    num_inference_steps=50      ,    output_type="np"      ,    width=512      ,    height=512      ,    sld_guidance_scale=2000      ,    sld_warmup_steps=7      ,    sld_threshold=0.0_2_5      ,    sld_momentum_scale=0.5      ,    sld_mom_beta=0.7      ,    )

      _lowercase      :				int      					=       output.images
      _lowercase      :				str      					=       image[0, -3:, -3:, -1]
      _lowercase      :				Dict      					=       np.array([0.5_8_1_8, 0.6_2_8_5, 0.6_8_3_5, 0.6_0_1_9, 0.6_2_5, 0.6_7_5_4, 0.6_0_9_6, 0.6_3_3_4, 0.6_5_6_1]  )
      assert image.shape == (1, 512, 512, 3)

      assert np.abs(image_slice.flatten() - expected_slice  ).max() < 1E-2









'''simple docstring'''
from math import pi, sqrt, tan







def  _A		(     snake_case					)      ->     float:
   if side_length < 0:
      raise ValueError("surface_area_cube() only accepts non-negative values"					)
   return 6 * side_length**2







def  _A		(     snake_case		,							snake_case		,							snake_case					)      ->     float:
   if length < 0 or breadth < 0 or height < 0:
      raise ValueError("surface_area_cuboid() only accepts non-negative values"					)
   return 2 * ((length * breadth) + (breadth * height) + (length * height))







def  _A		(     snake_case					)      ->     float:
   if radius < 0:
      raise ValueError("surface_area_sphere() only accepts non-negative values"					)
   return 4 * pi * radius**2







def  _A		(     snake_case					)      ->     float:
   if radius < 0:
      raise ValueError("surface_area_hemisphere() only accepts non-negative values"					)
   return 3 * pi * radius**2







def  _A		(     snake_case		,							snake_case					)      ->     float:
   if radius < 0 or height < 0:
      raise ValueError("surface_area_cone() only accepts non-negative values"					)
   return pi * radius * (radius + (height**2 + radius**2) ** 0.5)







def  _A		(     snake_case		,							snake_case		,							snake_case					)      ->     float:
   if radius_a < 0 or radius_a < 0 or height < 0:
      raise ValueError(
          "surface_area_conical_frustum() only accepts non-negative values"					)
   _lowercase      :				Union[str, Any]      					=       (height**2 + (radius_a - radius_a) ** 2) ** 0.5
   return pi * ((slant_height * (radius_a + radius_a)) + radius_a**2 + radius_a**2)







def  _A		(     snake_case		,							snake_case					)      ->     float:
   if radius < 0 or height < 0:
      raise ValueError("surface_area_cylinder() only accepts non-negative values"					)
   return 2 * pi * radius * (height + radius)







def  _A		(     snake_case		,							snake_case					)      ->     float:
   if torus_radius < 0 or tube_radius < 0:
      raise ValueError("surface_area_torus() only accepts non-negative values"					)
   if torus_radius < tube_radius:
      raise ValueError(
          "surface_area_torus() does not support spindle or self intersecting tori"					)
   return 4 * pow(snake_case		,							2					) * torus_radius * tube_radius







def  _A		(     snake_case		,							snake_case					)      ->     float:
   if length < 0 or width < 0:
      raise ValueError("area_rectangle() only accepts non-negative values"					)
   return length * width







def  _A		(     snake_case					)      ->     float:
   if side_length < 0:
      raise ValueError("area_square() only accepts non-negative values"					)
   return side_length**2







def  _A		(     snake_case		,							snake_case					)      ->     float:
   if base < 0 or height < 0:
      raise ValueError("area_triangle() only accepts non-negative values"					)
   return (base * height) / 2







def  _A		(     snake_case		,							snake_case		,							snake_case					)      ->     float:
   if sidea < 0 or sidea < 0 or sidea < 0:
      raise ValueError("area_triangle_three_sides() only accepts non-negative values"					)
   elif sidea + sidea < sidea or sidea + sidea < sidea or sidea + sidea < sidea:
      raise ValueError("Given three sides do not form a triangle"					)
   _lowercase      :				Any      					=       (sidea + sidea + sidea) / 2
   _lowercase      :				List[str]      					=       sqrt(
       semi_perimeter
       * (semi_perimeter - sidea)
       * (semi_perimeter - sidea)
       * (semi_perimeter - sidea)					)
   return area







def  _A		(     snake_case		,							snake_case					)      ->     float:
   if base < 0 or height < 0:
      raise ValueError("area_parallelogram() only accepts non-negative values"					)
   return base * height







def  _A		(     snake_case		,							snake_case		,							snake_case					)      ->     float:
   if basea < 0 or basea < 0 or height < 0:
      raise ValueError("area_trapezium() only accepts non-negative values"					)
   return 1 / 2 * (basea + basea) * height







def  _A		(     snake_case					)      ->     float:
   if radius < 0:
      raise ValueError("area_circle() only accepts non-negative values"					)
   return pi * radius**2







def  _A		(     snake_case		,							snake_case					)      ->     float:
   if radius_x < 0 or radius_y < 0:
      raise ValueError("area_ellipse() only accepts non-negative values"					)
   return pi * radius_x * radius_y







def  _A		(     snake_case		,							snake_case					)      ->     float:
   if diagonal_a < 0 or diagonal_a < 0:
      raise ValueError("area_rhombus() only accepts non-negative values"					)
   return 1 / 2 * diagonal_a * diagonal_a







def  _A		(     snake_case		,							snake_case					)      ->     float:
   if not isinstance(snake_case		,							snake_case					) or sides < 3:
      raise ValueError(
          "area_reg_polygon() only accepts integers greater than or \
equal to three as number of sides"					)
   elif length < 0:
      raise ValueError(
          "area_reg_polygon() only accepts non-negative values as \
length of a side"					)
   return (sides * length**2) / (4 * tan(pi / sides					))
   return (sides * length**2) / (4 * tan(pi / sides					))


if __name__ == "__main__":
    import doctest

    doctest.testmod(verbose=True)  # verbose so we can see methods missing tests

    print('[DEMO] Areas of various geometric shapes: \n')
    print(F'''Rectangle: {area_rectangle(10, 20) = }''')
    print(F'''Square: {area_square(10) = }''')
    print(F'''Triangle: {area_triangle(10, 10) = }''')
    print(F'''Triangle: {area_triangle_three_sides(5, 12, 13) = }''')
    print(F'''Parallelogram: {area_parallelogram(10, 20) = }''')
    print(F'''Rhombus: {area_rhombus(10, 20) = }''')
    print(F'''Trapezium: {area_trapezium(10, 20, 30) = }''')
    print(F'''Circle: {area_circle(20) = }''')
    print(F'''Ellipse: {area_ellipse(10, 20) = }''')
    print('\nSurface Areas of various geometric shapes: \n')
    print(F'''Cube: {surface_area_cube(20) = }''')
    print(F'''Cuboid: {surface_area_cuboid(10, 20, 30) = }''')
    print(F'''Sphere: {surface_area_sphere(20) = }''')
    print(F'''Hemisphere: {surface_area_hemisphere(20) = }''')
    print(F'''Cone: {surface_area_cone(10, 20) = }''')
    print(F'''Conical Frustum: {surface_area_conical_frustum(10, 20, 30) = }''')
    print(F'''Cylinder: {surface_area_cylinder(10, 20) = }''')
    print(F'''Torus: {surface_area_torus(20, 10) = }''')
    print(F'''Equilateral Triangle: {area_reg_polygon(3, 10) = }''')
    print(F'''Square: {area_reg_polygon(4, 10) = }''')
    print(F'''Reqular Pentagon: {area_reg_polygon(5, 10) = }''')






