

import random
import shutil
import tempfile
import unittest

import numpy as np

from transformers import TaTokenizer, TaTokenizerFast
from transformers.testing_utils import require_sentencepiece, require_torch
from transformers.utils.import_utils import is_speech_available, is_torch_available


if is_torch_available():
			pass

if is_speech_available():
			from transformers import EncodecFeatureExtractor, MusicgenProcessor


UpperCAmelCase_       :				List[str]		   =      random.Random()
def        __SCREAMING_SNAKE_CASE    (      a__						:      str ,a__						:      Dict=1.0 ,a__						:      int=None ,a__						:      List[Any]=None					)				->							Optional[int]:
	if rng is None:
		__A   : Tuple								= global_rng

	__A   : Optional[int]								= []
	for batch_idx in range(shape[0]					):
		values.append([]					)
		for _ in range(shape[1]					):
			values[-1].append(rng.random() * scale					)

	return values







@require_torch
@require_sentencepiece
class     lowerCamelCase_			(  unittest.TestCase  ):




	def 					lowerCAmelCase_					(				self	:    int       ):
		__A   : Union[str, Any]								= """facebook/musicgen-small"""
		__A   : Optional[int]								= tempfile.mkdtemp()




	def 					lowerCAmelCase_					(				self	:    List[str]				,			**__A	:    Optional[Any]       ):
		return TaTokenizer.from_pretrained(self.checkpoint				,			**__A       )




	def 					lowerCAmelCase_					(				self	:    int				,			**__A	:    Union[str, Any]       ):
		return EncodecFeatureExtractor.from_pretrained(self.checkpoint				,			**__A       )




	def 					lowerCAmelCase_					(				self	:    List[str]       ):
		shutil.rmtree(self.tmpdirname       )




	def 					lowerCAmelCase_					(				self	:    Any       ):
		__A   : Optional[Any]								= self.get_tokenizer()
		__A   : Optional[Any]								= self.get_feature_extractor()

		__A   : str								= MusicgenProcessor(tokenizer=__A				,			feature_extractor=__A       )

		processor.save_pretrained(self.tmpdirname       )
		__A   : List[Any]								= MusicgenProcessor.from_pretrained(self.tmpdirname       )

		self.assertEqual(processor.tokenizer.get_vocab()				,			tokenizer.get_vocab()       )
		self.assertIsInstance(processor.tokenizer				,			__A       )

		self.assertEqual(processor.feature_extractor.to_json_string()				,			feature_extractor.to_json_string()       )
		self.assertIsInstance(processor.feature_extractor				,			__A       )




	def 					lowerCAmelCase_					(				self	:    Any       ):
		__A   : Optional[int]								= MusicgenProcessor(tokenizer=self.get_tokenizer()				,			feature_extractor=self.get_feature_extractor()       )
		processor.save_pretrained(self.tmpdirname       )

		__A   : Optional[Any]								= self.get_tokenizer(bos_token="""(BOS)"""				,			eos_token="""(EOS)"""       )
		__A   : List[str]								= self.get_feature_extractor(do_normalize=__A				,			padding_value=1.0       )

		__A   : Optional[Any]								= MusicgenProcessor.from_pretrained(
		    self.tmpdirname				,			bos_token="""(BOS)"""				,			eos_token="""(EOS)"""				,			do_normalize=__A				,			padding_value=1.0       )

		self.assertEqual(processor.tokenizer.get_vocab()				,			tokenizer_add_kwargs.get_vocab()       )
		self.assertIsInstance(processor.tokenizer				,			__A       )

		self.assertEqual(processor.feature_extractor.to_json_string()				,			feature_extractor_add_kwargs.to_json_string()       )
		self.assertIsInstance(processor.feature_extractor				,			__A       )




	def 					lowerCAmelCase_					(				self	:    List[Any]       ):
		__A   : int								= self.get_feature_extractor()
		__A   : List[str]								= self.get_tokenizer()

		__A   : Tuple								= MusicgenProcessor(tokenizer=__A				,			feature_extractor=__A       )

		__A   : Optional[Any]								= floats_list((3, 1000)       )

		__A   : int								= feature_extractor(__A				,			return_tensors="""np"""       )
		__A   : int								= processor(__A				,			return_tensors="""np"""       )

		for key in input_feat_extract.keys():
			self.assertAlmostEqual(input_feat_extract[key].sum()				,			input_processor[key].sum()				,			delta=1e-2       )




	def 					lowerCAmelCase_					(				self	:    Union[str, Any]       ):
		__A   : Dict								= self.get_feature_extractor()
		__A   : int								= self.get_tokenizer()

		__A   : Dict								= MusicgenProcessor(tokenizer=__A				,			feature_extractor=__A       )

		__A   : Optional[int]								= """This is a test string"""

		__A   : List[str]								= processor(text=__A       )

		__A   : List[str]								= tokenizer(__A       )

		for key in encoded_tok.keys():
			self.assertListEqual(encoded_tok[key]				,			encoded_processor[key]       )




	def 					lowerCAmelCase_					(				self	:    Any       ):
		__A   : List[Any]								= self.get_feature_extractor()
		__A   : str								= self.get_tokenizer()

		__A   : Optional[int]								= MusicgenProcessor(tokenizer=__A				,			feature_extractor=__A       )

		__A   : Optional[int]								= [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

		__A   : List[str]								= processor.batch_decode(sequences=__A       )
		__A   : Any								= tokenizer.batch_decode(__A       )

		self.assertListEqual(__A				,			__A       )




	def 					lowerCAmelCase_					(				self	:    int       ):
		__A   : Optional[Any]								= self.get_feature_extractor()
		__A   : Optional[Any]								= self.get_tokenizer()

		__A   : Union[str, Any]								= MusicgenProcessor(tokenizer=__A				,			feature_extractor=__A       )

		self.assertListEqual(
		    processor.model_input_names				,			feature_extractor.model_input_names				,			msg="""`processor` and `feature_extractor` model input names do not match"""				,			)




	def 					lowerCAmelCase_					(				self	:    List[Any]       ):
		__A   : List[str]								= self.get_feature_extractor(padding_side="""left"""       )
		__A   : Optional[Any]								= self.get_tokenizer()

		__A   : Tuple								= MusicgenProcessor(tokenizer=__A				,			feature_extractor=__A       )

		__A   : str								= [floats_list((1, x)       )[0] for x in range(5				,			20				,			5       )]
		__A   : List[str]								= processor(__A       ).padding_mask

		__A   : Dict								= np.asarray(floats_list((3, 20)       )       )[:, None, :]
		__A   : List[str]								= processor.batch_decode(__A				,			padding_mask=__A       )

		self.assertIsInstance(__A				,			__A       )

		for audio in decoded_audios:
			self.assertIsInstance(__A				,			np.ndarray       )

		self.assertTrue(decoded_audios[0].shape == (1, 10)       )
		self.assertTrue(decoded_audios[1].shape == (1, 15)       )
		self.assertTrue(decoded_audios[2].shape == (1, 20)       )








UpperCAmelCase_       :				str		   =      [
    [0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0],
    [0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0],
    [0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0],
]
def        __SCREAMING_SNAKE_CASE    (      a__						:      int ,a__						:      int ,a__						:      int ,a__						:      int					)				->							bool:
	return 0 <= row < rows and 0 <= col < cols
def        __SCREAMING_SNAKE_CASE    (      a__						:      int ,a__						:      int ,a__						:      set ,a__						:      list[list[int]]					)				->							int:
	__A   : Union[str, Any]								= len(a__					)
	__A   : Any								= len(mat[0]					)
	if is_safe(a__ ,a__ ,a__ ,a__					) and (row, col) not in seen and mat[row][col] == 1:
		seen.add((row, col)					)
		return (
		    1
		    + depth_first_search(row + 1 ,a__ ,a__ ,a__					)
		    + depth_first_search(row - 1 ,a__ ,a__ ,a__					)
		    + depth_first_search(a__ ,col + 1 ,a__ ,a__					)
		    + depth_first_search(a__ ,col - 1 ,a__ ,a__					)
		)
	else:
		return 0
def        __SCREAMING_SNAKE_CASE    (      a__						:      list[list[int]]					)				->							int:
	__A   : set								= set()

	__A   : Union[str, Any]								= 0
	for row, line in enumerate(a__					):
		for col, item in enumerate(a__					):
			if item == 1 and (row, col) not in seen:
				# Maximizing the area
				__A   : Optional[Any]								= max(a__ ,depth_first_search(a__ ,a__ ,a__ ,a__					)					)
	return max_area


if __name__ == "__main__":
			import doctest

			print(find_max_area(matrix))  # Output -> 6
			doctest.testmod()





