




'''simple docstring'''







from sympy import diff, lambdify, symbols
from sympy.functions import *  # noqa: F403







def 						_A      ( UpperCAmelCase      ,UpperCAmelCase      ,UpperCAmelCase = "x"      ,UpperCAmelCase = 10**-10      ,UpperCAmelCase = 1      ,):






   '''simple docstring'''







   A__       =     symbols(UpperCAmelCase						)
   A__       =     lambdify(UpperCAmelCase      ,UpperCAmelCase						)
   A__       =     lambdify(UpperCAmelCase      ,diff(UpperCAmelCase      ,UpperCAmelCase						)						)

   A__       =     starting_point

   while True:
      if diff_function(UpperCAmelCase						) != 0:
         A__       =     prev_guess - multiplicity * func(UpperCAmelCase						) / diff_function(
             UpperCAmelCase						)
      else:
         raise ZeroDivisionError('Could not find root'						) from None

      # Precision is checked by comparing the difference of consecutive guesses
      if abs(next_guess - prev_guess						) < precision:
         return next_guess

      A__       =     next_guess


# Let's Execute
if __name__ == "__main__":
    # Find root of trigonometric function
    # Find value of pi
    print(f'''The root of sin(x) = 0 is {newton_raphson('sin(x)', 2)}''')

    # Find root of polynomial
    # Find fourth Root of 5
    print(f'''The root of x**4 - 5 = 0 is {newton_raphson('x**4 -5', 0.4 +5j)}''')

    # Find value of e
    print(
        '''The root of log(y) - 1 = 0 is ''',
        f'''{newton_raphson('log(y) - 1', 2, variable='y')}''',
    )

    # Exponential Roots
    print(
        '''The root of exp(x) - 1 = 0 is''',
        f'''{newton_raphson('exp(x) - 1', 1_0, precision=0.0_05)}''',
    )

    # Find root of cos(x)
    print(f'''The root of cos(x) = 0 is {newton_raphson('cos(x)', 0)}''')









"""simple docstring"""





import unittest

from transformers import is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision, slow, torch_device


if is_torch_available():
       import torch

       from transformers import AutoModelForImageClassification

if is_vision_available():
       from transformers import AutoImageProcessor

@require_torch
@require_vision
class 						lowercase   (   unittest.TestCase   ):





      @slow
      def        _snake_case     (			self					)						->	Any:
            lowerCAmelCase    		=			AutoImageProcessor.from_pretrained("""microsoft/dit-base-finetuned-rvlcdip"""					)
            lowerCAmelCase    		=			AutoModelForImageClassification.from_pretrained("""microsoft/dit-base-finetuned-rvlcdip"""					)
            model.to(lowercase					)

            from datasets import load_dataset

            lowerCAmelCase    		=			load_dataset("""nielsr/rvlcdip-demo"""					)

            lowerCAmelCase    		=			dataset["""train"""][0]["""image"""].convert("""RGB"""					)

            lowerCAmelCase    		=			image_processor(lowercase ,		return_tensors="""pt"""					).to(lowercase					)

            # forward pass
            with torch.no_grad():
                  lowerCAmelCase    		=			model(**lowercase					)
                  lowerCAmelCase    		=			outputs.logits

            lowerCAmelCase    		=			torch.Size((1, 16)					)
            self.assertEqual(logits.shape ,		lowercase					)

            lowerCAmelCase    		=			torch.tensor(
                [-0.4_158, -0.4_092, -0.4_347] ,		device=lowercase ,		dtype=torch.float ,		)
            self.assertTrue(torch.allclose(logits[0, :3] ,		lowercase ,		atol=1e-4					)					)






