



'''simple docstring'''
import json
import os
import unittest

from transformers import AutoTokenizer, GPTaTokenizer, GPTaTokenizerFast
from transformers.models.gpta.tokenization_gpta import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin






@require_tokenizers
class 							lowercase__     (							lowercase						, unittest.TestCase       ):
	lowercase__      =      GPTaTokenizer
	lowercase__      =      GPTaTokenizerFast
	lowercase__      =      True
	lowercase__      =      {"""add_prefix_space""": True}
	lowercase__      =      False





	def      UpperCamelCase_  (			self :    List[str]			):







							'''simple docstring'''
							super().setUp()

							# Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
							_UpperCamelCase :		int			    =       [
							    'l',
							    'o',
							    'w',
							    'e',
							    'r',
							    's',
							    't',
							    'i',
							    'd',
							    'n',
							    '\u0120',
							    '\u0120l',
							    '\u0120n',
							    '\u0120lo',
							    '\u0120low',
							    'er',
							    '\u0120lowest',
							    '\u0120newer',
							    '\u0120wider',
							    '<unk>',
							    '<|endoftext|>',
							]
							_UpperCamelCase :		Tuple			    =       dict(zip(lowerCamelCase__			,range(len(lowerCamelCase__			)			)			)			)
							_UpperCamelCase :		Union[str, Any]			    =       ['#version: 0.2', '\u0120 l', '\u0120l o', '\u0120lo w', 'e r', '']
							_UpperCamelCase :		Optional[int]			    =       {'unk_token': '<unk>'}

							_UpperCamelCase :		List[str]			    =       os.path.join(self.tmpdirname			,VOCAB_FILES_NAMES['vocab_file']			)
							_UpperCamelCase :		str			    =       os.path.join(self.tmpdirname			,VOCAB_FILES_NAMES['merges_file']			)
							with open(self.vocab_file			,'w'			,encoding='utf-8'			) as fp:
													fp.write(json.dumps(lowerCamelCase__			) + '\n'			)
							with open(self.merges_file			,'w'			,encoding='utf-8'			) as fp:
													fp.write('\n'.join(lowerCamelCase__			)			)





	def      UpperCamelCase_  (			self :    Optional[Any]			,**lowerCamelCase__ :    Any			):







							'''simple docstring'''
							kwargs.update(self.special_tokens_map			)
							return GPTaTokenizer.from_pretrained(self.tmpdirname			,**lowerCamelCase__			)





	def      UpperCamelCase_  (			self :    str			,**lowerCamelCase__ :    Optional[int]			):







							'''simple docstring'''
							kwargs.update(self.special_tokens_map			)
							return GPTaTokenizerFast.from_pretrained(self.tmpdirname			,**lowerCamelCase__			)





	def      UpperCamelCase_  (			self :    Optional[int]			,lowerCamelCase__ :    Any			):







							'''simple docstring'''
							_UpperCamelCase :		Optional[Any]			    =       'lower newer'
							_UpperCamelCase :		List[Any]			    =       'lower newer'
							return input_text, output_text





	def      UpperCamelCase_  (			self :    Optional[int]			):







							'''simple docstring'''
							_UpperCamelCase :		Any			    =       GPTaTokenizer(self.vocab_file			,self.merges_file			,**self.special_tokens_map			)
							_UpperCamelCase :		List[Any]			    =       'lower newer'
							_UpperCamelCase :		str			    =       ['\u0120low', 'er', '\u0120', 'n', 'e', 'w', 'er']
							_UpperCamelCase :		List[Any]			    =       tokenizer.tokenize(lowerCamelCase__			,add_prefix_space=lowerCamelCase__			)
							self.assertListEqual(lowerCamelCase__			,lowerCamelCase__			)

							_UpperCamelCase :		List[Any]			    =       tokens + [tokenizer.unk_token]
							_UpperCamelCase :		Tuple			    =       [14, 15, 10, 9, 3, 2, 15, 19]
							self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCamelCase__			)			,lowerCamelCase__			)





	def      UpperCamelCase_  (			self :    int			):







							'''simple docstring'''
							if not self.test_rust_tokenizer:
													return

							_UpperCamelCase :		Dict			    =       self.get_tokenizer()
							_UpperCamelCase :		Any			    =       self.get_rust_tokenizer(add_prefix_space=lowerCamelCase__			)

							_UpperCamelCase :		Any			    =       'lower newer'

							# Testing tokenization
							_UpperCamelCase :		str			    =       tokenizer.tokenize(lowerCamelCase__			,add_prefix_space=lowerCamelCase__			)
							_UpperCamelCase :		Dict			    =       rust_tokenizer.tokenize(lowerCamelCase__			)
							self.assertListEqual(lowerCamelCase__			,lowerCamelCase__			)

							# Testing conversion to ids without special tokens
							_UpperCamelCase :		List[Any]			    =       tokenizer.encode(lowerCamelCase__			,add_special_tokens=lowerCamelCase__			,add_prefix_space=lowerCamelCase__			)
							_UpperCamelCase :		List[str]			    =       rust_tokenizer.encode(lowerCamelCase__			,add_special_tokens=lowerCamelCase__			)
							self.assertListEqual(lowerCamelCase__			,lowerCamelCase__			)

							# Testing conversion to ids with special tokens
							_UpperCamelCase :		Any			    =       self.get_rust_tokenizer(add_prefix_space=lowerCamelCase__			)
							_UpperCamelCase :		Optional[int]			    =       tokenizer.encode(lowerCamelCase__			,add_prefix_space=lowerCamelCase__			)
							_UpperCamelCase :		int			    =       rust_tokenizer.encode(lowerCamelCase__			)
							self.assertListEqual(lowerCamelCase__			,lowerCamelCase__			)

							# Testing the unknown token
							_UpperCamelCase :		int			    =       tokens + [rust_tokenizer.unk_token]
							_UpperCamelCase :		Optional[Any]			    =       [14, 15, 10, 9, 3, 2, 15, 19]
							self.assertListEqual(rust_tokenizer.convert_tokens_to_ids(lowerCamelCase__			)			,lowerCamelCase__			)





	def      UpperCamelCase_  (			self :    int			,*lowerCamelCase__ :    List[Any]			,**lowerCamelCase__ :    Optional[int]			):







							'''simple docstring'''
							# It's very difficult to mix/test pretokenization with byte-level
							# And get both GPT2 and Roberta to work at the same time (mostly an issue of adding a space before the string)
							pass





	def      UpperCamelCase_  (			self :    Tuple			,lowerCamelCase__ :    Optional[int]=15			):







							'''simple docstring'''
							for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
													with self.subTest(F'{tokenizer.__class__.__name__} ({pretrained_name})'			):
																			_UpperCamelCase :		List[Any]			    =       self.rust_tokenizer_class.from_pretrained(lowerCamelCase__			,**lowerCamelCase__			)

																			# Simple input
																			_UpperCamelCase :		Tuple			    =       'This is a simple input'
																			_UpperCamelCase :		List[str]			    =       ['This is a simple input 1', 'This is a simple input 2']
																			_UpperCamelCase :		Optional[Any]			    =       ('This is a simple input', 'This is a pair')
																			_UpperCamelCase :		int			    =       [
																			    ('This is a simple input 1', 'This is a simple input 2'),
																			    ('This is a simple pair 1', 'This is a simple pair 2'),
																			]

																			# Simple input tests
																			self.assertRaises(lowerCamelCase__			,tokenizer_r.encode			,lowerCamelCase__			,max_length=lowerCamelCase__			,padding='max_length'			)

																			# Simple input
																			self.assertRaises(lowerCamelCase__			,tokenizer_r.encode_plus			,lowerCamelCase__			,max_length=lowerCamelCase__			,padding='max_length'			)

																			# Simple input
																			self.assertRaises(
																			    lowerCamelCase__			,tokenizer_r.batch_encode_plus			,lowerCamelCase__			,max_length=lowerCamelCase__			,padding='max_length'			,)

																			# Pair input
																			self.assertRaises(lowerCamelCase__			,tokenizer_r.encode			,lowerCamelCase__			,max_length=lowerCamelCase__			,padding='max_length'			)

																			# Pair input
																			self.assertRaises(lowerCamelCase__			,tokenizer_r.encode_plus			,lowerCamelCase__			,max_length=lowerCamelCase__			,padding='max_length'			)

																			# Pair input
																			self.assertRaises(
																			    lowerCamelCase__			,tokenizer_r.batch_encode_plus			,lowerCamelCase__			,max_length=lowerCamelCase__			,padding='max_length'			,)





	def      UpperCamelCase_  (			self :    Union[str, Any]			):







							'''simple docstring'''
							_UpperCamelCase :		str			    =       GPTaTokenizer.from_pretrained(self.tmpdirname			,pad_token='<pad>'			)

							# Simple input
							_UpperCamelCase :		int			    =       'This is a simple input'
							_UpperCamelCase :		Union[str, Any]			    =       ['This is a simple input looooooooong', 'This is a simple input']
							_UpperCamelCase :		Union[str, Any]			    =       ('This is a simple input', 'This is a pair')
							_UpperCamelCase :		Any			    =       [
							    ('This is a simple input loooooong', 'This is a simple input'),
							    ('This is a simple pair loooooong', 'This is a simple pair'),
							]

							_UpperCamelCase :		List[str]			    =       tokenizer.pad_token_id

							_UpperCamelCase :		Optional[int]			    =       tokenizer(lowerCamelCase__			,padding='max_length'			,max_length=30			,return_tensors='np'			)
							_UpperCamelCase :		str			    =       tokenizer(lowerCamelCase__			,padding=lowerCamelCase__			,truncate=lowerCamelCase__			,return_tensors='np'			)
							_UpperCamelCase :		Dict			    =       tokenizer(*lowerCamelCase__			,padding='max_length'			,max_length=60			,return_tensors='np'			)
							_UpperCamelCase :		Union[str, Any]			    =       tokenizer(lowerCamelCase__			,padding=lowerCamelCase__			,truncate=lowerCamelCase__			,return_tensors='np'			)

							# s
							# test single string max_length padding
							self.assertEqual(out_s['input_ids'].shape[-1]			,30			)
							self.assertTrue(pad_token_id in out_s['input_ids']			)
							self.assertTrue(0 in out_s['attention_mask']			)

							# s2
							# test automatic padding
							self.assertEqual(out_sa['input_ids'].shape[-1]			,33			)
							# long slice doesn't have padding
							self.assertFalse(pad_token_id in out_sa['input_ids'][0]			)
							self.assertFalse(0 in out_sa['attention_mask'][0]			)
							# short slice does have padding
							self.assertTrue(pad_token_id in out_sa['input_ids'][1]			)
							self.assertTrue(0 in out_sa['attention_mask'][1]			)

							# p
							# test single pair max_length padding
							self.assertEqual(out_p['input_ids'].shape[-1]			,60			)
							self.assertTrue(pad_token_id in out_p['input_ids']			)
							self.assertTrue(0 in out_p['attention_mask']			)

							# p2
							# test automatic padding pair
							self.assertEqual(out_pa['input_ids'].shape[-1]			,52			)
							# long slice pair doesn't have padding
							self.assertFalse(pad_token_id in out_pa['input_ids'][0]			)
							self.assertFalse(0 in out_pa['attention_mask'][0]			)
							# short slice pair does have padding
							self.assertTrue(pad_token_id in out_pa['input_ids'][1]			)
							self.assertTrue(0 in out_pa['attention_mask'][1]			)





	def      UpperCamelCase_  (			self :    int			):







							'''simple docstring'''
							_UpperCamelCase :		Tuple			    =       '$$$'
							_UpperCamelCase :		Any			    =       GPTaTokenizer.from_pretrained(self.tmpdirname			,bos_token=lowerCamelCase__			,add_bos_token=lowerCamelCase__			)

							_UpperCamelCase :		Tuple			    =       'This is a simple input'
							_UpperCamelCase :		Union[str, Any]			    =       ['This is a simple input 1', 'This is a simple input 2']

							_UpperCamelCase :		Tuple			    =       tokenizer.bos_token_id

							_UpperCamelCase :		Optional[Any]			    =       tokenizer(lowerCamelCase__			)
							_UpperCamelCase :		Union[str, Any]			    =       tokenizer(lowerCamelCase__			)

							self.assertEqual(out_s.input_ids[0]			,lowerCamelCase__			)
							self.assertTrue(all(o[0] == bos_token_id for o in out_sa.input_ids			)			)

							_UpperCamelCase :		Union[str, Any]			    =       tokenizer.decode(out_s.input_ids			)
							_UpperCamelCase :		int			    =       tokenizer.batch_decode(out_sa.input_ids			)

							self.assertEqual(decode_s.split()[0]			,lowerCamelCase__			)
							self.assertTrue(all(d.split()[0] == bos_token for d in decode_sa			)			)





	def      UpperCamelCase_  (			self :    Union[str, Any]			):







							'''simple docstring'''
							pass





	def      UpperCamelCase_  (			self :    Union[str, Any]			):







							'''simple docstring'''
							# TODO: change to self.get_tokenizers() when the fast version is implemented
							_UpperCamelCase :		Tuple			    =       [self.get_tokenizer(do_lower_case=lowerCamelCase__			,add_bos_token=lowerCamelCase__			)]
							for tokenizer in tokenizers:
													with self.subTest(F'{tokenizer.__class__.__name__}'			):
																			_UpperCamelCase :		str			    =       'Encode this.'
																			_UpperCamelCase :		Tuple			    =       'This one too please.'
																			_UpperCamelCase :		Optional[Any]			    =       tokenizer.encode(lowerCamelCase__			,add_special_tokens=lowerCamelCase__			)
																			encoded_sequence += tokenizer.encode(lowerCamelCase__			,add_special_tokens=lowerCamelCase__			)
																			_UpperCamelCase :		Optional[int]			    =       tokenizer.encode_plus(
																			    lowerCamelCase__			,lowerCamelCase__			,add_special_tokens=lowerCamelCase__			,return_special_tokens_mask=lowerCamelCase__			,)
																			_UpperCamelCase :		Tuple			    =       encoded_sequence_dict['input_ids']
																			_UpperCamelCase :		List[Any]			    =       encoded_sequence_dict['special_tokens_mask']
																			self.assertEqual(len(lowerCamelCase__			)			,len(lowerCamelCase__			)			)

																			_UpperCamelCase :		List[str]			    =       [
																			    (x if not special_tokens_mask[i] else None) for i, x in enumerate(lowerCamelCase__			)
																			]
																			_UpperCamelCase :		int			    =       [x for x in filtered_sequence if x is not None]
																			self.assertEqual(lowerCamelCase__			,lowerCamelCase__			)






