


'''simple docstring'''






import pyarrow.parquet as pq
import pytest

from datasets import Audio, Dataset, DatasetDict, Features, NamedSplit, Sequence, Value, config
from datasets.features.image import Image
from datasets.io.parquet import ParquetDatasetReader, ParquetDatasetWriter, get_writer_batch_size

from ..utils import assert_arrow_memory_doesnt_increase, assert_arrow_memory_increases





def lowerCamelCase__      (						__lowerCamelCase	:							Dict	,   __lowerCamelCase	:							int							):







   '''simple docstring'''




   assert isinstance(__lowerCamelCase	,   __lowerCamelCase							)
   assert dataset.num_rows == 4
   assert dataset.num_columns == 3
   assert dataset.column_names == ["col_1", "col_2", "col_3"]
   for feature, expected_dtype in expected_features.items():
      assert dataset.features[feature].dtype == expected_dtype





@pytest.mark.parametrize('keep_in_memory'	,   [False, True]							)
def lowerCamelCase__      (						__lowerCamelCase	:							Optional[Any]	,   __lowerCamelCase	:							Optional[int]	,   __lowerCamelCase	:							Optional[Any]							):







   '''simple docstring'''




   _UpperCAmelCase       :       Optional[Any]							   =tmp_path / 'cache'
   _UpperCAmelCase       :       Optional[Any]							   ={'col_1': 'string', 'col_2': 'int64', 'col_3': 'float64'}
   with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
      _UpperCAmelCase       :       Optional[Any]							   =ParquetDatasetReader(__lowerCamelCase	,   cache_dir=__lowerCamelCase	,   keep_in_memory=__lowerCamelCase							).read()
   _check_parquet_dataset(__lowerCamelCase	,   __lowerCamelCase							)





@pytest.mark.parametrize(
    'features'	,   [
        None,
        {'col_1': 'string', 'col_2': 'int64', 'col_3': 'float64'},
        {'col_1': 'string', 'col_2': 'string', 'col_3': 'string'},
        {'col_1': 'int32', 'col_2': 'int32', 'col_3': 'int32'},
        {'col_1': 'float32', 'col_2': 'float32', 'col_3': 'float32'},
    ]	,   )
def lowerCamelCase__      (						__lowerCamelCase	:							str	,   __lowerCamelCase	:							List[str]	,   __lowerCamelCase	:							Any							):







   '''simple docstring'''




   _UpperCAmelCase       :       Optional[Any]							   =tmp_path / 'cache'
   _UpperCAmelCase       :       List[Any]							   ={'col_1': 'string', 'col_2': 'int64', 'col_3': 'float64'}
   _UpperCAmelCase       :       Optional[Any]							   =features.copy() if features else default_expected_features
   _UpperCAmelCase       :       List[str]							   =(
       Features({feature: Value(__lowerCamelCase							) for feature, dtype in features.items()}							) if features is not None else None
   )
   _UpperCAmelCase       :       int							   =ParquetDatasetReader(__lowerCamelCase	,   features=__lowerCamelCase	,   cache_dir=__lowerCamelCase							).read()
   _check_parquet_dataset(__lowerCamelCase	,   __lowerCamelCase							)





@pytest.mark.parametrize('split'	,   [None, NamedSplit('train'							), 'train', 'test']							)
def lowerCamelCase__      (						__lowerCamelCase	:							str	,   __lowerCamelCase	:							Optional[Any]	,   __lowerCamelCase	:							Optional[Any]							):







   '''simple docstring'''




   _UpperCAmelCase       :       Any							   =tmp_path / 'cache'
   _UpperCAmelCase       :       int							   ={'col_1': 'string', 'col_2': 'int64', 'col_3': 'float64'}
   _UpperCAmelCase       :       List[str]							   =ParquetDatasetReader(__lowerCamelCase	,   cache_dir=__lowerCamelCase	,   split=__lowerCamelCase							).read()
   _check_parquet_dataset(__lowerCamelCase	,   __lowerCamelCase							)
   assert dataset.split == split if split else "train"





@pytest.mark.parametrize('path_type'	,   [str, list]							)
def lowerCamelCase__      (						__lowerCamelCase	:							Optional[int]	,   __lowerCamelCase	:							Dict	,   __lowerCamelCase	:							Union[str, Any]							):







   '''simple docstring'''




   if issubclass(__lowerCamelCase	,   __lowerCamelCase							):
      _UpperCAmelCase       :       Union[str, Any]							   =parquet_path
   elif issubclass(__lowerCamelCase	,   __lowerCamelCase							):
      _UpperCAmelCase       :       Union[str, Any]							   =[parquet_path]
   _UpperCAmelCase       :       Union[str, Any]							   =tmp_path / 'cache'
   _UpperCAmelCase       :       Union[str, Any]							   ={'col_1': 'string', 'col_2': 'int64', 'col_3': 'float64'}
   _UpperCAmelCase       :       int							   =ParquetDatasetReader(__lowerCamelCase	,   cache_dir=__lowerCamelCase							).read()
   _check_parquet_dataset(__lowerCamelCase	,   __lowerCamelCase							)





