

'''simple docstring'''

import csv
import os

import pytest

from datasets import Dataset, DatasetDict, Features, NamedSplit, Value
from datasets.io.csv import CsvDatasetReader, CsvDatasetWriter

from ..utils import assert_arrow_memory_doesnt_increase, assert_arrow_memory_increases

def 				__UpperCamelCase							(	lowercase__						:  List[str],					lowercase__						:  Union[str, Any] ):






     '''simple docstring'''





     assert isinstance(lowercase__,					lowercase__ )
     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 				__UpperCamelCase							(	lowercase__						:  Tuple,					lowercase__						:  Union[str, Any],					lowercase__						:  List[Any] ):






     '''simple docstring'''





     __lowercase					=tmp_path / 'cache'
     __lowercase					={'col_1': 'int64', 'col_2': 'int64', 'col_3': 'float64'}
     with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
          __lowercase					=CsvDatasetReader(lowercase__,					cache_dir=lowercase__,					keep_in_memory=lowercase__ ).read()
     _check_csv_dataset(lowercase__,					lowercase__ )

@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 				__UpperCamelCase							(	lowercase__						:  Optional[int],					lowercase__						:  int,					lowercase__						:  Optional[int] ):






     '''simple docstring'''





     __lowercase					=tmp_path / 'cache'
     # CSV file loses col_1 string dtype information: default now is "int64" instead of "string"
     __lowercase					={'col_1': 'int64', 'col_2': 'int64', 'col_3': 'float64'}
     __lowercase					=features.copy() if features else default_expected_features
     __lowercase					=(
         Features({feature: Value(lowercase__ ) for feature, dtype in features.items()} ) if features is not None else None
     )
     __lowercase					=CsvDatasetReader(lowercase__,					features=lowercase__,					cache_dir=lowercase__ ).read()
     _check_csv_dataset(lowercase__,					lowercase__ )

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






     '''simple docstring'''





     __lowercase					=tmp_path / 'cache'
     __lowercase					={'col_1': 'int64', 'col_2': 'int64', 'col_3': 'float64'}
     __lowercase					=CsvDatasetReader(lowercase__,					cache_dir=lowercase__,					split=lowercase__ ).read()
     _check_csv_dataset(lowercase__,					lowercase__ )
     assert dataset.split == split if split else "train"

@pytest.mark.parametrize('path_type',					[str, list] )
def 				__UpperCamelCase							(	lowercase__						:  Tuple,					lowercase__						:  Optional[int],					lowercase__						:  int ):






     '''simple docstring'''





     if issubclass(lowercase__,					lowercase__ ):
          __lowercase					=csv_path
     elif issubclass(lowercase__,					lowercase__ ):
          __lowercase					=[csv_path]
     __lowercase					=tmp_path / 'cache'
     __lowercase					={'col_1': 'int64', 'col_2': 'int64', 'col_3': 'float64'}
     __lowercase					=CsvDatasetReader(lowercase__,					cache_dir=lowercase__ ).read()
     _check_csv_dataset(lowercase__,					lowercase__ )

def 				__UpperCamelCase							(	lowercase__						:  Union[str, Any],					lowercase__						:  Dict,					lowercase__						:  List[str]=("train",) ):






     '''simple docstring'''





     assert isinstance(lowercase__,					lowercase__ )
     for split in splits:
          __lowercase					=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 				__UpperCamelCase							(	lowercase__						:  int,					lowercase__						:  Union[str, Any],					lowercase__						:  Any ):






     '''simple docstring'''





     __lowercase					=tmp_path / 'cache'
     __lowercase					={'col_1': 'int64', 'col_2': 'int64', 'col_3': 'float64'}
     with assert_arrow_memory_increases() if keep_in_memory else assert_arrow_memory_doesnt_increase():
          __lowercase					=CsvDatasetReader({'train': csv_path},					cache_dir=lowercase__,					keep_in_memory=lowercase__ ).read()
     _check_csv_datasetdict(lowercase__,					lowercase__ )

@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 				__UpperCamelCase							(	lowercase__						:  Tuple,					lowercase__						:  Optional[int],					lowercase__						:  List[str] ):






     '''simple docstring'''





     __lowercase					=tmp_path / 'cache'
     # CSV file loses col_1 string dtype information: default now is "int64" instead of "string"
     __lowercase					={'col_1': 'int64', 'col_2': 'int64', 'col_3': 'float64'}
     __lowercase					=features.copy() if features else default_expected_features
     __lowercase					=(
         Features({feature: Value(lowercase__ ) for feature, dtype in features.items()} ) if features is not None else None
     )
     __lowercase					=CsvDatasetReader({'train': csv_path},					features=lowercase__,					cache_dir=lowercase__ ).read()
     _check_csv_datasetdict(lowercase__,					lowercase__ )

