





import itertools
from dataclasses import dataclass
from typing import Optional

import pandas as pd
import pyarrow as pa

import datasets
from datasets.table import table_cast



@dataclass
class  A__       (	datasets.BuilderConfig      ):
      _UpperCAmelCase     :Optional[datasets.Features]						   =       None



class  A__       (	datasets.ArrowBasedBuilder      ):
      _UpperCAmelCase     :str						   =       PandasConfig





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       return datasets.DatasetInfo(features=self.config.features       )





      def 	__UpperCamelCase(			self	,							A_       ):
       '''simple docstring'''




       if not self.config.data_files:
        raise ValueError(F"""At least one data file must be specified, but got data_files={self.config.data_files}"""       )
       UpperCamelCase     : Any	     =       dl_manager.download_and_extract(self.config.data_files       )
       if isinstance(A_	,							(str, list, tuple)       ):
        UpperCamelCase     : Dict	     =       data_files
        if isinstance(A_	,							A_       ):
         UpperCamelCase     : Any	     =       [files]
        # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
        UpperCamelCase     : Union[str, Any]	     =       [dl_manager.iter_files(A_       ) for file in files]
        return [datasets.SplitGenerator(name=datasets.Split.TRAIN	,							gen_kwargs={"files": files}       )]
       UpperCamelCase     : Union[str, Any]	     =       []
       for split_name, files in data_files.items():
        if isinstance(A_	,							A_       ):
         UpperCamelCase     : List[Any]	     =       [files]
        # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
        UpperCamelCase     : str	     =       [dl_manager.iter_files(A_       ) for file in files]
        splits.append(datasets.SplitGenerator(name=A_	,							gen_kwargs={"files": files}       )       )
       return splits





      def 	__UpperCamelCase(			self	,							A_       ):
       '''simple docstring'''




       if self.config.features is not None:
        # more expensive cast to support nested features with keys in a different order
        # allows str <-> int/float or str to Audio for example
        UpperCamelCase     : Optional[Any]	     =       table_cast(A_	,							self.config.features.arrow_schema       )
       return pa_table





      def 	__UpperCamelCase(			self	,							A_       ):
       '''simple docstring'''




       for i, file in enumerate(itertools.chain.from_iterable(A_       )       ):
        with open(A_	,							"rb"       ) as f:
         UpperCamelCase     : List[Any]	     =       pa.Table.from_pandas(pd.read_pickle(A_       )       )
         yield i, self._cast_table(A_       )







from __future__ import annotations

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



def 		A_    (					_lowerCAmelCase							,       _lowerCAmelCase							,       _lowerCAmelCase							,       _lowerCAmelCase							,       )						->			list[float]:
 UpperCamelCase     ,   UpperCamelCase     : List[Any]	     =       coefficient_matrix.shape
 UpperCamelCase     ,   UpperCamelCase     : Optional[int]	     =       constant_matrix.shape

 if rowsa != colsa:
  UpperCamelCase     : List[Any]	     =       F"""Coefficient matrix dimensions must be nxn but received {rowsa}x{colsa}"""
  raise ValueError(_lowerCAmelCase					)

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

 if rowsa != rowsa:
  UpperCamelCase     : Tuple	     =       (
      "Coefficient and constant matrices dimensions must be nxn and nx1 but "
      F"""received {rowsa}x{colsa} and {rowsa}x{colsa}"""
  )
  raise ValueError(_lowerCAmelCase					)

 if len(_lowerCAmelCase					) != rowsa:
  UpperCamelCase     : Any	     =       (
      "Number of initial values must be equal to number of rows in coefficient "
      F"""matrix but received {len(_lowerCAmelCase					)} and {rowsa}"""
  )
  raise ValueError(_lowerCAmelCase					)

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

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

 UpperCamelCase     ,   UpperCamelCase     : str	     =       table.shape

 strictly_diagonally_dominant(_lowerCAmelCase					)

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

 return [float(_lowerCAmelCase					) for i in new_val]



def 		A_    (					_lowerCAmelCase					)						->			bool:
 UpperCamelCase     ,   UpperCamelCase     : Dict	     =       table.shape

 UpperCamelCase     : List[Any]	     =       True

 for i in range(0							,       _lowerCAmelCase					):
  UpperCamelCase     : Union[str, 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()
