



"""simple docstring"""





import unittest

import numpy as np

from transformers import AlbertConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
  import jax.numpy as jnp

  from transformers.models.albert.modeling_flax_albert import (
      FlaxAlbertForMaskedLM,
      FlaxAlbertForMultipleChoice,
      FlaxAlbertForPreTraining,
      FlaxAlbertForQuestionAnswering,
      FlaxAlbertForSequenceClassification,
      FlaxAlbertForTokenClassification,
      FlaxAlbertModel,
  )


class    __lowerCamelCase						( unittest.TestCase     ):







   def __init__(self							,						lowerCamelCase							,						lowerCamelCase=13							,						lowerCamelCase=7							,						lowerCamelCase=True							,						lowerCamelCase=True							,						lowerCamelCase=True							,						lowerCamelCase=True							,						lowerCamelCase=99							,						lowerCamelCase=32							,						lowerCamelCase=5							,						lowerCamelCase=4							,						lowerCamelCase=37							,						lowerCamelCase="gelu"							,						lowerCamelCase=0.1							,						lowerCamelCase=0.1							,						lowerCamelCase=512							,						lowerCamelCase=16							,						lowerCamelCase=2							,						lowerCamelCase=0.02							,						lowerCamelCase=4							,						):




      '''simple docstring'''




      _lowerCAmelCase         =		parent
      _lowerCAmelCase         =		batch_size
      _lowerCAmelCase         =		seq_length
      _lowerCAmelCase         =		is_training
      _lowerCAmelCase         =		use_attention_mask
      _lowerCAmelCase         =		use_token_type_ids
      _lowerCAmelCase         =		use_labels
      _lowerCAmelCase         =		vocab_size
      _lowerCAmelCase         =		hidden_size
      _lowerCAmelCase         =		num_hidden_layers
      _lowerCAmelCase         =		num_attention_heads
      _lowerCAmelCase         =		intermediate_size
      _lowerCAmelCase         =		hidden_act
      _lowerCAmelCase         =		hidden_dropout_prob
      _lowerCAmelCase         =		attention_probs_dropout_prob
      _lowerCAmelCase         =		max_position_embeddings
      _lowerCAmelCase         =		type_vocab_size
      _lowerCAmelCase         =		type_sequence_label_size
      _lowerCAmelCase         =		initializer_range
      _lowerCAmelCase         =		num_choices







   def 				A__    (self					):




      '''simple docstring'''




      _lowerCAmelCase         =		ids_tensor([self.batch_size, self.seq_length]							,						self.vocab_size					)

      _lowerCAmelCase         =		None
      if self.use_attention_mask:
         _lowerCAmelCase         =		random_attention_mask([self.batch_size, self.seq_length]					)

      _lowerCAmelCase         =		None
      if self.use_token_type_ids:
         _lowerCAmelCase         =		ids_tensor([self.batch_size, self.seq_length]							,						self.type_vocab_size					)

      _lowerCAmelCase         =		AlbertConfig(
          vocab_size=self.vocab_size							,						hidden_size=self.hidden_size							,						num_hidden_layers=self.num_hidden_layers							,						num_attention_heads=self.num_attention_heads							,						intermediate_size=self.intermediate_size							,						hidden_act=self.hidden_act							,						hidden_dropout_prob=self.hidden_dropout_prob							,						attention_probs_dropout_prob=self.attention_probs_dropout_prob							,						max_position_embeddings=self.max_position_embeddings							,						type_vocab_size=self.type_vocab_size							,						is_decoder=lowerCamelCase							,						initializer_range=self.initializer_range							,						)

      return config, input_ids, token_type_ids, attention_mask







   def 				A__    (self					):




      '''simple docstring'''




      _lowerCAmelCase         =		self.prepare_config_and_inputs()
      _lowerCAmelCase  ,    _lowerCAmelCase  ,    _lowerCAmelCase  ,    _lowerCAmelCase         =		config_and_inputs
      _lowerCAmelCase         =		{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": attention_mask}
      return config, inputs_dict





@require_flax
class    __lowerCamelCase						( __lowercase ,				unittest.TestCase     ):
   __UpperCamelCase						= (
       (
           FlaxAlbertModel,
           FlaxAlbertForPreTraining,
           FlaxAlbertForMaskedLM,
           FlaxAlbertForMultipleChoice,
           FlaxAlbertForQuestionAnswering,
           FlaxAlbertForSequenceClassification,
           FlaxAlbertForTokenClassification,
           FlaxAlbertForQuestionAnswering,
       )
       if is_flax_available()
       else ()
   )







   def 				A__    (self					):




      '''simple docstring'''




      _lowerCAmelCase         =		FlaxAlbertModelTester(self					)







   @slow
   def 				A__    (self					):




      '''simple docstring'''




      for model_class_name in self.all_model_classes:
         _lowerCAmelCase         =		model_class_name.from_pretrained("""albert-base-v2"""					)
         _lowerCAmelCase         =		model(np.ones((1, 1)					)					)
         self.assertIsNotNone(lowerCamelCase					)





@require_flax
class    __lowerCamelCase						( unittest.TestCase     ):







   @slow
   def 				A__    (self					):




      '''simple docstring'''




      _lowerCAmelCase         =		FlaxAlbertModel.from_pretrained("""albert-base-v2"""					)
      _lowerCAmelCase         =		np.array([[0, 345, 232, 328, 740, 140, 1_695, 69, 6_078, 1_588, 2]]					)
      _lowerCAmelCase         =		np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]					)
      _lowerCAmelCase         =		model(lowerCamelCase							,						attention_mask=lowerCamelCase					)[0]
      _lowerCAmelCase         =		(1, 11, 768)
      self.assertEqual(output.shape							,						lowerCamelCase					)
      _lowerCAmelCase         =		np.array(
          [[[-0.6513, 1.5035, -0.2766], [-0.6515, 1.5046, -0.2780], [-0.6512, 1.5049, -0.2784]]]					)

      self.assertTrue(jnp.allclose(output[:, 1:4, 1:4]							,						lowerCamelCase							,						atol=1e-4					)					)




