





'''simple docstring'''


import json
import os
import tempfile

import transformers

import datasets
from utils import generate_example_dataset, get_duration


lowerCAmelCase :					Dict 							=500_000

lowerCAmelCase :					Tuple 							=os.path.split(__file__)
lowerCAmelCase :					int 							=os.path.join(RESULTS_BASEPATH, '''results''', RESULTS_FILENAME.replace('''.py''', '''.json'''))
@get_duration
def 							UpperCAmelCase_  (						__lowerCamelCase : datasets.Dataset     ,**__lowerCamelCase : int			):
   lowercase_      :List[str]         =			dataset.map(**__lowerCamelCase			)
@get_duration
def 							UpperCAmelCase_  (						__lowerCamelCase : datasets.Dataset     ,**__lowerCamelCase : Dict			):
   lowercase_      :Optional[int]         =			dataset.filter(**__lowerCamelCase			)
def 							UpperCAmelCase_  (						):
   lowercase_      :Dict         =			{"num examples": SPEED_TEST_N_EXAMPLES}
   with tempfile.TemporaryDirectory() as tmp_dir:
      lowercase_      :str         =			datasets.Features({"text": datasets.Value("string"			), "numbers": datasets.Value("float32"			)}			)
      lowercase_      :List[str]         =			generate_example_dataset(
          os.path.join(__lowerCamelCase     ,"dataset.arrow"			)     ,__lowerCamelCase     ,num_examples=__lowerCamelCase			)

      lowercase_      :List[str]         =			transformers.AutoTokenizer.from_pretrained("bert-base-cased"     ,use_fast=__lowerCamelCase			)

      def tokenize(__lowerCamelCase : Tuple			):
         return tokenizer(examples["text"]			)

      lowercase_      :List[str]         =			map(__lowerCamelCase			)

      lowercase_      :Optional[int]         =			map(__lowerCamelCase     ,batched=__lowerCamelCase			)

      lowercase_      :Tuple         =			map(__lowerCamelCase     ,function=lambda __lowerCamelCase			: None     ,batched=__lowerCamelCase			)

      with dataset.formatted_as(type="numpy"			):
         lowercase_      :List[Any]         =			map(__lowerCamelCase     ,function=lambda __lowerCamelCase			: None     ,batched=__lowerCamelCase			)

      with dataset.formatted_as(type="pandas"			):
         lowercase_      :List[str]         =			map(__lowerCamelCase     ,function=lambda __lowerCamelCase			: None     ,batched=__lowerCamelCase			)

      with dataset.formatted_as(type="torch"     ,columns="numbers"			):
         lowercase_      :Any         =			map(__lowerCamelCase     ,function=lambda __lowerCamelCase			: None     ,batched=__lowerCamelCase			)

      with dataset.formatted_as(type="tensorflow"     ,columns="numbers"			):
         lowercase_      :str         =			map(__lowerCamelCase     ,function=lambda __lowerCamelCase			: None     ,batched=__lowerCamelCase			)

      lowercase_      :int         =			map(__lowerCamelCase     ,function=__lowerCamelCase     ,batched=__lowerCamelCase			)

      lowercase_      :Tuple         =			filter(__lowerCamelCase			)

      # Activate later when tokenizer support batched inputs
      # with dataset.formatted_as(type='numpy'):
      #     times[func.__name__ + " fast-tokenizer batched numpy"] = func(dataset, function=tokenize, batched=True)

   with open(__lowerCamelCase     ,"wb"			) as f:
      f.write(json.dumps(__lowerCamelCase			).encode("utf-8"			)			)


if __name__ == "__main__":  # useful to run the profiler
 benchmark_map_filter()









'''simple docstring'''


import numpy as np
def 							UpperCAmelCase_  (						__lowerCamelCase : str     ,__lowerCamelCase : Optional[Any]     ,__lowerCamelCase : int     ,__lowerCamelCase : List[str]     ,__lowerCamelCase : List[Any]			):
   lowercase_      :Dict         =			int(np.ceil((x_end - xa) / h			)			)
   lowercase_      :Optional[int]         =			np.zeros((n + 1,)			)
   lowercase_      :Tuple         =			ya
   lowercase_      :List[str]         =			xa

   for k in range(__lowerCamelCase			):
      lowercase_      :Any         =			f(__lowerCamelCase     ,y[k]			)
      lowercase_      :Optional[Any]         =			f(x + 0.5 * h     ,y[k] + 0.5 * h * ka			)
      lowercase_      :Optional[Any]         =			f(x + 0.5 * h     ,y[k] + 0.5 * h * ka			)
      lowercase_      :Any         =			f(x + h     ,y[k] + h * ka			)
      lowercase_      :Tuple         =			y[k] + (1 / 6) * h * (ka + 2 * ka + 2 * ka + ka)
      x += h

   return y


if __name__ == "__main__":
 import doctest

 doctest.testmod()


