





import tempfile

import torch

from diffusers import PNDMScheduler

from .test_schedulers import SchedulerCommonTest

class    _UpperCAmelCase							(		__a     ):
      a						       =							(PNDMScheduler,)
      a						       =							(("num_inference_steps", 50),)
      def 		_lowerCamelCase      (		self      ,       **a__       ):
         A_     :				Dict			      =	{
             """num_train_timesteps""": 1000,
             """beta_start""": 0.0001,
             """beta_end""": 0.02,
             """beta_schedule""": """linear""",
         }

         config.update(**lowerCAmelCase_       )
         return config
      def 		_lowerCamelCase      (		self      ,       a__=0      ,       **a__       ):
         A_     :				str			      =	dict(self.forward_default_kwargs       )
         A_     :				str			      =	kwargs.pop("""num_inference_steps"""      ,       lowerCAmelCase_       )
         A_     :				Union[str, Any]			      =	self.dummy_sample
         A_     :				Optional[int]			      =	0.1 * sample
         A_     :				Optional[Any]			      =	[residual + 0.2, residual + 0.15, residual + 0.1, residual + 0.05]

         for scheduler_class in self.scheduler_classes:
            A_     :				Union[str, Any]			      =	self.get_scheduler_config(**lowerCAmelCase_       )
            A_     :				List[str]			      =	scheduler_class(**lowerCAmelCase_       )
            scheduler.set_timesteps(lowerCAmelCase_       )
            # copy over dummy past residuals
            A_     :				List[Any]			      =	dummy_past_residuals[:]

            with tempfile.TemporaryDirectory() as tmpdirname:
               scheduler.save_config(lowerCAmelCase_       )
               A_     :				List[str]			      =	scheduler_class.from_pretrained(lowerCAmelCase_       )
               new_scheduler.set_timesteps(lowerCAmelCase_       )
               # copy over dummy past residuals
               A_     :				Dict			      =	dummy_past_residuals[:]

            A_     :				Tuple			      =	scheduler.step_prk(lowerCAmelCase_      ,       lowerCAmelCase_      ,       lowerCAmelCase_      ,       **lowerCAmelCase_       ).prev_sample
            A_     :				Optional[int]			      =	new_scheduler.step_prk(lowerCAmelCase_      ,       lowerCAmelCase_      ,       lowerCAmelCase_      ,       **lowerCAmelCase_       ).prev_sample

            assert torch.sum(torch.abs(output - new_output       )       ) < 1E-5, "Scheduler outputs are not identical"

            A_     :				Tuple			      =	scheduler.step_plms(lowerCAmelCase_      ,       lowerCAmelCase_      ,       lowerCAmelCase_      ,       **lowerCAmelCase_       ).prev_sample
            A_     :				str			      =	new_scheduler.step_plms(lowerCAmelCase_      ,       lowerCAmelCase_      ,       lowerCAmelCase_      ,       **lowerCAmelCase_       ).prev_sample

            assert torch.sum(torch.abs(output - new_output       )       ) < 1E-5, "Scheduler outputs are not identical"
      def 		_lowerCamelCase      (		self       ):
         pass
      def 		_lowerCamelCase      (		self      ,       a__=0      ,       **a__       ):
         A_     :				Union[str, Any]			      =	dict(self.forward_default_kwargs       )
         A_     :				int			      =	kwargs.pop("""num_inference_steps"""      ,       lowerCAmelCase_       )
         A_     :				List[str]			      =	self.dummy_sample
         A_     :				Optional[Any]			      =	0.1 * sample
         A_     :				Tuple			      =	[residual + 0.2, residual + 0.15, residual + 0.1, residual + 0.05]

         for scheduler_class in self.scheduler_classes:
            A_     :				List[str]			      =	self.get_scheduler_config()
            A_     :				Union[str, Any]			      =	scheduler_class(**lowerCAmelCase_       )
            scheduler.set_timesteps(lowerCAmelCase_       )

            # copy over dummy past residuals (must be after setting timesteps)
            A_     :				Optional[int]			      =	dummy_past_residuals[:]

            with tempfile.TemporaryDirectory() as tmpdirname:
               scheduler.save_config(lowerCAmelCase_       )
               A_     :				Dict			      =	scheduler_class.from_pretrained(lowerCAmelCase_       )
               # copy over dummy past residuals
               new_scheduler.set_timesteps(lowerCAmelCase_       )

               # copy over dummy past residual (must be after setting timesteps)
               A_     :				List[str]			      =	dummy_past_residuals[:]

            A_     :				Tuple			      =	scheduler.step_prk(lowerCAmelCase_      ,       lowerCAmelCase_      ,       lowerCAmelCase_      ,       **lowerCAmelCase_       ).prev_sample
            A_     :				Optional[Any]			      =	new_scheduler.step_prk(lowerCAmelCase_      ,       lowerCAmelCase_      ,       lowerCAmelCase_      ,       **lowerCAmelCase_       ).prev_sample

            assert torch.sum(torch.abs(output - new_output       )       ) < 1E-5, "Scheduler outputs are not identical"

            A_     :				Dict			      =	scheduler.step_plms(lowerCAmelCase_      ,       lowerCAmelCase_      ,       lowerCAmelCase_      ,       **lowerCAmelCase_       ).prev_sample
            A_     :				int			      =	new_scheduler.step_plms(lowerCAmelCase_      ,       lowerCAmelCase_      ,       lowerCAmelCase_      ,       **lowerCAmelCase_       ).prev_sample

            assert torch.sum(torch.abs(output - new_output       )       ) < 1E-5, "Scheduler outputs are not identical"
      def 		_lowerCamelCase      (		self      ,       **a__       ):
         A_     :				List[Any]			      =	self.scheduler_classes[0]
         A_     :				int			      =	self.get_scheduler_config(**lowerCAmelCase_       )
         A_     :				Tuple			      =	scheduler_class(**lowerCAmelCase_       )

         A_     :				List[str]			      =	10
         A_     :				Optional[Any]			      =	self.dummy_model()
         A_     :				List[str]			      =	self.dummy_sample_deter
         scheduler.set_timesteps(lowerCAmelCase_       )

         for i, t in enumerate(scheduler.prk_timesteps       ):
            A_     :				Dict			      =	model(lowerCAmelCase_      ,       lowerCAmelCase_       )
            A_     :				int			      =	scheduler.step_prk(lowerCAmelCase_      ,       lowerCAmelCase_      ,       lowerCAmelCase_       ).prev_sample

         for i, t in enumerate(scheduler.plms_timesteps       ):
            A_     :				List[str]			      =	model(lowerCAmelCase_      ,       lowerCAmelCase_       )
            A_     :				int			      =	scheduler.step_plms(lowerCAmelCase_      ,       lowerCAmelCase_      ,       lowerCAmelCase_       ).prev_sample

         return sample
      def 		_lowerCamelCase      (		self       ):
         A_     :				List[Any]			      =	dict(self.forward_default_kwargs       )

         A_     :				Union[str, Any]			      =	kwargs.pop("""num_inference_steps"""      ,       lowerCAmelCase_       )

         for scheduler_class in self.scheduler_classes:
            A_     :				Optional[Any]			      =	self.get_scheduler_config()
            A_     :				Dict			      =	scheduler_class(**lowerCAmelCase_       )

            A_     :				Dict			      =	self.dummy_sample
            A_     :				List[str]			      =	0.1 * sample

            if num_inference_steps is not None and hasattr(lowerCAmelCase_      ,       """set_timesteps"""       ):
               scheduler.set_timesteps(lowerCAmelCase_       )
            elif num_inference_steps is not None and not hasattr(lowerCAmelCase_      ,       """set_timesteps"""       ):
               A_     :				int			      =	num_inference_steps

            # copy over dummy past residuals (must be done after set_timesteps)
            A_     :				List[Any]			      =	[residual + 0.2, residual + 0.15, residual + 0.1, residual + 0.05]
            A_     :				Union[str, Any]			      =	dummy_past_residuals[:]

            A_     :				Optional[Any]			      =	scheduler.step_prk(lowerCAmelCase_      ,       0      ,       lowerCAmelCase_      ,       **lowerCAmelCase_       ).prev_sample
            A_     :				List[str]			      =	scheduler.step_prk(lowerCAmelCase_      ,       1      ,       lowerCAmelCase_      ,       **lowerCAmelCase_       ).prev_sample

            self.assertEqual(output_a.shape      ,       sample.shape       )
            self.assertEqual(output_a.shape      ,       output_a.shape       )

            A_     :				int			      =	scheduler.step_plms(lowerCAmelCase_      ,       0      ,       lowerCAmelCase_      ,       **lowerCAmelCase_       ).prev_sample
            A_     :				List[Any]			      =	scheduler.step_plms(lowerCAmelCase_      ,       1      ,       lowerCAmelCase_      ,       **lowerCAmelCase_       ).prev_sample

            self.assertEqual(output_a.shape      ,       sample.shape       )
            self.assertEqual(output_a.shape      ,       output_a.shape       )
      def 		_lowerCamelCase      (		self       ):







         for timesteps in [100, 1000]:
            self.check_over_configs(num_train_timesteps=lowerCAmelCase_       )
      def 		_lowerCamelCase      (		self       ):







         for steps_offset in [0, 1]:
            self.check_over_configs(steps_offset=lowerCAmelCase_       )

         A_     :				Tuple			      =	self.scheduler_classes[0]
         A_     :				Any			      =	self.get_scheduler_config(steps_offset=1       )
         A_     :				Optional[int]			      =	scheduler_class(**lowerCAmelCase_       )
         scheduler.set_timesteps(10       )
         assert torch.equal(
             scheduler.timesteps      ,       torch.LongTensor(
                 [901, 851, 851, 801, 801, 751, 751, 701, 701, 651, 651, 601, 601, 501, 401, 301, 201, 101, 1]       )      ,       )
      def 		_lowerCamelCase      (		self       ):







         for beta_start, beta_end in zip([0.0001, 0.001]      ,       [0.002, 0.02]       ):
            self.check_over_configs(beta_start=lowerCAmelCase_      ,       beta_end=lowerCAmelCase_       )
      def 		_lowerCamelCase      (		self       ):







         for schedule in ["linear", "squaredcos_cap_v2"]:
            self.check_over_configs(beta_schedule=lowerCAmelCase_       )
      def 		_lowerCamelCase      (		self       ):







         for prediction_type in ["epsilon", "v_prediction"]:
            self.check_over_configs(prediction_type=lowerCAmelCase_       )
      def 		_lowerCamelCase      (		self       ):







         for t in [1, 5, 10]:
            self.check_over_forward(time_step=lowerCAmelCase_       )
      def 		_lowerCamelCase      (		self       ):







         for t, num_inference_steps in zip([1, 5, 10]      ,       [10, 50, 100]       ):
            self.check_over_forward(num_inference_steps=lowerCAmelCase_       )
      def 		_lowerCamelCase      (		self       ):
         A_     :				Union[str, Any]			      =	27

         for scheduler_class in self.scheduler_classes:
            A_     :				Tuple			      =	self.dummy_sample
            A_     :				List[str]			      =	0.1 * sample

            A_     :				Optional[Any]			      =	self.get_scheduler_config()
            A_     :				List[Any]			      =	scheduler_class(**lowerCAmelCase_       )

            scheduler.set_timesteps(lowerCAmelCase_       )

            # before power of 3 fix, would error on first step, so we only need to do two
            for i, t in enumerate(scheduler.prk_timesteps[:2]       ):
               A_     :				List[Any]			      =	scheduler.step_prk(lowerCAmelCase_      ,       lowerCAmelCase_      ,       lowerCAmelCase_       ).prev_sample
      def 		_lowerCamelCase      (		self       ):







         with self.assertRaises(lowerCAmelCase_       ):
            A_     :				Tuple			      =	self.scheduler_classes[0]
            A_     :				str			      =	self.get_scheduler_config()
            A_     :				str			      =	scheduler_class(**lowerCAmelCase_       )

            scheduler.step_plms(self.dummy_sample      ,       1      ,       self.dummy_sample       ).prev_sample
      def 		_lowerCamelCase      (		self       ):
         A_     :				Union[str, Any]			      =	self.full_loop()
         A_     :				Dict			      =	torch.sum(torch.abs(lowerCAmelCase_       )       )
         A_     :				Optional[int]			      =	torch.mean(torch.abs(lowerCAmelCase_       )       )

         assert abs(result_sum.item() - 198.1318       ) < 1E-2
         assert abs(result_mean.item() - 0.2580       ) < 1E-3
      def 		_lowerCamelCase      (		self       ):
         A_     :				Dict			      =	self.full_loop(prediction_type="""v_prediction"""       )
         A_     :				int			      =	torch.sum(torch.abs(lowerCAmelCase_       )       )
         A_     :				Optional[int]			      =	torch.mean(torch.abs(lowerCAmelCase_       )       )

         assert abs(result_sum.item() - 67.3986       ) < 1E-2
         assert abs(result_mean.item() - 0.0878       ) < 1E-3
      def 		_lowerCamelCase      (		self       ):
         A_     :				Tuple			      =	self.full_loop(set_alpha_to_one=lowerCAmelCase_      ,       beta_start=0.01       )
         A_     :				Dict			      =	torch.sum(torch.abs(lowerCAmelCase_       )       )
         A_     :				Dict			      =	torch.mean(torch.abs(lowerCAmelCase_       )       )

         assert abs(result_sum.item() - 230.0399       ) < 1E-2
         assert abs(result_mean.item() - 0.2995       ) < 1E-3






      def 		_lowerCamelCase      (		self       ):
         A_     :				Tuple			      =	self.full_loop(set_alpha_to_one=lowerCAmelCase_      ,       beta_start=0.01       )
         A_     :				Union[str, Any]			      =	torch.sum(torch.abs(lowerCAmelCase_       )       )
         A_     :				Tuple			      =	torch.mean(torch.abs(lowerCAmelCase_       )       )

         assert abs(result_sum.item() - 186.9482       ) < 1E-2
         assert abs(result_mean.item() - 0.2434       ) < 1E-3






import re



def     _lowerCAmelCase		(  _lowerCAmelCase     ):
   '''simple docstring'''


   A_     :				Any			      =	re.compile(r"""^(\+91[\-\s]?)?[0]?(91)?[789]\d{9}$"""     )
   if match := re.search(_lowerCAmelCase  ,_lowerCAmelCase     ):
      return match.string == phone
   return False


if __name__ == "__main__":
      print(indian_phone_validator("""+918827897895"""))






