




"""simple docstring"""

from math import factorial, pi






def 		_snake_case	(   _snake_case				:   float							,    _snake_case				:   int = 30				)       ->   float:






      '''simple docstring'''


      if not isinstance(_snake_case							,    (int, float)				):
            raise ValueError('maclaurin_sin() requires either an int or float for theta'				)

      if not isinstance(_snake_case							,    _snake_case				) or accuracy <= 0:
            raise ValueError('maclaurin_sin() requires a positive int for accuracy'				)

      _A     =  float(_snake_case				)
      _A     =  theta // (2 * pi)
      theta -= 2 * div * pi
      return sum(
          (-1) ** r * theta ** (2 * r + 1) / factorial(2 * r + 1				) for r in range(_snake_case				)				)






def 		_snake_case	(   _snake_case				:   float							,    _snake_case				:   int = 30				)       ->   float:






      '''simple docstring'''


      if not isinstance(_snake_case							,    (int, float)				):
            raise ValueError('maclaurin_cos() requires either an int or float for theta'				)

      if not isinstance(_snake_case							,    _snake_case				) or accuracy <= 0:
            raise ValueError('maclaurin_cos() requires a positive int for accuracy'				)

      _A     =  float(_snake_case				)
      _A     =  theta // (2 * pi)
      theta -= 2 * div * pi
      return sum((-1) ** r * theta ** (2 * r) / factorial(2 * r				) for r in range(_snake_case				)				)


if __name__ == "__main__":
       import doctest

       doctest.testmod()

       print(maclaurin_sin(10))
       print(maclaurin_sin(-10))
       print(maclaurin_sin(10, 15))
       print(maclaurin_sin(-10, 15))

       print(maclaurin_cos(5))
       print(maclaurin_cos(-5))
       print(maclaurin_cos(10, 15))
       print(maclaurin_cos(-10, 15))



"""simple docstring"""


import unittest

from transformers import is_flax_available
from transformers.testing_utils import require_flax, require_sentencepiece, require_tokenizers, require_torch, slow


if is_flax_available():
						import optax
						from flax.training.common_utils import onehot

						from transformers import AutoTokenizer, FlaxMTaForConditionalGeneration
						from transformers.models.ta.modeling_flax_ta import shift_tokens_right




@require_torch
@require_sentencepiece
@require_tokenizers
@require_flax
class  __lowerCamelCase  ( unittest.TestCase			):




				@slow
				def        UpperCAmelCase__						(				self   ):
							lowerCamelCase_					=  FlaxMTaForConditionalGeneration.from_pretrained('''google/mt5-small'''   )
							lowerCamelCase_					=  AutoTokenizer.from_pretrained('''google/mt5-small'''   )

							lowerCamelCase_					=  tokenizer('''Hello there'''							,						return_tensors='''np'''   ).input_ids
							lowerCamelCase_					=  tokenizer('''Hi I am'''							,						return_tensors='''np'''   ).input_ids

							lowerCamelCase_					=  shift_tokens_right(UpperCAmelCase							,						model.config.pad_token_id							,						model.config.decoder_start_token_id   )

							lowerCamelCase_					=  model(UpperCAmelCase							,						decoder_input_ids=UpperCAmelCase   ).logits
							lowerCamelCase_					=  optax.softmax_cross_entropy(UpperCAmelCase							,						onehot(UpperCAmelCase							,						logits.shape[-1]   )   ).mean()

							lowerCamelCase_					=  -(labels.shape[-1] * loss.item())

							lowerCamelCase_					=  -8_4.9_1_2_7
							self.assertTrue(abs(mtf_score - EXPECTED_SCORE   ) < 1e-4   )



