





from dataclasses import dataclass
from typing import Optional, Tuple, Union

import torch
import torch.nn as nn

from ..configuration_utils import ConfigMixin, register_to_config
from ..utils import BaseOutput, apply_forward_hook
from .modeling_utils import ModelMixin
from .vae import Decoder, DecoderOutput, Encoder, VectorQuantizer


@dataclass
class   A      (SCREAMING_SNAKE_CASE   ):
			'''simple docstring'''




			__lowerCamelCase     :	torch.FloatTensor


class   A      (SCREAMING_SNAKE_CASE       ,					SCREAMING_SNAKE_CASE   ):
			'''simple docstring'''




			@register_to_config
			def __init__(      self       :   int							,     __lowerCAmelCase       :   int = 3							,     __lowerCAmelCase       :   int = 3							,     __lowerCAmelCase       :   Tuple[str] = ("DownEncoderBlock2D",)							,     __lowerCAmelCase       :   Tuple[str] = ("UpDecoderBlock2D",)							,     __lowerCAmelCase       :   Tuple[int] = (64,)							,     __lowerCAmelCase       :   int = 1							,     __lowerCAmelCase       :   str = "silu"							,     __lowerCAmelCase       :   int = 3							,     __lowerCAmelCase       :   int = 32							,     __lowerCAmelCase       :   int = 2_56							,     __lowerCAmelCase       :   int = 32							,     __lowerCAmelCase       :   Optional[int] = None							,     __lowerCAmelCase       :   float = 0.1_8_2_1_5							,     __lowerCAmelCase       :   str = "group"							,     )     ->     int:







					"""simple docstring"""






					super().__init__()

					# pass init params to Encoder
					A__  				=       Encoder(
					    in_channels=__lowerCAmelCase							,     out_channels=__lowerCAmelCase							,     down_block_types=__lowerCAmelCase							,     block_out_channels=__lowerCAmelCase							,     layers_per_block=__lowerCAmelCase							,     act_fn=__lowerCAmelCase							,     norm_num_groups=__lowerCAmelCase							,     double_z=__lowerCAmelCase							,     )

					A__  				=       vq_embed_dim if vq_embed_dim is not None else latent_channels

					A__  				=       nn.Convad(__lowerCAmelCase							,     __lowerCAmelCase							,     1       )
					A__  				=       VectorQuantizer(__lowerCAmelCase							,     __lowerCAmelCase							,     beta=0.2_5							,     remap=__lowerCAmelCase							,     sane_index_shape=__lowerCAmelCase       )
					A__  				=       nn.Convad(__lowerCAmelCase							,     __lowerCAmelCase							,     1       )

					# pass init params to Decoder
					A__  				=       Decoder(
					    in_channels=__lowerCAmelCase							,     out_channels=__lowerCAmelCase							,     up_block_types=__lowerCAmelCase							,     block_out_channels=__lowerCAmelCase							,     layers_per_block=__lowerCAmelCase							,     act_fn=__lowerCAmelCase							,     norm_num_groups=__lowerCAmelCase							,     norm_type=__lowerCAmelCase							,     )






			@apply_forward_hook
			def        a_	(      self       :   int							,     __lowerCAmelCase       :   torch.FloatTensor							,     __lowerCAmelCase       :   bool = True       )     ->     VQEncoderOutput:







					"""simple docstring"""






					A__  				=       self.encoder(__lowerCAmelCase       )
					A__  				=       self.quant_conv(__lowerCAmelCase       )

					if not return_dict:
							return (h,)

					return VQEncoderOutput(latents=__lowerCAmelCase       )






			@apply_forward_hook
			def        a_	(      self       :   Any							,     __lowerCAmelCase       :   torch.FloatTensor							,     __lowerCAmelCase       :   bool = False							,     __lowerCAmelCase       :   bool = True       )     ->     Union[DecoderOutput, torch.FloatTensor]:







					"""simple docstring"""






					if not force_not_quantize:
							A__				,      A__				,      A__  				=       self.quantize(__lowerCAmelCase       )
					else:
							A__  				=       h
					A__  				=       self.post_quant_conv(__lowerCAmelCase       )
					A__  				=       self.decoder(__lowerCAmelCase							,     quant if self.config.norm_type == """spatial""" else None       )

					if not return_dict:
							return (dec,)

					return DecoderOutput(sample=__lowerCAmelCase       )







			def        a_	(      self       :   int							,     __lowerCAmelCase       :   torch.FloatTensor							,     __lowerCAmelCase       :   bool = True       )     ->     Union[DecoderOutput, torch.FloatTensor]:







					"""simple docstring"""






					A__  				=       sample
					A__  				=       self.encode(__lowerCAmelCase       ).latents
					A__  				=       self.decode(__lowerCAmelCase       ).sample

					if not return_dict:
							return (dec,)

					return DecoderOutput(sample=__lowerCAmelCase       )










def        __lowerCamelCase (							__a       :float   ,					__a       :list[float]   )		->    float:






		"""simple docstring"""

		if discount_rate < 0:
				raise ValueError("""Discount rate cannot be negative"""   )
		if not cash_flows:
				raise ValueError("""Cash flows list cannot be empty"""   )
		A__  				=       sum(
		    cash_flow / ((1 + discount_rate) ** i) for i, cash_flow in enumerate(__a   )   )
		return round(__a   ,					ndigits=2   )


if __name__ == "__main__":
					import doctest

					doctest.testmod()