@require_tokenizers
class 							lowercase__     (							unittest.TestCase       ):





	def      UpperCamelCase_  (			self :    Optional[int]			):







							'''simple docstring'''
							# More context:
							# https://huggingface.co/wjmcat/opt-350m-paddle/discussions/1
							# https://huggingface.slack.com/archives/C01N44FJDHT/p1653511495183519
							# https://github.com/huggingface/transformers/pull/17088#discussion_r871246439

							_UpperCamelCase :		List[str]			    =       AutoTokenizer.from_pretrained('facebook/opt-350m'			,from_slow=lowerCamelCase__			)
							_UpperCamelCase :		str			    =       'A photo of a cat'

							_UpperCamelCase :		str			    =       tokenizer.encode(
							    lowerCamelCase__			,)
							self.assertEqual(lowerCamelCase__			,[2, 250, 1345, 9, 10, 4758]			)
							tokenizer.save_pretrained('test_opt'			)

							_UpperCamelCase :		Union[str, Any]			    =       AutoTokenizer.from_pretrained('./test_opt'			)
							_UpperCamelCase :		List[Any]			    =       tokenizer.encode(
							    lowerCamelCase__			,)
							self.assertEqual(lowerCamelCase__			,[2, 250, 1345, 9, 10, 4758]			)





	def      UpperCamelCase_  (			self :    Union[str, Any]			):







							'''simple docstring'''
							_UpperCamelCase :		Optional[Any]			    =       AutoTokenizer.from_pretrained('facebook/opt-350m'			,use_slow=lowerCamelCase__			)
							_UpperCamelCase :		List[str]			    =       'A photo of a cat'

							_UpperCamelCase :		List[Any]			    =       tokenizer.encode(
							    lowerCamelCase__			,)
							# Same as above
							self.assertEqual(lowerCamelCase__			,[2, 250, 1345, 9, 10, 4758]			)





	@unittest.skip('This test is failing because of a bug in the fast tokenizer'			)
	def      UpperCamelCase_  (			self :    str			):







							'''simple docstring'''
							_UpperCamelCase :		str			    =       AutoTokenizer.from_pretrained('facebook/opt-350m'			,from_slow=lowerCamelCase__			)

							_UpperCamelCase :		Optional[Any]			    =       'bos'
							_UpperCamelCase :		List[Any]			    =       tokenizer.get_vocab()['bos']

							_UpperCamelCase :		Optional[int]			    =       'A photo of a cat'
							_UpperCamelCase :		Optional[int]			    =       tokenizer.encode(
							    lowerCamelCase__			,)
							# We changed the bos token
							self.assertEqual(lowerCamelCase__			,[31957, 250, 1345, 9, 10, 4758]			)
							tokenizer.save_pretrained('./tok'			)
							_UpperCamelCase :		Any			    =       AutoTokenizer.from_pretrained('./tok'			)
							self.assertTrue(tokenizer.is_fast			)
							_UpperCamelCase :		Optional[int]			    =       tokenizer.encode(
							    lowerCamelCase__			,)
							self.assertEqual(lowerCamelCase__			,[31957, 250, 1345, 9, 10, 4758]			)







