
def 				SCREAMING_SNAKE_CASE     (      ) ->       list[list[int]]:

				"""simple docstring"""







				return [list(range(10_00 - i							,						-10_00 - i							,						-1       )       ) for i in range(10_00       )]


_SCREAMING_SNAKE_CASE    :      Tuple          =			generate_large_matrix()
_SCREAMING_SNAKE_CASE    :      int          =			(
    [[4, 3, 2, -1], [3, 2, 1, -1], [1, 1, -1, -2], [-1, -1, -2, -3]],
    [[3, 2], [1, 0]],
    [[7, 7, 6]],
    [[7, 7, 6], [-1, -2, -3]],
    grid,
)

def 				SCREAMING_SNAKE_CASE     (      __UpperCamelCase :						list[list[int]]       ) ->       None:

				"""simple docstring"""







				assert all(row == sorted(__UpperCamelCase							,						reverse=__UpperCamelCase       ) for row in grid       )
				assert all(list(__UpperCamelCase       ) == sorted(__UpperCamelCase							,						reverse=__UpperCamelCase       ) for col in zip(*__UpperCamelCase       )       )

def 				SCREAMING_SNAKE_CASE     (      __UpperCamelCase :						list[int]       ) ->       int:

				"""simple docstring"""







				A__  :	List[str]         =							0
				A__  :	int         =							len(__UpperCamelCase       ) - 1

				# Edge cases such as no values or all numbers are negative.
				if not array or array[0] < 0:
								return 0

				while right + 1 > left:
								A__  :	Union[str, Any]         =							(left + right) // 2
								A__  :	Optional[Any]         =							array[mid]

								# Num must be negative and the index must be greater than or equal to 0.
								if num < 0 and array[mid - 1] >= 0:
												return mid

								if num >= 0:
												A__  :	Optional[int]         =							mid + 1
								else:
												A__  :	Any         =							mid - 1
    # No negative numbers so return the last index of the array + 1 which is the length.
				return len(__UpperCamelCase       )

def 				SCREAMING_SNAKE_CASE     (      __UpperCamelCase :						list[list[int]]       ) ->       int:

				"""simple docstring"""







				A__  :	Dict         =							0
				A__  :	Dict         =							len(grid[0]       )

				for i in range(len(__UpperCamelCase       )       ):
								A__  :	Union[str, Any]         =							find_negative_index(grid[i][:bound]       )
								total += bound
				return (len(__UpperCamelCase       ) * len(grid[0]       )) - total

def 				SCREAMING_SNAKE_CASE     (      __UpperCamelCase :						list[list[int]]       ) ->       int:

				"""simple docstring"""







				return len([number for row in grid for number in row if number < 0]       )

def 				SCREAMING_SNAKE_CASE     (      __UpperCamelCase :						list[list[int]]       ) ->       int:

				"""simple docstring"""







				A__  :	Optional[Any]         =							0
				for row in grid:
								for i, number in enumerate(__UpperCamelCase       ):
												if number < 0:
																total += len(__UpperCamelCase       ) - i
																break
				return total

def 				SCREAMING_SNAKE_CASE     (      ) ->       None:

				"""simple docstring"""







				from timeit import timeit

				print('''Running benchmarks'''       )
				A__  :	Any         =							(
				    '''from __main__ import count_negatives_binary_search, '''
				    '''count_negatives_brute_force, count_negatives_brute_force_with_break, grid'''
				)
				for func in (
				    "count_negatives_binary_search",  # took 0.7727 seconds
				    "count_negatives_brute_force_with_break",  # took 4.6505 seconds
				    "count_negatives_brute_force",  # took 12.8160 seconds
				):
								A__  :	Union[str, Any]         =							timeit(F"{func}(grid=grid)"							,						setup=__UpperCamelCase							,						number=5_00       )
								print(F"{func}() took {time:0.4f} seconds"       )


if __name__ == "__main__":
					import doctest

					doctest.testmod()
					benchmark()

import inspect
import os
import unittest

import torch

import accelerate
from accelerate import debug_launcher
from accelerate.test_utils import (
    execute_subprocess_async,
    require_cpu,
    require_huggingface_suite,
    require_multi_gpu,
    require_single_gpu,
)
from accelerate.utils import patch_environment







@require_huggingface_suite
class  UpperCamelCase__		(    unittest.TestCase   ):







	'''simple docstring'''





	def   __snake_case				(			self		):
					A__  :	Dict         =							inspect.getfile(accelerate.test_utils		)
					A__  :	Any         =							os.path.sep.join(
					    mod_file.split(os.path.sep		)[:-1] + ['''scripts''', '''external_deps''', '''test_metrics.py''']		)

					from accelerate.test_utils.scripts.external_deps import test_metrics  # noqa: F401

					A__  :	Tuple         =							test_metrics





	@require_cpu
	def   __snake_case				(			self		):
					debug_launcher(self.test_metrics.main				,       num_processes=1		)





	@require_cpu
	def   __snake_case				(			self		):
					debug_launcher(self.test_metrics.main		)





	@require_single_gpu
	def   __snake_case				(			self		):
					self.test_metrics.main()





	@require_multi_gpu
	def   __snake_case				(			self		):
					print(F"Found {torch.cuda.device_count()} devices."		)
					A__  :	int         =							['''torchrun''', F"--nproc_per_node={torch.cuda.device_count()}", self.test_file_path]
					with patch_environment(omp_num_threads=1		):
									execute_subprocess_async(UpperCamelCase__				,       env=os.environ.copy()		)