






"""simple docstring"""


import itertools
from dataclasses import dataclass
from io import StringIO
from typing import Optional

import pyarrow as pa

import datasets
from datasets.features.features import require_storage_cast
from datasets.table import table_cast


_UpperCamelCase   :						Any     						= datasets.utils.logging.get_logger(__name__)






@dataclass
class __a   (   datasets.BuilderConfig				):
  __lowercase    :    Optional[datasets.Features]						=					None
  __lowercase    :    str						=					"utf-8"
  __lowercase    :    Optional[str]						=					None
  __lowercase    :    int						=					10 << 20  # 10MB
  __lowercase    :    bool						=					False
  __lowercase    :    str						=					"line"






class __a   (   datasets.ArrowBasedBuilder				):
  __lowercase    :    str						=					TextConfig



  def 						A_				(self  :		Optional[int]   )		->							Dict:
   return datasets.DatasetInfo(features=self.config.features   )



  def 						A_				(self  :		List[str]				,			lowercase_  :		Tuple   )		->							Optional[Any]:
   if not self.config.data_files:
    raise ValueError(f"At least one data file must be specified, but got data_files={self.config.data_files}"   )
   __A	:       str       =	dl_manager.download_and_extract(self.config.data_files   )
   if isinstance(lowercase_				,			(str, list, tuple)   ):
    __A	:       str       =	data_files
    if isinstance(lowercase_				,			lowercase_   ):
     __A	:       Optional[int]       =	[files]
    __A	:       str       =	[dl_manager.iter_files(lowercase_   ) for file in files]
    return [datasets.SplitGenerator(name=datasets.Split.TRAIN				,			gen_kwargs={'files': files}   )]
   __A	:       Tuple       =	[]
   for split_name, files in data_files.items():
    if isinstance(lowercase_				,			lowercase_   ):
     __A	:       str       =	[files]
    __A	:       str       =	[dl_manager.iter_files(lowercase_   ) for file in files]
    splits.append(datasets.SplitGenerator(name=lowercase_				,			gen_kwargs={'files': files}   )   )
   return splits



  def 						A_				(self  :		Dict				,			lowercase_  :		pa.Table   )		->							pa.Table:
   if self.config.features is not None:
    __A	:       Tuple       =	self.config.features.arrow_schema
    if all(not require_storage_cast(lowercase_   ) for feature in self.config.features.values()   ):
     # cheaper cast
     __A	:       Optional[Any]       =	pa_table.cast(lowercase_   )
    else:
     # more expensive cast; allows str <-> int/float or str to Audio for example
     __A	:       Optional[int]       =	table_cast(lowercase_				,			lowercase_   )
    return pa_table
   else:
    return pa_table.cast(pa.schema({'text': pa.string()}   )   )



  def 						A_				(self  :		int				,			lowercase_  :		List[Any]   )		->							Optional[int]:
   __A	:       List[str]       =	list(self.config.features   ) if self.config.features is not None else ['text']
   for file_idx, file in enumerate(itertools.chain.from_iterable(lowercase_   )   ):
    # open in text mode, by default translates universal newlines ("\n", "\r\n" and "\r") into "\n"
    with open(lowercase_				,			encoding=self.config.encoding				,			errors=self.config.errors   ) as f:
     if self.config.sample_by == "line":
      __A	:       Optional[int]       =	0
      while True:
       __A	:       int       =	f.read(self.config.chunksize   )
       if not batch:
        break
       batch += f.readline()  # finish current line
       # StringIO.readlines, by default splits only on "\n" (and keeps line breaks)
       __A	:       int       =	StringIO(lowercase_   ).readlines()
       if not self.config.keep_linebreaks:
        __A	:       Tuple       =	[line.rstrip('\n'   ) for line in batch]
       __A	:       List[Any]       =	pa.Table.from_arrays([pa.array(lowercase_   )]				,			names=lowercase_   )
       # Uncomment for debugging (will print the Arrow table size and elements)
       # logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
       # logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
       yield (file_idx, batch_idx), self._cast_table(lowercase_   )
       batch_idx += 1
     elif self.config.sample_by == "paragraph":
      __A	:       Dict       =	0
      __A	:       Any       =	''
      while True:
       __A	:       List[str]       =	f.read(self.config.chunksize   )
       if not new_batch:
        break
       batch += new_batch
       batch += f.readline()  # finish current line
       __A	:       Union[str, Any]       =	batch.split('\n\n'   )
       __A	:       Optional[Any]       =	pa.Table.from_arrays(
           [pa.array([example for example in batch[:-1] if example]   )]				,			names=lowercase_   )
       # Uncomment for debugging (will print the Arrow table size and elements)
       # logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
       # logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
       yield (file_idx, batch_idx), self._cast_table(lowercase_   )
       batch_idx += 1
       __A	:       List[Any]       =	batch[-1]
      if batch:
       __A	:       Optional[int]       =	pa.Table.from_arrays([pa.array([batch]   )]				,			names=lowercase_   )
       yield (file_idx, batch_idx), self._cast_table(lowercase_   )
     elif self.config.sample_by == "document":
      __A	:       Tuple       =	f.read()
      __A	:       str       =	pa.Table.from_arrays([pa.array([text]   )]				,			names=lowercase_   )
      yield file_idx, self._cast_table(lowercase_   )













"""simple docstring"""


import math




def 				a (     UpperCamelCase_							:				int		)  ->		list[int]:
 if not isinstance(UpperCamelCase_     ,	UpperCamelCase_		):
  __A	:       Any       =	F"Input value of [number={number}] must be an integer"
  raise TypeError(UpperCamelCase_		)
 if number < 1:
  __A	:       int       =	F"Input value of [number={number}] must be a positive integer"
  raise ValueError(UpperCamelCase_		)
 __A	:       Optional[Any]       =	[number]
 while number != 1:
  if number % 2 == 0:
   __A	:       Optional[int]       =	math.floor(math.sqrt(UpperCamelCase_		)		)
  else:
   __A	:       List[str]       =	math.floor(
       math.sqrt(UpperCamelCase_		) * math.sqrt(UpperCamelCase_		) * math.sqrt(UpperCamelCase_		)		)
  sequence.append(UpperCamelCase_		)
 return sequence


if __name__ == "__main__":
   import doctest

   doctest.testmod()