@pytest.mark.parametrize('split',					[None, NamedSplit('train' ), 'train', 'test'] )
def 				__UpperCamelCase							(	lowercase__						:  Any,					lowercase__						:  Dict,					lowercase__						:  Any ):






     '''simple docstring'''





     if split:
          __lowercase					={split: csv_path}
     else:
          __lowercase					={'train': csv_path, 'test': csv_path}
     __lowercase					=tmp_path / 'cache'
     __lowercase					={'col_1': 'int64', 'col_2': 'int64', 'col_3': 'float64'}
     __lowercase					=CsvDatasetReader(lowercase__,					cache_dir=lowercase__ ).read()
     _check_csv_datasetdict(lowercase__,					lowercase__,					splits=list(path.keys() ) )
     assert all(dataset[split].split == split for split in path.keys() )

def 				__UpperCamelCase							(	lowercase__						:  List[str] ):






     '''simple docstring'''





     with open(lowercase__,					encoding='utf-8' ) as csvfile:
          yield from csv.reader(lowercase__ )

def 				__UpperCamelCase							(	lowercase__						:  Optional[int],					lowercase__						:  Union[str, Any] ):






     '''simple docstring'''





     __lowercase					=tmp_path / 'cache'
     __lowercase					=os.path.join(lowercase__,					'tmp.csv' )
     __lowercase					=CsvDatasetReader({'train': csv_path},					cache_dir=lowercase__ ).read()
     CsvDatasetWriter(dataset['train'],					lowercase__,					num_proc=1 ).write()

     __lowercase					=iter_csv_file(lowercase__ )
     __lowercase					=iter_csv_file(lowercase__ )

     for rowa, rowa in zip(lowercase__,					lowercase__ ):
          assert rowa == rowa

def 				__UpperCamelCase							(	lowercase__						:  Dict,					lowercase__						:  List[str] ):






     '''simple docstring'''





     __lowercase					=tmp_path / 'cache'
     __lowercase					=os.path.join(lowercase__,					'tmp.csv' )
     __lowercase					=CsvDatasetReader({'train': csv_path},					cache_dir=lowercase__ ).read()
     CsvDatasetWriter(dataset['train'],					lowercase__,					num_proc=2 ).write()

     __lowercase					=iter_csv_file(lowercase__ )
     __lowercase					=iter_csv_file(lowercase__ )

     for rowa, rowa in zip(lowercase__,					lowercase__ ):
          assert rowa == rowa







def 				__UpperCamelCase							(	lowercase__						:  str,					lowercase__						:  Tuple ):






     '''simple docstring'''





     __lowercase					=tmp_path / 'cache'
     __lowercase					=os.path.join(lowercase__,					'tmp.csv' )
     __lowercase					=CsvDatasetReader({'train': csv_path},					cache_dir=lowercase__ ).read()
     with pytest.raises(lowercase__ ):
          CsvDatasetWriter(dataset['train'],					lowercase__,					num_proc=0 )





'''simple docstring'''

from __future__ import annotations

from pathlib import Path

def 				__UpperCamelCase							(	lowercase__						:  tuple[int, int],					lowercase__						:  tuple[int, int] ):






     '''simple docstring'''





     return pointa[0] * pointa[1] - pointa[1] * pointa[0]

def 				__UpperCamelCase							(	lowercase__						:  int,					lowercase__						:  int,					lowercase__						:  int,					lowercase__						:  int,					lowercase__						:  int,					lowercase__						:  int ):






     '''simple docstring'''





     __lowercase					=(xa, ya)
     __lowercase					=(xa - xa, ya - ya)
     __lowercase					=(xa - xa, ya - ya)
     __lowercase					=-vector_product(lowercase__,					lowercase__ ) / vector_product(
         lowercase__,					lowercase__ )
     __lowercase					=+vector_product(lowercase__,					lowercase__ ) / vector_product(
         lowercase__,					lowercase__ )

     return a > 0 and b > 0 and a + b < 1

def 				__UpperCamelCase							(	lowercase__						:  str = "p102_triangles.txt" ):






     '''simple docstring'''





     __lowercase					=Path(lowercase__ ).parent.joinpath(lowercase__ ).read_text(encoding='utf-8' )

     __lowercase					=[]
     for line in data.strip().split('\n' ):
          triangles.append([int(lowercase__ ) for number in line.split(',' )] )

     __lowercase					=0
     __lowercase					=42

     for triangle in triangles:
          ret += contains_origin(*lowercase__ )

     return ret


if __name__ == "__main__":
       print(F'''{solution() = }''')