'''simple docstring'''





def lowerCAmelCase    (__A):



     """simple docstring"""



     return credit_card_number.startswith(('''34''', '''35''', '''37''', '''4''', '''5''', '''6'''))




def lowerCAmelCase    (__A):



     """simple docstring"""



     _a           =    credit_card_number
     _a           =    0
     _a           =    len(__A) - 2
     for i in range(__A    ,      -1    ,      -2):
          #  double the value of every second digit
          _a           =    int(cc_number[i])
          digit *= 2
          # If doubling of a number results in a two digit number
          # i.e greater than 9(e.g., 6 × 2 = 12),
          # then add the digits of the product (e.g., 12: 1 + 2 = 3, 15: 1 + 5 = 6),
          # to get a single digit number.
          if digit > 9:
               digit %= 10
               digit += 1
          _a           =    cc_number[:i] + str(__A) + cc_number[i + 1 :]
          total += digit

     # Sum up the remaining digits
     for i in range(len(__A) - 1    ,      -1    ,      -2):
          total += int(cc_number[i])

     return total % 10 == 0




def lowerCAmelCase    (__A):



     """simple docstring"""



     _a           =    F'''{credit_card_number} is an invalid credit card number because'''
     if not credit_card_number.isdigit():
          print(F'''{error_message} it has nonnumerical characters.''')
          return False

     if not 13 <= len(__A) <= 16:
          print(F'''{error_message} of its length.''')
          return False

     if not validate_initial_digits(__A):
          print(F'''{error_message} of its first two digits.''')
          return False

     if not luhn_validation(__A):
          print(F'''{error_message} it fails the Luhn check.''')
          return False

     print(F'''{credit_card_number} is a valid credit card number.''')
     return True


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  validate_credit_card_number("4111111111111111")
  validate_credit_card_number("32323")



