




'''simple docstring'''







from typing import Optional, Tuple

import jax
import jax.numpy as jnp
from flax import linen as nn
from flax.core.frozen_dict import FrozenDict
from transformers import CLIPConfig, FlaxPreTrainedModel
from transformers.models.clip.modeling_flax_clip import FlaxCLIPVisionModule







def 						_A      ( UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase=1e-12						):






   '''simple docstring'''







   A__       =     jnp.divide(emb_a.T      ,jnp.clip(jnp.linalg.norm(UpperCAmelCase      ,axis=1						)      ,a_min=UpperCAmelCase						)						).T
   A__       =     jnp.divide(emb_a.T      ,jnp.clip(jnp.linalg.norm(UpperCAmelCase      ,axis=1						)      ,a_min=UpperCAmelCase						)						).T
   return jnp.matmul(UpperCAmelCase      ,norm_emb_a.T						)

class 	_snake_case(			nn.Module      ):
 __snake_case:							CLIPConfig
 __snake_case:							jnp.dtype						=					jnp.floataa






 def 						_UpperCamelCase (self       :  Optional[int]    )       ->   List[str]:






    """simple docstring"""


    A__       =     FlaxCLIPVisionModule(self.config.vision_config    )
    A__       =     nn.Dense(self.config.projection_dim    ,		use_bias=a    ,		dtype=self.dtype    )

    A__       =     self.param('concept_embeds'    ,		jax.nn.initializers.ones    ,		(17, self.config.projection_dim)    )
    A__       =     self.param(
        'special_care_embeds'    ,		jax.nn.initializers.ones    ,		(3, self.config.projection_dim)    )

    A__       =     self.param('concept_embeds_weights'    ,		jax.nn.initializers.ones    ,		(17,)    )
    A__       =     self.param('special_care_embeds_weights'    ,		jax.nn.initializers.ones    ,		(3,)    )






 def __call__(self       :  str    ,		a       :  Optional[Any]    )       ->   List[str]:






    """simple docstring"""


    A__       =     self.vision_model(a    )[1]
    A__       =     self.visual_projection(a    )

    A__       =     jax_cosine_distance(a    ,		self.special_care_embeds    )
    A__       =     jax_cosine_distance(a    ,		self.concept_embeds    )

    # increase this value to create a stronger `nfsw` filter
    # at the cost of increasing the possibility of filtering benign image inputs
    A__       =     0.0

    A__       =     special_cos_dist - self.special_care_embeds_weights[None, :] + adjustment
    A__       =     jnp.round(a    ,		3    )
    A__       =     jnp.any(special_scores > 0    ,		axis=1    ,		keepdims=a    )
    # Use a lower threshold if an image has any special care concept
    A__       =     is_special_care * 0.01

    A__       =     cos_dist - self.concept_embeds_weights[None, :] + special_adjustment
    A__       =     jnp.round(a    ,		3    )
    A__       =     jnp.any(concept_scores > 0    ,		axis=1    )

    return has_nsfw_concepts




class 	_snake_case(			UpperCAmelCase      ):
 __snake_case:							Dict						=					CLIPConfig
 __snake_case:							List[str]						=					'''clip_input'''
 __snake_case:							Optional[Any]						=					FlaxStableDiffusionSafetyCheckerModule






 def __init__(self       :  int    ,		a       :  CLIPConfig    ,		a       :  Optional[Tuple] = None    ,		a       :  int = 0    ,		a       :  jnp.dtype = jnp.floataa    ,		a       :  bool = True    ,		**a       :  List[str]    ,		)       ->   Optional[int]:






    """simple docstring"""


    if input_shape is None:
       A__       =     (1, 2_24, 2_24, 3)
    A__       =     self.module_class(config=a    ,		dtype=a    ,		**a    )
    super().__init__(a    ,		a    ,		input_shape=a    ,		seed=a    ,		dtype=a    ,		_do_init=_do_init    )






 def 						_UpperCamelCase (self       :  int    ,		a       :  jax.random.KeyArray    ,		a       :  Tuple    ,		a       :  FrozenDict = None    )       ->   FrozenDict:






    """simple docstring"""


    A__       =     jax.random.normal(a    ,		a    )

    A__  ,			A__       =     jax.random.split(a    )
    A__       =     {'params': params_rng, 'dropout': dropout_rng}

    A__       =     self.module.init(a    ,		a    )['params']

    return random_params






 def __call__(self       :  Any    ,		a       :  Union[str, Any]    ,		a       :  dict = None    ,		)       ->   Union[str, Any]:






    """simple docstring"""


    A__       =     jnp.transpose(a    ,		(0, 2, 3, 1)    )

    return self.module.apply(
        {'params': params or self.params}    ,		jnp.array(a    ,		dtype=jnp.floataa    )    ,		rngs={}    ,		)








'''simple docstring'''







def 						_A      ( UpperCAmelCase						):






   '''simple docstring'''







   A__       =     0
   while num > 0:
      digit_sum += num % 10
      num //= 10
   return digit_sum







def 						_A      ( UpperCAmelCase = 100						):






   '''simple docstring'''







   A__       =     1
   A__       =     2

   for i in range(2      ,max_n + 1						):
      A__       =     pre_numerator
      A__       =     2 * i // 3 if i % 3 == 0 else 1
      A__       =     cur_numerator
      A__       =     e_cont * pre_numerator + temp

   return sum_digits(UpperCAmelCase						)


if __name__ == "__main__":
    print(f'''{solution() = }''')