'''simple docstring'''
import itertools
import os
from collections import Counter, defaultdict
from concurrent.futures import ThreadPoolExecutor, as_completed

import numpy as np

import datasets

from .execute import check_correctness


snake_case_			:     List[str]  	=  '\\n@misc{chen2021evaluating,\n      title={Evaluating Large Language Models Trained on Code},\n      author={Mark Chen and Jerry Tworek and Heewoo Jun and Qiming Yuan \\nand Henrique Ponde de Oliveira Pinto and Jared Kaplan and Harri Edwards \\nand Yuri Burda and Nicholas Joseph and Greg Brockman and Alex Ray \\nand Raul Puri and Gretchen Krueger and Michael Petrov and Heidy Khlaaf \\nand Girish Sastry and Pamela Mishkin and Brooke Chan and Scott Gray \\nand Nick Ryder and Mikhail Pavlov and Alethea Power and Lukasz Kaiser \\nand Mohammad Bavarian and Clemens Winter and Philippe Tillet \\nand Felipe Petroski Such and Dave Cummings and Matthias Plappert \\nand Fotios Chantzis and Elizabeth Barnes and Ariel Herbert-Voss \\nand William Hebgen Guss and Alex Nichol and Alex Paino and Nikolas Tezak \\nand Jie Tang and Igor Babuschkin and Suchir Balaji and Shantanu Jain \\nand William Saunders and Christopher Hesse and Andrew N. Carr \\nand Jan Leike and Josh Achiam and Vedant Misra and Evan Morikawa \\nand Alec Radford and Matthew Knight and Miles Brundage and Mira Murati \\nand Katie Mayer and Peter Welinder and Bob McGrew and Dario Amodei \\nand Sam McCandlish and Ilya Sutskever and Wojciech Zaremba},\n      year={2021},\n      eprint={2107.03374},\n      archivePrefix={arXiv},\n      primaryClass={cs.LG}\n}\n'

