





"""simple docstring"""




from __future__ import annotations

import numpy as np
from numpy import floataa
from numpy.typing import NDArray





def 	a_    (							_lowercase	,						_lowercase	,						_lowercase	,						_lowercase	,						):
						_UpperCamelCase       ,							_UpperCamelCase      : Dict         =   coefficient_matrix.shape
						_UpperCamelCase       ,							_UpperCamelCase      : Tuple         =   constant_matrix.shape

						if rowsa != colsa:
												_UpperCamelCase      : Union[str, Any]         =   F"""Coefficient matrix dimensions must be nxn but received {rowsa}x{colsa}"""
												raise ValueError(_lowercase       )

						if colsa != 1:
												_UpperCamelCase      : Any         =   F"""Constant matrix must be nx1 but received {rowsa}x{colsa}"""
												raise ValueError(_lowercase       )

						if rowsa != rowsa:
												_UpperCamelCase      : List[str]         =   (
												    '''Coefficient and constant matrices dimensions must be nxn and nx1 but '''
												    F"""received {rowsa}x{colsa} and {rowsa}x{colsa}"""
												)
												raise ValueError(_lowercase       )

						if len(_lowercase       ) != rowsa:
												_UpperCamelCase      : Union[str, Any]         =   (
												    '''Number of initial values must be equal to number of rows in coefficient '''
												    F"""matrix but received {len(_lowercase       )} and {rowsa}"""
												)
												raise ValueError(_lowercase       )

						if iterations <= 0:
												raise ValueError('''Iterations must be at least 1'''       )

						_UpperCamelCase      : NDArray[floataa]         =   np.concatenate(
						    (coefficient_matrix, constant_matrix)	,						axis=1       )

						_UpperCamelCase       ,							_UpperCamelCase      : List[str]         =   table.shape

						strictly_diagonally_dominant(_lowercase       )

						# Iterates the whole matrix for given number of times
						for _ in range(_lowercase       ):
												_UpperCamelCase      : Dict         =   []
												for row in range(_lowercase       ):
																		_UpperCamelCase      : Dict         =   0
																		for col in range(_lowercase       ):
																								if col == row:
																														_UpperCamelCase      : List[Any]         =   table[row][col]
																								elif col == cols - 1:
																														_UpperCamelCase      : Any         =   table[row][col]
																								else:
																														temp += (-1) * table[row][col] * init_val[col]
																		_UpperCamelCase      : Optional[Any]         =   (temp + val) / denom
																		new_val.append(_lowercase       )
												_UpperCamelCase      : Any         =   new_val

						return [float(_lowercase       ) for i in new_val]





def 	a_    (							_lowercase       ):
						_UpperCamelCase       ,							_UpperCamelCase      : int         =   table.shape

						_UpperCamelCase      : Tuple         =   True

						for i in range(0	,						_lowercase       ):
												_UpperCamelCase      : List[Any]         =   0
												for j in range(0	,						cols - 1       ):
																		if i == j:
																								continue
																		else:
																								total += table[i][j]

												if table[i][i] <= total:
																		raise ValueError('''Coefficient matrix is not strictly diagonally dominant'''       )

						return is_diagonally_dominant


# Test Cases
if __name__ == "__main__":
						import doctest

						doctest.testmod()










"""simple docstring"""




class 			_a						:






				def __init__(			self		:   Optional[int],			lowerCAmelCase__		:   list							)     ->				None:




										'''simple docstring'''



										_UpperCamelCase      : Optional[int]         =   set_counts
										_UpperCamelCase      : Any         =   max(lowerCAmelCase__							)
										_UpperCamelCase      : int         =   len(lowerCAmelCase__							)
										_UpperCamelCase      : int         =   [1] * num_sets
										_UpperCamelCase      : List[Any]         =   list(range(lowerCAmelCase__							)							)






				def     snake_case     (			self		:   int,			lowerCAmelCase__		:   int,			lowerCAmelCase__		:   int							)     ->				bool:




										'''simple docstring'''



										_UpperCamelCase      : Optional[Any]         =   self.get_parent(lowerCAmelCase__							)
										_UpperCamelCase      : Any         =   self.get_parent(lowerCAmelCase__							)

										if src_parent == dst_parent:
																return False

										if self.ranks[dst_parent] >= self.ranks[src_parent]:
																self.set_counts[dst_parent] += self.set_counts[src_parent]
																_UpperCamelCase      : List[Any]         =   0
																_UpperCamelCase      : str         =   dst_parent
																if self.ranks[dst_parent] == self.ranks[src_parent]:
																						self.ranks[dst_parent] += 1
																_UpperCamelCase      : Union[str, Any]         =   self.set_counts[dst_parent]
										else:
																self.set_counts[src_parent] += self.set_counts[dst_parent]
																_UpperCamelCase      : Tuple         =   0
																_UpperCamelCase      : Optional[Any]         =   src_parent
																_UpperCamelCase      : int         =   self.set_counts[src_parent]

										_UpperCamelCase      : Optional[Any]         =   max(self.max_set,			lowerCAmelCase__							)
										return True






				def     snake_case     (			self		:   Optional[Any],			lowerCAmelCase__		:   int							)     ->				int:




										'''simple docstring'''



										if self.parents[disj_set] == disj_set:
																return disj_set
										_UpperCamelCase      : Union[str, Any]         =   self.get_parent(self.parents[disj_set]							)
										return self.parents[disj_set]



