


import unittest

from knapsack import greedy_knapsack as kp


class 			A_   (			unittest.TestCase       ):




      '''simple docstring'''


      def 	_snake_case      (							self:			Optional[Any]							):
       __lowerCamelCase						:				Any						   =		[10, 20, 30, 40, 50, 60]
       __lowerCamelCase						:				List[str]						   =		[2, 4, 6, 8, 10, 12]
       __lowerCamelCase						:				str						   =		100
       self.assertEqual(kp.calc_profit(__snake_case		, __snake_case		, __snake_case							)		, 210							)




      def 	_snake_case      (							self:			Optional[Any]							):
       self.assertRaisesRegex(__snake_case		, 'max_weight must greater than zero.'							)




      def 	_snake_case      (							self:			Optional[int]							):
       self.assertRaisesRegex(__snake_case		, 'Weight can not be negative.'							)




      def 	_snake_case      (							self:			int							):
       self.assertRaisesRegex(__snake_case		, 'Profit can not be negative.'							)




      def 	_snake_case      (							self:			Optional[int]							):
       self.assertRaisesRegex(__snake_case		, 'max_weight must greater than zero.'							)




      def 	_snake_case      (							self:			Dict							):
       self.assertRaisesRegex(
           __snake_case		, 'The length of profit and weight must be same.'							)


if __name__ == "__main__":
       unittest.main()








'''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	):






     """simple docstring"""






     @slow
     def      lowerCAmelCase			(   self							:			Union[str, Any]						)->	Optional[Any]:
        snake_case 						=   FlaxMTaForConditionalGeneration.from_pretrained("""google/mt5-small"""						)
        snake_case 						=   AutoTokenizer.from_pretrained("""google/mt5-small"""						)

        snake_case 						=   tokenizer("""Hello there"""   ,       return_tensors="""np"""						).input_ids
        snake_case 						=   tokenizer("""Hi I am"""   ,       return_tensors="""np"""						).input_ids

        snake_case 						=   shift_tokens_right(__snake_case   ,       model.config.pad_token_id   ,       model.config.decoder_start_token_id						)

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

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

        snake_case 						=   -84.91_27
        self.assertTrue(abs(mtf_score - EXPECTED_SCORE						) < 1e-4						)