snake_case_			:     Tuple  	=  '\\nThis metric implements the evaluation harness for the HumanEval problem solving dataset\ndescribed in the paper "Evaluating Large Language Models Trained on Code"\n(https://arxiv.org/abs/2107.03374).\n'


snake_case_			:     str  	=  '\nCalculates how good are predictions given some references, using certain scores\nArgs:\n    predictions: list of candidates to evaluate. Each candidates should be a list\n        of strings with several code candidates to solve the problem.\n    references: a list with a test for each prediction. Each test should evaluate the\n        correctness of a code candidate.\n    k: number of code candidates to consider in the evaluation (Default: [1, 10, 100])\n    num_workers: number of workers used to evaluate the canidate programs (Default: 4).\n    timeout:\nReturns:\n    pass_at_k: dict with pass rates for each k\n    results: dict with granular results of each unittest\nExamples:\n    >>> code_eval = datasets.load_metric("code_eval")\n    >>> test_cases = ["assert add(2,3)==5"]\n    >>> candidates = [["def add(a,b): return a*b", "def add(a, b): return a+b"]]\n    >>> pass_at_k, results = code_eval.compute(references=test_cases, predictions=candidates, k=[1, 2])\n    >>> print(pass_at_k)\n    {\'pass@1\': 0.5, \'pass@2\': 1.0}\n'