def lowerCamelCase__      (						__lowerCamelCase	:							List[str]	,   __lowerCamelCase	:							Union[str, Any]	,   __lowerCamelCase	:							str=("train",)							):







   '''simple docstring'''




   assert isinstance(__lowerCamelCase	,   __lowerCamelCase							)
   for split in splits:
      _UpperCAmelCase       :       List[Any]							   =dataset_dict[split]
      assert dataset.num_rows == 4
      assert dataset.num_columns == 3
      assert dataset.column_names == ["col_1", "col_2", "col_3"]
      for feature, expected_dtype in expected_features.items():
         assert dataset.features[feature].dtype == expected_dtype





@pytest.mark.parametrize('keep_in_memory'	,   [False, True]							)
def lowerCamelCase__      (						__lowerCamelCase	:							Union[str, Any]	,   __lowerCamelCase	:							int	,   __lowerCamelCase	:							str							):







   '''simple docstring'''




   _UpperCAmelCase       :       Any							   =tmp_path / 'cache'
   _UpperCAmelCase       :       Optional[int]							   ={'col_1': 'string', 'col_2': 'int64', 'col_3': 'float64'}
   with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
      _UpperCAmelCase       :       List[Any]							   =ParquetDatasetReader(
          {'train': parquet_path}	,   cache_dir=__lowerCamelCase	,   keep_in_memory=__lowerCamelCase							).read()
   _check_parquet_datasetdict(__lowerCamelCase	,   __lowerCamelCase							)





@pytest.mark.parametrize(
    'features'	,   [
        None,
        {'col_1': 'string', 'col_2': 'int64', 'col_3': 'float64'},
        {'col_1': 'string', 'col_2': 'string', 'col_3': 'string'},
        {'col_1': 'int32', 'col_2': 'int32', 'col_3': 'int32'},
        {'col_1': 'float32', 'col_2': 'float32', 'col_3': 'float32'},
    ]	,   )
def lowerCamelCase__      (						__lowerCamelCase	:							Optional[int]	,   __lowerCamelCase	:							List[str]	,   __lowerCamelCase	:							Union[str, Any]							):







   '''simple docstring'''




   _UpperCAmelCase       :       str							   =tmp_path / 'cache'
   _UpperCAmelCase       :       Tuple							   ={'col_1': 'string', 'col_2': 'int64', 'col_3': 'float64'}
   _UpperCAmelCase       :       Any							   =features.copy() if features else default_expected_features
   _UpperCAmelCase       :       Optional[Any]							   =(
       Features({feature: Value(__lowerCamelCase							) for feature, dtype in features.items()}							) if features is not None else None
   )
   _UpperCAmelCase       :       Tuple							   =ParquetDatasetReader({'train': parquet_path}	,   features=__lowerCamelCase	,   cache_dir=__lowerCamelCase							).read()
   _check_parquet_datasetdict(__lowerCamelCase	,   __lowerCamelCase							)





@pytest.mark.parametrize('split'	,   [None, NamedSplit('train'							), 'train', 'test']							)
def lowerCamelCase__      (						__lowerCamelCase	:							Tuple	,   __lowerCamelCase	:							Union[str, Any]	,   __lowerCamelCase	:							Optional[int]							):







   '''simple docstring'''




   if split:
      _UpperCAmelCase       :       Dict							   ={split: parquet_path}
   else:
      _UpperCAmelCase       :       Optional[Any]							   ='train'
      _UpperCAmelCase       :       Any							   ={'train': parquet_path, 'test': parquet_path}
   _UpperCAmelCase       :       Any							   =tmp_path / 'cache'
   _UpperCAmelCase       :       Union[str, Any]							   ={'col_1': 'string', 'col_2': 'int64', 'col_3': 'float64'}
   _UpperCAmelCase       :       List[Any]							   =ParquetDatasetReader(__lowerCamelCase	,   cache_dir=__lowerCamelCase							).read()
   _check_parquet_datasetdict(__lowerCamelCase	,   __lowerCamelCase	,   splits=list(path.keys()							)							)
   assert all(dataset[split].split == split for split in path.keys()							)





