




'''simple docstring'''



from __future__ import annotations







def       _UpperCamelCase			(_lowerCamelCase				:  float ,						_lowerCamelCase				:  float ,						_lowerCamelCase				:  float						)-> Optional[int]:




     '''simple docstring'''





     if days_between_payments <= 0:
          raise ValueError('''days_between_payments must be > 0'''						)
     if daily_interest_rate < 0:
          raise ValueError('''daily_interest_rate must be >= 0'''						)
     if principal <= 0:
          raise ValueError('''principal must be > 0'''						)
     return principal * daily_interest_rate * days_between_payments







def       _UpperCamelCase			(_lowerCamelCase				:  float ,						_lowerCamelCase				:  float ,						_lowerCamelCase				:  float ,						)-> Optional[int]:




     '''simple docstring'''





     if number_of_compounding_periods <= 0:
          raise ValueError('''number_of_compounding_periods must be > 0'''						)
     if nominal_annual_interest_rate_percentage < 0:
          raise ValueError('''nominal_annual_interest_rate_percentage must be >= 0'''						)
     if principal <= 0:
          raise ValueError('''principal must be > 0'''						)

     return principal * (
         (1 + nominal_annual_interest_rate_percentage) ** number_of_compounding_periods
         - 1
     )







def       _UpperCamelCase			(_lowerCamelCase				:  float ,						_lowerCamelCase				:  float ,						_lowerCamelCase				:  float ,						)-> Tuple:




     '''simple docstring'''





     if number_of_years <= 0:
          raise ValueError('''number_of_years must be > 0'''						)
     if nominal_annual_percentage_rate < 0:
          raise ValueError('''nominal_annual_percentage_rate must be >= 0'''						)
     if principal <= 0:
          raise ValueError('''principal must be > 0'''						)

     return compound_interest(
         UpperCamelCase_ ,						nominal_annual_percentage_rate / 3_65 ,						number_of_years * 3_65						)


if __name__ == "__main__":
     import doctest

     doctest.testmod()










'''simple docstring'''





from typing import Optional

from torch import nn

from .transformer_ad import TransformeraDModel, TransformeraDModelOutput




class 				UpperCAmelCase			(			nn.Module						):


 def __init__(      self							:	int			,       __lowerCamelCase							:	int = 1_6			,       __lowerCamelCase							:	int = 8_8			,       __lowerCamelCase							:	Optional[int] = None			,       __lowerCamelCase							:	int = 1			,       __lowerCamelCase							:	float = 0.0			,       __lowerCamelCase							:	int = 3_2			,       __lowerCamelCase							:	Optional[int] = None			,       __lowerCamelCase							:	bool = False			,       __lowerCamelCase							:	Optional[int] = None			,       __lowerCamelCase							:	Optional[int] = None			,       __lowerCamelCase							:	str = "geglu"			,       __lowerCamelCase							:	Optional[int] = None			,       ):
    super().__init__()
    UpperCAmelCase__	:Optional[int]      =      nn.ModuleList(
        [
            TransformeraDModel(
                num_attention_heads=__lowerCamelCase			,       attention_head_dim=__lowerCamelCase			,       in_channels=__lowerCamelCase			,       num_layers=__lowerCamelCase			,       dropout=__lowerCamelCase			,       norm_num_groups=__lowerCamelCase			,       cross_attention_dim=__lowerCamelCase			,       attention_bias=__lowerCamelCase			,       sample_size=__lowerCamelCase			,       num_vector_embeds=__lowerCamelCase			,       activation_fn=__lowerCamelCase			,       num_embeds_ada_norm=__lowerCamelCase			,       )
            for _ in range(2 )
        ] )

    # Variables that can be set by a pipeline:

    # The ratio of transformer1 to transformer2's output states to be combined during inference
    UpperCAmelCase__	:Tuple      =      0.5

    # The shape of `encoder_hidden_states` is expected to be
    # `(batch_size, condition_lengths[0]+condition_lengths[1], num_features)`
    UpperCAmelCase__	:int      =      [7_7, 2_5_7]

    # Which transformer to use to encode which condition.
    # E.g. `(1, 0)` means that we'll use `transformers[1](conditions[0])` and `transformers[0](conditions[1])`
    UpperCAmelCase__	:Any      =      [1, 0]





 def        __SCREAMING_SNAKE_CASE					(      self							:	str			,       __lowerCamelCase							:	Optional[int]			,       __lowerCamelCase							:	Any			,       __lowerCamelCase							:	int=None			,       __lowerCamelCase							:	Dict=None			,       __lowerCamelCase							:	Dict=None			,       __lowerCamelCase							:	bool = True			,       ):
    UpperCAmelCase__	:Optional[int]      =      hidden_states

    UpperCAmelCase__	:Dict      =      []
    UpperCAmelCase__	:Tuple      =      0
    # attention_mask is not used yet
    for i in range(2 ):
       # for each of the two transformers, pass the corresponding condition tokens
       UpperCAmelCase__	:List[Any]      =      encoder_hidden_states[:, tokens_start : tokens_start + self.condition_lengths[i]]
       UpperCAmelCase__	:Dict      =      self.transformer_index_for_condition[i]
       UpperCAmelCase__	:Tuple      =      self.transformers[transformer_index](
           __lowerCamelCase			,       encoder_hidden_states=__lowerCamelCase			,       timestep=__lowerCamelCase			,       cross_attention_kwargs=__lowerCamelCase			,       return_dict=__lowerCamelCase			,       )[0]
       encoded_states.append(encoded_state - input_states )
       tokens_start += self.condition_lengths[i]

    UpperCAmelCase__	:Optional[int]      =      encoded_states[0] * self.mix_ratio + encoded_states[1] * (1 - self.mix_ratio)
    UpperCAmelCase__	:Optional[Any]      =      output_states + input_states

    if not return_dict:
       return (output_states,)

    return TransformeraDModelOutput(sample=__lowerCamelCase )



