


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


     """simple docstring"""


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


__snake_case   							=						generate_large_matrix()
__snake_case   							=						(
    [[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 		_A		(		_lowercase )					-> None:


     """simple docstring"""


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






def 		_A		(		_lowercase )					-> int:


     """simple docstring"""


     __UpperCamelCase =			0
     __UpperCamelCase =			len(_lowercase ) - 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:
          __UpperCamelCase =			(left + right) // 2
          __UpperCamelCase =			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:
               __UpperCamelCase =			mid + 1
          else:
               __UpperCamelCase =			mid - 1
    # No negative numbers so return the last index of the array + 1 which is the length.
     return len(_lowercase )






def 		_A		(		_lowercase )					-> int:


     """simple docstring"""


     __UpperCamelCase =			0
     __UpperCamelCase =			len(grid[0] )

     for i in range(len(_lowercase ) ):
          __UpperCamelCase =			find_negative_index(grid[i][:bound] )
          total += bound
     return (len(_lowercase ) * len(grid[0] )) - total






def 		_A		(		_lowercase )					-> int:


     """simple docstring"""


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






def 		_A		(		_lowercase )					-> int:


     """simple docstring"""


     __UpperCamelCase =			0
     for row in grid:
          for i, number in enumerate(_lowercase ):
               if number < 0:
                    total += len(_lowercase ) - i
                    break
     return total






def 		_A		(		)					-> None:


     """simple docstring"""


     from timeit import timeit

     print('Running benchmarks' )
     __UpperCamelCase =			(
         '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
     ):
          __UpperCamelCase =			timeit(f'''{func}(grid=grid)'''					,  setup=_lowercase					,  number=5_00 )
          print(f'''{func}() took {time:0.4f} seconds''' )


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    benchmark()








import math

import tensorflow as tf
from packaging import version




def 		lowerCAmelCase_ (						lowerCamelCase ):
				__magic_name__						:						str										=tf.convert_to_tensor(lowerCamelCase )
				__magic_name__						:						List[str]										=0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0 )						,  x.dtype ) ))

				return x * cdf




def 		lowerCAmelCase_ (						lowerCamelCase ):
				__magic_name__						:						str										=tf.convert_to_tensor(lowerCamelCase )
				__magic_name__						:						Optional[Any]										=tf.cast(math.pi						,  x.dtype )
				__magic_name__						:						int										=tf.cast(0.0_4_4_7_1_5						,  x.dtype )
				__magic_name__						:						Tuple										=0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi ) * (x + coeff * tf.pow(lowerCamelCase						,  3 )) ))

				return x * cdf




def 		lowerCAmelCase_ (						lowerCamelCase ):
				__magic_name__						:						Any										=tf.convert_to_tensor(lowerCamelCase )

				return x * tf.tanh(tf.math.softplus(lowerCamelCase ) )




def 		lowerCAmelCase_ (						lowerCamelCase ):
				__magic_name__						:						Optional[Any]										=tf.convert_to_tensor(lowerCamelCase )
				__magic_name__						:						Union[str, Any]										=tf.cast(0.0_4_4_7_1_5						,  x.dtype )
				__magic_name__						:						Tuple										=tf.cast(0.7_9_7_8_8_4_5_6_0_8						,  x.dtype )

				return 0.5 * x * (1.0 + tf.tanh(x * coeffa * (1.0 + coeffa * x * x) ))




def 		lowerCAmelCase_ (						lowerCamelCase ):
				__magic_name__						:						List[str]										=tf.convert_to_tensor(lowerCamelCase )
				__magic_name__						:						Dict										=tf.cast(1.7_0_2						,  x.dtype )
				return x * tf.math.sigmoid(coeff * x )




def 		lowerCAmelCase_ (						lowerCamelCase ):
				return tf.clip_by_value(_gelu(lowerCamelCase )						,  -10						,  10 )




def 		lowerCAmelCase_ (						lowerCamelCase						,  lowerCamelCase=-1 ):
				__magic_name__					,			__magic_name__						:						List[Any]										=tf.split(lowerCamelCase						,  2						,  axis=lowerCamelCase )
				return a * tf.math.sigmoid(lowerCamelCase )


if version.parse(tf.version.VERSION) >= version.parse("2.4"):




							def 		lowerCAmelCase_ (						lowerCamelCase ):
											return tf.keras.activations.gelu(lowerCamelCase						,  approximate=lowerCamelCase )

							UpperCAmelCase_		:					List[str]          =  tf.keras.activations.gelu



							UpperCAmelCase_		:					Dict          =  approximate_gelu_wrap
else:
							UpperCAmelCase_		:					Dict          =  _gelu
							UpperCAmelCase_		:					str          =  _gelu_new


UpperCAmelCase_		:					Any          =  {
    "gelu": gelu,
    "gelu_10": gelu_aa,
    "gelu_fast": gelu_fast,
    "gelu_new": gelu_new,
    "glu": glu,
    "mish": mish,
    "quick_gelu": quick_gelu,
    "relu": tf.keras.activations.relu,
    "sigmoid": tf.keras.activations.sigmoid,
    "silu": tf.keras.activations.swish,
    "swish": tf.keras.activations.swish,
    "tanh": tf.keras.activations.tanh,
}




def 		lowerCAmelCase_ (						lowerCamelCase ):
				if activation_string in ACTaFN:
								return ACTaFN[activation_string]
				else:
								raise KeyError(F"function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys() )}" )




