

"""simple docstring"""

import itertools
from dataclasses import dataclass
from typing import List, Optional

import pyarrow as pa
import pyarrow.parquet as pq

import datasets
from datasets.table import table_cast


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






@dataclass
class 			__a					(						datasets.BuilderConfig       ):





       """simple docstring"""


       __UpperCamelCase					:      int    =						10000
       __UpperCamelCase					:      Optional[List[str]]    =						None
       __UpperCamelCase					:      Optional[datasets.Features]    =						None






class 			__a					(						datasets.ArrowBasedBuilder       ):





       """simple docstring"""


       __UpperCamelCase					:      Union[str, Any]    =						ParquetConfig






       def 			SCREAMING_SNAKE_CASE_	(   self   ):





        """simple docstring"""

        return datasets.DatasetInfo(features=self.config.features   )






       def 			SCREAMING_SNAKE_CASE_	(   self			,					snake_case   ):





        """simple docstring"""

        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}"""   )
        lowerCAmelCase__   :				Dict 			=				dl_manager.download_and_extract(self.config.data_files   )
        if isinstance(snake_case			,					(str, list, tuple)   ):
         lowerCAmelCase__   :				Union[str, Any] 			=				data_files
         if isinstance(snake_case			,					snake_case   ):
          lowerCAmelCase__   :				str 			=				[files]
         # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
         lowerCAmelCase__   :				Optional[int] 			=				[dl_manager.iter_files(snake_case   ) for file in files]
         return [datasets.SplitGenerator(name=datasets.Split.TRAIN			,					gen_kwargs={"files": files}   )]
        lowerCAmelCase__   :				Union[str, Any] 			=				[]
        for split_name, files in data_files.items():
         if isinstance(snake_case			,					snake_case   ):
          lowerCAmelCase__   :				List[str] 			=				[files]
         # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
         lowerCAmelCase__   :				int 			=				[dl_manager.iter_files(snake_case   ) for file in files]
         # Infer features is they are stoed in the arrow schema
         if self.info.features is None:
          for file in itertools.chain.from_iterable(snake_case   ):
           with open(snake_case			,					"rb"   ) as f:
            lowerCAmelCase__   :				Dict 			=				datasets.Features.from_arrow_schema(pq.read_schema(snake_case   )   )
           break
         splits.append(datasets.SplitGenerator(name=snake_case			,					gen_kwargs={"files": files}   )   )
        return splits






       def 			SCREAMING_SNAKE_CASE_	(   self			,					snake_case   ):





        """simple docstring"""

        if self.info.features is not None:
         # more expensive cast to support nested features with keys in a different order
         # allows str <-> int/float or str to Audio for example
         lowerCAmelCase__   :				int 			=				table_cast(snake_case			,					self.info.features.arrow_schema   )
        return pa_table






       def 			SCREAMING_SNAKE_CASE_	(   self			,					snake_case   ):





        """simple docstring"""

        lowerCAmelCase__   :				List[str] 			=				self.info.features.arrow_schema if self.info.features is not None else None
        if self.info.features is not None and self.config.columns is not None:
         if sorted(field.name for field in schema   ) != sorted(self.config.columns   ):
          raise ValueError(
              F"""Tried to load parquet data with columns '{self.config.columns}' with mismatching features '{self.info.features}'"""   )
        for file_idx, file in enumerate(itertools.chain.from_iterable(snake_case   )   ):
         with open(snake_case			,					"rb"   ) as f:
          lowerCAmelCase__   :				Tuple 			=				pq.ParquetFile(snake_case   )
          try:
           for batch_idx, record_batch in enumerate(
               parquet_file.iter_batches(batch_size=self.config.batch_size			,					columns=self.config.columns   )   ):
            lowerCAmelCase__   :				Optional[int] 			=				pa.Table.from_batches([record_batch]   )
            # 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 F"""{file_idx}_{batch_idx}""", self._cast_table(snake_case   )
          except ValueError as e:
           logger.error(F"""Failed to read file '{file}' with error {type(snake_case   )}: {e}"""   )
           raise









"""simple docstring"""

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


_UpperCamelCase		     =    logging.get_logger(__name__)

_UpperCamelCase		     =    {
    """microsoft/focalnet-tiny""": """https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json""",
}






class 			__a					(						__magic_name__       ,	__magic_name__       ):





       """simple docstring"""


       __UpperCamelCase					:      Optional[Any]    =						'focalnet'






       def __init__(   self			,					snake_case=224			,					snake_case=4			,					snake_case=3			,					snake_case=96			,					snake_case=False			,					snake_case=[192, 384, 768, 768]			,					snake_case=[2, 2, 6, 2]			,					snake_case=[2, 2, 2, 2]			,					snake_case=[3, 3, 3, 3]			,					snake_case="gelu"			,					snake_case=4.0			,					snake_case=0.0			,					snake_case=0.1			,					snake_case=False			,					snake_case=1e-4			,					snake_case=False			,					snake_case=False			,					snake_case=False			,					snake_case=0.02			,					snake_case=1e-5			,					snake_case=32			,					snake_case=None			,					snake_case=None			,					**snake_case			,					):





        """simple docstring"""

        super().__init__(**snake_case   )

        lowerCAmelCase__   :				Optional[Any] 			=				image_size
        lowerCAmelCase__   :				Union[str, Any] 			=				patch_size
        lowerCAmelCase__   :				List[str] 			=				num_channels
        lowerCAmelCase__   :				List[str] 			=				embed_dim
        lowerCAmelCase__   :				List[Any] 			=				use_conv_embed
        lowerCAmelCase__   :				List[str] 			=				hidden_sizes
        lowerCAmelCase__   :				List[Any] 			=				depths
        lowerCAmelCase__   :				Union[str, Any] 			=				focal_levels
        lowerCAmelCase__   :				Union[str, Any] 			=				focal_windows
        lowerCAmelCase__   :				int 			=				hidden_act
        lowerCAmelCase__   :				List[Any] 			=				mlp_ratio
        lowerCAmelCase__   :				str 			=				hidden_dropout_prob
        lowerCAmelCase__   :				Union[str, Any] 			=				drop_path_rate
        lowerCAmelCase__   :				Tuple 			=				use_layerscale
        lowerCAmelCase__   :				Tuple 			=				layerscale_value
        lowerCAmelCase__   :				str 			=				use_post_layernorm
        lowerCAmelCase__   :				str 			=				use_post_layernorm_in_modulation
        lowerCAmelCase__   :				Union[str, Any] 			=				normalize_modulator
        lowerCAmelCase__   :				Optional[int] 			=				initializer_range
        lowerCAmelCase__   :				List[Any] 			=				layer_norm_eps
        lowerCAmelCase__   :				str 			=				encoder_stride
        lowerCAmelCase__   :				Union[str, Any] 			=				["stem"] + [F"""stage{idx}""" for idx in range(1			,					len(self.depths   ) + 1   )]
        lowerCAmelCase__			,						lowerCAmelCase__   :				Union[str, Any] 			=				get_aligned_output_features_output_indices(
            out_features=snake_case			,					out_indices=snake_case			,					stage_names=self.stage_names   )






