




import json
import os
import tempfile

import transformers

import datasets
from utils import generate_example_dataset, get_duration


UpperCamelCase								=					50_0000

UpperCamelCase						,  UpperCamelCase								=					os.path.split(__file__)
UpperCamelCase								=					os.path.join(RESULTS_BASEPATH, 'results', RESULTS_FILENAME.replace('.py', '.json'))



@get_duration
def 							_A       (						lowerCAmelCase_					: datasets.Dataset       ,    **lowerCAmelCase_					: str      ):
     """simple docstring"""

     lowerCAmelCase__          =			dataset.map(**lowerCAmelCase_      )



@get_duration
def 							_A       (						lowerCAmelCase_					: datasets.Dataset       ,    **lowerCAmelCase_					: str      ):
     """simple docstring"""

     lowerCAmelCase__          =			dataset.filter(**lowerCAmelCase_      )



def 							_A       (						):
     """simple docstring"""

     lowerCAmelCase__          =			{"num examples": SPEED_TEST_N_EXAMPLES}
     with tempfile.TemporaryDirectory() as tmp_dir:
          lowerCAmelCase__          =			datasets.Features({"text": datasets.Value("string"      ), "numbers": datasets.Value("float32"      )}      )
          lowerCAmelCase__          =			generate_example_dataset(
              os.path.join(lowerCAmelCase_       ,    "dataset.arrow"      )       ,    lowerCAmelCase_       ,    num_examples=lowerCAmelCase_      )

          lowerCAmelCase__          =			transformers.AutoTokenizer.from_pretrained("bert-base-cased"       ,    use_fast=lowerCAmelCase_      )

          def tokenize(lowerCAmelCase_					: int      ):
               return tokenizer(examples["text"]      )

          lowerCAmelCase__          =			map(lowerCAmelCase_      )

          lowerCAmelCase__          =			map(lowerCAmelCase_       ,    batched=lowerCAmelCase_      )

          lowerCAmelCase__          =			map(lowerCAmelCase_       ,    function=lambda lowerCAmelCase_      : None       ,    batched=lowerCAmelCase_      )

          with dataset.formatted_as(type="numpy"      ):
               lowerCAmelCase__          =			map(lowerCAmelCase_       ,    function=lambda lowerCAmelCase_      : None       ,    batched=lowerCAmelCase_      )

          with dataset.formatted_as(type="pandas"      ):
               lowerCAmelCase__          =			map(lowerCAmelCase_       ,    function=lambda lowerCAmelCase_      : None       ,    batched=lowerCAmelCase_      )

          with dataset.formatted_as(type="torch"       ,    columns="numbers"      ):
               lowerCAmelCase__          =			map(lowerCAmelCase_       ,    function=lambda lowerCAmelCase_      : None       ,    batched=lowerCAmelCase_      )

          with dataset.formatted_as(type="tensorflow"       ,    columns="numbers"      ):
               lowerCAmelCase__          =			map(lowerCAmelCase_       ,    function=lambda lowerCAmelCase_      : None       ,    batched=lowerCAmelCase_      )

          lowerCAmelCase__          =			map(lowerCAmelCase_       ,    function=lowerCAmelCase_       ,    batched=lowerCAmelCase_      )

          lowerCAmelCase__          =			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()






from maths.prime_factors import prime_factors



def 							_A       (						lowerCAmelCase_					: int      ):
     """simple docstring"""

     if not isinstance(lowerCAmelCase_       ,    lowerCAmelCase_      ):
          lowerCAmelCase__          =			F'Input value of [number={number}] must be an integer'
          raise TypeError(lowerCAmelCase_      )
     if number < 1:
          raise ValueError("Input must be a positive integer"      )
     return -1 if len(prime_factors(lowerCAmelCase_      )      ) % 2 else 1


if __name__ == "__main__":
     import doctest

     doctest.testmod()