snake_case_			:     str  	=  '\n################################################################################\n                                  !!!WARNING!!!\n################################################################################\nThe "code_eval" metric executes untrusted model-generated code in Python.\nAlthough it is highly unlikely that model-generated code will do something\novertly malicious in response to this test suite, model-generated code may act\ndestructively due to a lack of model capability or alignment.\nUsers are strongly encouraged to sandbox this evaluation suite so that it\ndoes not perform destructive actions on their host or network. For more\ninformation on how OpenAI sandboxes its code, see the paper "Evaluating Large\nLanguage Models Trained on Code" (https://arxiv.org/abs/2107.03374).\n\nOnce you have read this disclaimer and taken appropriate precautions,\nset the environment variable HF_ALLOW_CODE_EVAL="1". Within Python you can to this\nwith:\n\n>>> import os\n>>> os.environ["HF_ALLOW_CODE_EVAL"] = "1"\n\n################################################################################\\n'

snake_case_			:     List[Any]  	=  'The MIT License\n\nCopyright (c) OpenAI (https://openai.com)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the "Software"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.'






@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION						, _KWARGS_DESCRIPTION       )
class 							lowercase__     (							datasets.Metric       ):





	def      UpperCamelCase_  (			self :    List[str]			):







							'''simple docstring'''
							return datasets.MetricInfo(
							    # This is the description that will appear on the metrics page.
							    description=_DESCRIPTION			,citation=_CITATION			,inputs_description=_KWARGS_DESCRIPTION			,features=datasets.Features(
							        {
							            'predictions': datasets.Sequence(datasets.Value('string'			)			),
							            'references': datasets.Value('string'			),
							        }			)			,homepage='https://github.com/openai/human-eval'			,codebase_urls=['https://github.com/openai/human-eval']			,reference_urls=['https://github.com/openai/human-eval']			,license=_LICENSE			,)





	def      UpperCamelCase_  (			self :    str			,lowerCamelCase__ :    Dict			,lowerCamelCase__ :    Dict			,lowerCamelCase__ :    List[Any]=[1, 10, 100]			,lowerCamelCase__ :    int=4			,lowerCamelCase__ :    List[Any]=3.0			):







							'''simple docstring'''

							if os.getenv('HF_ALLOW_CODE_EVAL'			,0			) != "1":
													raise ValueError(_WARNING			)

							if os.name == "nt":
													raise NotImplementedError('This metric is currently not supported on Windows.'			)

							with ThreadPoolExecutor(max_workers=lowerCamelCase__			) as executor:
													_UpperCamelCase :		Optional[int]			    =       []
													_UpperCamelCase :		Optional[int]			    =       Counter()
													_UpperCamelCase :		int			    =       0
													_UpperCamelCase :		Dict			    =       defaultdict(lowerCamelCase__			)

													for task_id, (candidates, test_case) in enumerate(zip(lowerCamelCase__			,lowerCamelCase__			)			):
																			for candidate in candidates:
																									_UpperCamelCase :		int			    =       candidate + '\n' + test_case
																									_UpperCamelCase :		Optional[Any]			    =       (test_program, timeout, task_id, completion_id[task_id])
																									_UpperCamelCase :		Dict			    =       executor.submit(lowerCamelCase__			,*lowerCamelCase__			)
																									futures.append(lowerCamelCase__			)
																									completion_id[task_id] += 1
																									n_samples += 1

													for future in as_completed(lowerCamelCase__			):
																			_UpperCamelCase :		Dict			    =       future.result()
																			results[result["task_id"]].append((result['completion_id'], result)			)

							_UpperCamelCase    ,      _UpperCamelCase :		List[str]			    =       [], []
							for result in results.values():
													result.sort()
													_UpperCamelCase :		Optional[Any]			    =       [r[1]['passed'] for r in result]
													total.append(len(lowerCamelCase__			)			)
													correct.append(sum(lowerCamelCase__			)			)
							_UpperCamelCase :		List[str]			    =       np.array(lowerCamelCase__			)
							_UpperCamelCase :		List[Any]			    =       np.array(lowerCamelCase__			)

							_UpperCamelCase :		Tuple			    =       k
							_UpperCamelCase :		Tuple			    =       {F'pass@{k}': estimate_pass_at_k(lowerCamelCase__			,lowerCamelCase__			,lowerCamelCase__			).mean() for k in ks if (total >= k).all()}

							return pass_at_k, results






def A__   (					UpperCAmelCase_  ,  UpperCAmelCase_  ,  UpperCAmelCase_							):

						def estimator(UpperCAmelCase_  ,  UpperCAmelCase_  ,  UpperCAmelCase_							) -> float:
												if n - c < k:
																		return 1.0
												return 1.0 - np.prod(1.0 - k / np.arange(n - c + 1  ,  n + 1							)							)

						if isinstance(UpperCAmelCase_  ,  UpperCAmelCase_							):
												_UpperCamelCase :		int			    =       itertools.repeat(UpperCAmelCase_  ,  len(UpperCAmelCase_							)							)
						else:
												assert len(UpperCAmelCase_							) == len(UpperCAmelCase_							)
												_UpperCamelCase :		Optional[Any]			    =       iter(UpperCAmelCase_							)

						return np.array([estimator(int(UpperCAmelCase_							)  ,  int(UpperCAmelCase_							)  ,  UpperCAmelCase_							) for n, c in zip(UpperCAmelCase_  ,  UpperCAmelCase_							)]							)