def lowerCamelCase__      (						__lowerCamelCase	:							Optional[int]	,   __lowerCamelCase	:							str							):







   '''simple docstring'''




   _UpperCAmelCase       :       str							   =ParquetDatasetWriter(__lowerCamelCase	,   tmp_path / 'foo.parquet'							)
   assert writer.write() > 0
   _UpperCAmelCase       :       Dict							   =pq.ParquetFile(tmp_path / 'foo.parquet'							)
   _UpperCAmelCase       :       str							   =pf.read()
   assert dataset.data.table == output_table





def lowerCamelCase__      (						__lowerCamelCase	:							Optional[Any]	,   __lowerCamelCase	:							Any							):







   '''simple docstring'''




   _UpperCAmelCase       :       List[str]							   =str(shared_datadir / 'test_image_rgb.jpg'							)
   _UpperCAmelCase       :       Any							   ={'image': [image_path]}
   _UpperCAmelCase       :       int							   =Features({'image': Image()}							)
   _UpperCAmelCase       :       Any							   =Dataset.from_dict(__lowerCamelCase	,   features=__lowerCamelCase							)
   _UpperCAmelCase       :       Dict							   =ParquetDatasetWriter(__lowerCamelCase	,   tmp_path / 'foo.parquet'							)
   assert writer.write() > 0

   _UpperCAmelCase       :       Any							   =Dataset.from_parquet(str(tmp_path / 'foo.parquet'							)							)
   assert dataset.features == reloaded_dataset.features

   _UpperCAmelCase       :       Dict							   =ParquetDatasetReader(str(tmp_path / 'foo.parquet'							)	,   streaming=__lowerCamelCase							).read()
   assert dataset.features == reloaded_iterable_dataset.features





@pytest.mark.parametrize(
    'feature, expected'	,   [
        (Features({'foo': Value('int32'							)}							), None),
        (Features({'image': Image(), 'foo': Value('int32'							)}							), config.PARQUET_ROW_GROUP_SIZE_FOR_IMAGE_DATASETS),
        (Features({'nested': Sequence(Audio()							)}							), config.PARQUET_ROW_GROUP_SIZE_FOR_AUDIO_DATASETS),
    ]	,   )
def lowerCamelCase__      (						__lowerCamelCase	:							List[Any]	,   __lowerCamelCase	:							List[Any]							):







   '''simple docstring'''




   assert get_writer_batch_size(__lowerCamelCase							) == expected





'''simple docstring'''






def lowerCamelCase__      (						__lowerCamelCase	:							int	,   __lowerCamelCase	:							list[int]	,   __lowerCamelCase	:							int							):







   '''simple docstring'''




   def count_of_possible_combinations(__lowerCamelCase	:							int							) -> int:
      if target < 0:
         return 0
      if target == 0:
         return 1
      return sum(count_of_possible_combinations(target - item							) for item in array							)

   return count_of_possible_combinations(__lowerCamelCase							)





def lowerCamelCase__      (						__lowerCamelCase	:							int	,   __lowerCamelCase	:							list[int]	,   __lowerCamelCase	:							int							):







   '''simple docstring'''




   def count_of_possible_combinations_with_dp_array(
       __lowerCamelCase	:							int	,   __lowerCamelCase	:							list[int]							) -> int:
      if target < 0:
         return 0
      if target == 0:
         return 1
      if dp_array[target] != -1:
         return dp_array[target]
      _UpperCAmelCase       :       str							   =sum(
          count_of_possible_combinations_with_dp_array(target - item	,   __lowerCamelCase							)
          for item in array							)
      _UpperCAmelCase       :       Optional[Any]							   =answer
      return answer

   _UpperCAmelCase       :       int							   =[-1] * (target + 1)
   return count_of_possible_combinations_with_dp_array(__lowerCamelCase	,   __lowerCamelCase							)





def lowerCamelCase__      (						__lowerCamelCase	:							int	,   __lowerCamelCase	:							list[int]	,   __lowerCamelCase	:							int							):







   '''simple docstring'''




   _UpperCAmelCase       :       Tuple							   =[0] * (target + 1)
   _UpperCAmelCase       :       Dict							   =1

   for i in range(1	,   target + 1							):
      for j in range(__lowerCamelCase							):
         if i - array[j] >= 0:
            dp_array[i] += dp_array[i - array[j]]

   return dp_array[target]


if __name__ == "__main__":
 import doctest

 doctest.testmod()
 lowercase							=3
 lowercase							=5
 lowercase							=[1, 2, 5]
 print(combination_sum_iv(n, array, target))

