
    htg                       % S SK Jr  S SKJrJrJrJrJrJrJ	r	  S SK
Jr  S SKrS SKJr  S SKJr  S SKrS SKrS SKrS SKJr  S SKJr  / SQrS(S	 jr\\\      rS
\S'   \\\S4      rS
\S'   \\\4   r S
\S'   \RB                  \RD                     r!S
\S'   S)S jr#\" SS9S*S j5       r$ " S S5      r% " S S\RL                  5      r'S+S,S jjr(S-S jr)S.S jr*S/S jr+ " S S\'5      r,S0S jr-      S.S jr.          S1S  jr/S2S3S! jjr0S2S4S" jjr1S5S# jr2 " S$ S%\'5      r3S6S& jr4              S7S' jr5g)8    )annotations)IterableTupleListSequenceAnycastOptional)	TypeAliasN)	lru_cache)repeat)	USE_C_EXT)MatrixSolvernumpy_vector_solvernumpy_matrix_solverNumpySolvertridiagonal_vector_solvertridiagonal_matrix_solverdetect_banded_matrixcompact_banded_matrixBandedMatrixLUbanded_matrixquadratic_equationcubic_equationbinomial_coefficientc               '  D   #    [        U 6  H  n[        U5      v   M     g 7fN)ziplist)argses     C/var/www/html/env/lib/python3.13/site-packages/ezdxf/math/linalg.pyzip_to_listr$   ,   s     $Z1g s    r   
MatrixData.FrozenMatrixDataShapeNDArrayc           
         [        U [        5      (       a  U R                  n U  VVs/ s H  o Vs/ s H  n[        U5      PM     snPM      snn$ s  snf s  snnf r   
isinstancer   matrixfloat)Arowvs      r#   copy_float_matrixr1   7   sF    !VHH/01qs#s!U1Xs#q11#1s   	AAAA   )maxsizec                    X:  a  [        S5      $ [        R                  " U 5      n[        R                  " U5      n[        R                  " X-
  5      n[        X$U-  -  5      $ )zComputes the binomial coefficient (denoted by `k choose i`).

Please see the following website for details:
http://mathworld.wolfram.com/BinomialCoefficient.html

Args:
    k: size of the set of distinct elements
    i: size of the subsets

r   )r-   math	factorial)kik_facti_factk_i_facts        r#   r   r   =   sQ     	uQx..#F..#FNN15)Hf,-..    c                     \ rS rSrSrSr   S%     S&S jjrS'S jrS(S jrS)S jr	S)S	 jr
\S*S
 j5       r\S+S j5       r\S+S j5       r\S,S j5       rS-S jrS-S jrS-S jrS.S jrS.S jrS/S0S jjrS/S0S jjrS1S0S jjr\S2S j5       rS3S jrS3S jrS4S jrS5S jrS6S jrS7S jr S7S jr!S8S jr"\"r#S8S jr$\$r%S8S  jr&\&r'S4S! jr(S4S" jr)S9S# jr*S$r+g):r   T   a  Basic matrix implementation based :class:`numpy.ndarray`. Matrix data is stored in
row major order, this means in a list of rows, where each row is a list of floats.

Initialization:

    - Matrix(shape=(rows, cols)) ... new matrix filled with zeros
    - Matrix(matrix[, shape=(rows, cols)]) ... from copy of matrix and optional reshape
    - Matrix([[row_0], [row_1], ..., [row_n]]) ... from Iterable[Iterable[float]]
    - Matrix([a1, a2, ..., an], shape=(rows, cols)) ... from Iterable[float] and shape

.. versionchanged:: 1.2
    Implementation based on :class:`numpy.ndarray`.

Attributes:
    matrix: matrix data as :class:`numpy.ndarray`

)r,   abs_tolNc                   SU l         [        R                  " S[        R                  S9U l        Ub)  [        R                  " U[        R                  S9U l        g Uc   Ub  [        R
                  " U5      U l        g g [        U[        5      (       a>  Uc  UR                  nUR                  R                  U5      R                  5       U l        g [        U5      n [        R                  " U Vs/ s H  n[        U5      PM     sn[        R                  S9U l        g s  snf ! [         aH    UbB  [        R                  " [        U5      [        R                  S9R                  U5      U l         g  g f = f)N-q= dtype)r?   nparrayfloat64r,   zerosr+   r   shapereshapecopyr    	TypeError)selfitemsrI   r,   r/   s        r#   __init__Matrix.__init__i   s    $!xx"**=((6<DK=  hhuov&&},,..u5::<DKKEY hhU'CUcS	U'C2::V'C Y$"$((4;bjj"I"Q"QRW"XDK %Ys%   D& 2D!D& !D& &AE87E8c                B    [         R                  " U R                  5      $ r   )rE   ravelr,   rM   s    r#   __iter__Matrix.__iter__   s    xx$$r<   c                j    [        U R                  R                  5       S9nU R                  Ul        U$ )Nr,   )r   r,   rK   r?   rM   ms     r#   __copy__Matrix.__copy__   s)    $++**,-LL	r<   c                ,    [        U R                  5      $ r   )strr,   rS   s    r#   __str__Matrix.__str__   s    4;;r<   c                J    S[         R                  " U R                  5       S3$ )NzMatrix())reprlibreprr,   rS   s    r#   __repr__Matrix.__repr__   s    dkk23155r<   c                    [        [        R                  " [        U 5      [        R                  S9R                  U5      S9$ )zKReturns a new matrix for iterable `items` in the configuration of
`shape`.
rC   rW   )r   rE   rF   r    rG   rJ   )rN   rI   s     r#   rJ   Matrix.reshape   s-    
 RXXd5kDLLUSTTr<   c                4    U R                   R                  S   $ zCount of matrix rows.r   r,   rI   rS   s    r#   nrowsMatrix.nrows        {{  ##r<   c                4    U R                   R                  S   $ )zCount of matrix columns.   rj   rS   s    r#   ncolsMatrix.ncols   rm   r<   c                .    U R                   R                  $ )z9Shape of matrix as (n, m) tuple for n rows and m columns.rj   rS   s    r#   rI   Matrix.shape   s     {{   r<   c                2    [        U R                  U   5      $ )z&Returns row `index` as list of floats.r    r,   rM   indexs     r#   r/   
Matrix.row   s    DKK&''r<   c                :    [        U R                  SS2U4   5      $ )z(Return column `index` as list of floats.Nru   rv   s     r#   col
Matrix.col   s    DKK5)**r<   c                J    [        U R                  R                  U5      5      $ )aL  Returns diagonal `index` as list of floats.

An `index` of 0 specifies the main diagonal, negative values
specifies diagonals below the main diagonal and positive values
specifies diagonals above the main diagonal.

e.g. given a 4x4 matrix:

- index 0 is [00, 11, 22, 33],
- index -1 is [10, 21, 32] and
- index +1 is [01, 12, 23]

)r    r,   diagonalrv   s     r#   diagMatrix.diag   s     DKK((/00r<   c                :    [        S U R                   5       5      $ )zReturn a list of all rows.c              3  8   #    U  H  n[        U5      v   M     g 7fr   )r    ).0rs     r#   	<genexpr>Matrix.rows.<locals>.<genexpr>   s     1[DGG[s   ru   rS   s    r#   rowsMatrix.rows   s    1T[[111r<   c                    [        U R                  5       Vs/ s H  n[        U R                  U5      5      PM     sn$ s  snf )zReturn a list of all columns.)rangerp   r    rz   )rM   r8   s     r#   colsMatrix.cols   s2    +0+<=+<aTXXa[!+<===s   $?c                    [        U[        [        45      (       a  [        U5      /U R                  -  n[	        U5      n[        U5      U R                  :w  a  [        S5      eX R                  U'   g)z>Set row values to a fixed value or from an iterable of floats.zInvalid item countN)r+   r-   intrp   r    len
ValueErrorr,   rM   rw   rN   s      r#   set_rowMatrix.set_row   sX    eeS\**5\NTZZ/EUu:#122"Er<   c                    [        U[        [        45      (       a  [        U5      /U R                  -  n[	        U5      U R
                  SS2U4'   g)zASet column values to a fixed value or from an iterable of floats.N)r+   r-   r   rk   r    r,   r   s      r#   set_colMatrix.set_col   s=    eeS\**5\NTZZ/E $UAuHr<   c                h   [        U[        [        45      (       a  [        [        U5      5      n[	        US5      n[        [        US5      5      n[        [        [	        U R                  U R                  5      5      U5       H  u  p XPR                  X-   X-   4'   M     g! [         a       gf = f)am  Set diagonal values to a fixed value or from an iterable of floats.

An `index` of ``0`` specifies the main diagonal, negative values
specifies diagonals below the main diagonal and positive values
specifies diagonals above the main diagonal.

e.g. given a 4x4 matrix:
index ``0`` is [00, 11, 22, 33],
index ``-1`` is [10, 21, 32] and
index ``+1`` is [01, 12, 23]

r   N)r+   r-   r   r   maxabsminr   r   rk   rp   r,   
IndexError)rM   rw   rN   
col_offset
row_offsetvalues         r#   set_diagMatrix.set_diag   s     eeS\**5<(EeQ-
c%m,
c$**djj&A BEJLEFKE.0BBC K  s   
B##
B10B1c                <    [        US9nUR                  SS5        U$ )z6Returns the identity matrix for configuration `shape`.)rI   r         ?)r   r   )clsrI   rY   s      r#   identityMatrix.identity   s!     	

1cr<   c                   U R                   R                  S:X  a*  [        R                  " U/[        R                  S9U l         g[        U5      U R                  :X  a%  [        R                  U R                   U4   U l         g[        S5      e)zAppend a row to the matrix.r   rC   Invalid item count.N)	r,   sizerE   rF   rG   r   rp   r_r   )rM   rN   s     r#   
append_rowMatrix.append_row   sa    ;;q ((E7"**=DKZ4::%%%U 23DK233r<   c                F   U R                   R                  S:X  a:  [        R                  " U Vs/ s H  o"/PM     sn[        R                  S9U l         g[        U5      U R                  :X  a%  [        R                  U R                   U4   U l         g[        S5      es  snf )zAppend a column to the matrix.r   rC   r   N)	r,   r   rE   rF   rG   r   rk   c_r   )rM   rN   items      r#   
append_colMatrix.append_col  ss    ;;q ((u#=utFu#=RZZPDKZ4::%%%U 23DK233	 $>s   Bc                \    U R                  5       nSUR                  R                  l        U$ )z@Returns a frozen matrix, all data is stored in immutable tuples.F)rZ   r,   flags	writeablerX   s     r#   freezeMatrix.freeze  s"    MMO#( r<   c                2    [        U R                  U   5      $ )zZGet value by (row, col) index tuple, fancy slicing as known from
numpy is not supported.

)r-   r,   )rM   r   s     r#   __getitem__Matrix.__getitem__  s    
 T[[&''r<   c                     X R                   U'   g)zZSet value by (row, col) index tuple, fancy slicing as known from
numpy is not supported.

NrW   )rM   r   r   s      r#   __setitem__Matrix.__setitem__  s    
 "Dr<   c                    [        U[        5      (       d  [        S5      eU R                  UR                  :w  a  [        S5      e[	        [
        R                  " U R                  UR                  :H  5      5      $ )z'Returns ``True`` if matrices are equal.Matrix class required.Matrices have different shapes.)r+   r   rL   rI   boolrE   allr,   rM   others     r#   __eq__Matrix.__eq__  sX    %((455::$=>>BFF4;;%,,6788r<   c           
     .   [        U[        5      (       d  [        S5      eU R                  UR                  :w  a  [        S5      e[	        [
        R                  " [
        R                  " U R                  UR                  U R                  S95      5      $ )zReturns ``True`` if matrices are close to equal, tolerance value for
comparison is adjustable by the attribute :attr:`Matrix.abs_tol`.

r   r   )atol)
r+   r   rL   rI   r   rE   r   iscloser,   r?   r   s     r#   r   Matrix.isclose'  sf    
 %((455::$=>>BFF2::dkk5<<dllSTUUr<   c                    [        U[        5      (       a2  [        [        R                  " U R                  UR                  5      S9$ [        U R                  [        U5      -  S9nU$ )zKMatrix multiplication by another matrix or a float, returns a new
matrix.

rW   )r+   r   rE   matmulr,   r-   )rM   r   r,   s      r#   __mul__Matrix.__mul__2  sK    
 eV$$4;;!EFF4;;u#=>Fr<   c                    [        U[        5      (       a   [        U R                  UR                  -   S9$ [        U R                  [        U5      -   S9$ )zCMatrix addition by another matrix or a float, returns a new matrix.rW   r*   r   s     r#   __add__Matrix.__add__?  s?    eV$$u||!;<<uU|!;<<r<   c                    [        U[        5      (       a   [        U R                  UR                  -
  S9$ [        U R                  [        U5      -
  S9$ )zHMatrix subtraction by another matrix or a float, returns a new
matrix.

rW   r*   r   s     r#   __sub__Matrix.__sub__H  sA    
 eV$$u||!;<<uU|!;<<r<   c                <    [        U R                  R                  S9$ )z Returns a new transposed matrix.rW   )r   r,   TrS   s    r#   	transposeMatrix.transposeT  s    T[[]]++r<   c                    U R                   U R                  :w  a  [        S5      e [        [        R
                  R                  U R                  5      S9$ ! [        R
                  R                   a    [        ef = f)z(Returns inverse of matrix as new object.z+Inverse of non-square matrix not supported.rW   )
rk   rp   rL   r   rE   linalginvr,   LinAlgErrorZeroDivisionErrorrS   s    r#   inverseMatrix.inverseX  s^    ::#IJJ	$t{{!;<<yy$$ 	$##	$s   /A %A<c                f    [        [        R                  R                  U R                  5      5      $ )zYReturns determinant of matrix, raises :class:`ZeroDivisionError`
if matrix is singular.

)r-   rE   r   detr,   rS   s    r#   determinantMatrix.determinanta  s     
 RYY]]4;;/00r<   )r?   r,   )NNN)rN   r   rI   zOptional[Shape]r,   zOptional[MatrixData | NDArray])returnr(   )r   z'Matrix')r   r]   )rN   Iterable[float]rI   r'   r   r   r   r   )r   r'   )rw   r   r   list[float])r   zlist[list[float]])r   )rw   r   rN   zfloat | Iterable[float]r   None)r   r   )rI   r'   r   r   )rN   Sequence[float]r   r   )r   r   )r   tuple[int, int]r   r-   )r   r   r   r-   )r   objectr   r   )r   zMatrix | floatr   r   )r   r-   ),__name__
__module____qualname____firstlineno____doc__	__slots__rO   rT   rZ   r^   rd   staticmethodrJ   propertyrk   rp   rI   r/   rz   r~   r   r   r   r   r   classmethodr   r   r   r   r   r   r   r   r   __imul__r   __iadd__r   __isub__r   r   r   __static_attributes__rB   r<   r#   r   r   T   s7   $ &I !%15	YY Y /	Y:%
 6 U U $ $ $ $ ! !(+1 2>#,2  44("9	V	 H= H= H,$1r<   r   c                  d    \ rS rSr\R
                  SS j5       r\R
                  SS j5       rSrg)r   ii  c                    g r   rB   rM   Bs     r#   solve_matrixSolver.solve_matrixj      r<   c                    g r   rB   r   s     r#   solve_vectorSolver.solve_vectorn  r   r<   rB   Nr   MatrixData | NDArrayr   r   r   r   r   r   )	r   r   r   r   abcabstractmethodr   r   r   rB   r<   r#   r   r   i  s4      	 r<   r   c                    [        U 5      U:  a  [        U5      U:  a  U* 4$ U* U-  4$  [        R                  " US-  SU -  U-  -
  5      nU* U-   SU -  -  U* U-
  SU -  -  4$ ! [         a    [	        5       s $ f = f)zvReturns the solution for the quadratic equation ``a*x^2 + b*x + c = 0``.

Returns 0-2 solutions as a tuple of floats.
             @)r   r5   sqrtr   tuple)abcr?   discriminants        r#   r   r   s  s    
 1vq6GB5LQyyyAA	!12 R,37+\0AcAg/NOO  ws   "A% %A<;A<c                   [        U 5      S:  a   [        XU5      $ X-  nX -  nX0-  nXD-  nUS-  nSU-  U-
  S-  n	SU-  U-  SU-  -
  SXt-  -  -
  S-  n
X-  U	-  nXU
-  -   nUS:  a  [        R
                  " U5      nSn[        R                  " S	X-   5      [        R                  " [        X-   5      U5      -  n[        R                  " S	X-
  5      [        R                  " [        X-
  5      U5      -  nUU-   nUU-
  (       a  U* U-   4$ US-  nU* U-   U* U-
  U* U-
  4$ [        R                  " U
[        R
                  " U* 5      -  5      n[        R
                  " U	* 5      S-  nU[        R                  " US-  5      -  U-
  U[        R                  " US[        R                  -  -   S-  5      -  U-
  U[        R                  " US
[        R                  -  -   S-  5      -  U-
  4$ ! [         a    [        5       s $ f = f)zzReturns the solution for the cubic equation ``a*x^3 + b*x^2 + c*x + d = 0``.

Returns 0-3 solutions as a tuple of floats.
rA   g      @g      "@g      ;@r  g      K@        gUUUUUU?r   g      @)r   r   ArithmeticErrorr
  r5   r	  copysignpowacoscospi)r  r  r  dr.   r   CAAA3QRQQQDsqrtDexpSr   STST_2thsqrtQ2s                        r#   r   r     s
   
 1v~	%aA.. 	
A	A	A	
B	
SB	q2A	q1tax	#.	0D8A
%!)C1uACx		!MM#qy)DHHS^S,IIMM#qy)DHHS^S,IIUq5C"H;8Dbd
d
  
1tyy#&	'BYYr]S F"s(##b(2dgg-455:2dgg-455: ?  	7N	s   G2 2H	H	c                    [         R                  " U [         R                  S9n[         R                  " U[         R                  S9n[        [         R                  R                  X#5      S9$ )aQ  Solves the linear equation system given by a nxn Matrix A . x = B by the
numpy.linalg.solve() function.

Args:
    A: matrix [[a11, a12, ..., a1n], [a21, a22, ..., a2n], ... [an1, an2, ..., ann]]
    B: matrix [[b11, b12, ..., b1m], [b21, b22, ..., b2m], ... [bn1, bn2, ..., bnm]]

Raises:
    numpy.linalg.LinAlgError: singular matrix

rC   rW   )rE   rF   rG   r   r   solve)r.   r   mat_Amat_Bs       r#   r   r     sD     HHQbjj)EHHQbjj)E677r<   c                F   [         R                  " U [         R                  S9n[         R                  " U Vs/ s H  n[        U5      /PM     sn[         R                  S9n[	        [         R
                  " [         R                  R                  X$5      5      5      $ s  snf )aT  Solves the linear equation system given by a nxn Matrix A . x = B,
right-hand side quantities as vector B with n elements by the numpy.linalg.solve()
function.

Args:
    A: matrix [[a11, a12, ..., a1n], [a21, a22, ..., a2n], ... [an1, an2, ..., ann]]
    B: vector [b1, b2, ..., bn]

Raises:
    numpy.linalg.LinAlgError: singular matrix

rC   )rE   rF   rG   r-   r    rR   r   r'  )r.   r   r(  r0   r)  s        r#   r   r     sg     HHQbjj)EHH!,!QuQxj!,BJJ?E6788 -s   Bc                  6    \ rS rSrSrSS jrS	S jrS
S jrSrg)r   i  z5Replaces in v1.2 the :class:`LUDecomposition` solver.c                T    [         R                  " U[         R                  S9U l        g )NrC   )rE   rF   rG   r(  )rM   r.   s     r#   rO   NumpySolver.__init__  s    XXarzz2
r<   c                    [         R                  " U[         R                  S9n[        [         R                  R                  U R                  U5      S9$ )a  
Solves the linear equation system given by the nxn Matrix
A . x = B, right-hand side quantities as nxm Matrix B.

Args:
    B: matrix [[b11, b12, ..., b1m], [b21, b22, ..., b2m],
        ... [bn1, bn2, ..., bnm]]

Raises:
    numpy.linalg.LinAlgError: singular matrix

rC   rW   )rE   rF   rG   r   r   r'  r(  )rM   r   r)  s      r#   r   NumpySolver.solve_matrix  s6     "**-RYY__TZZ?@@r<   c                   [         R                  " U Vs/ s H  n[        U5      /PM     sn[         R                  S9n[	        [         R
                  " [         R                  R                  U R                  U5      5      5      $ s  snf )zSolves the linear equation system given by the nxn Matrix
A . x = B, right-hand side quantities as vector B with n elements.

Args:
    B: vector [b1, b2, ..., bn]

Raises:
    numpy.linalg.LinAlgError: singular matrix

rC   )	rE   rF   r-   rG   r    rR   r   r'  r(  )rM   r   r0   r)  s       r#   r   NumpySolver.solve_vector  sY     a0a58*a0

CBHHRYY__TZZ?@AA 1s   B)r(  N)r.   r  r   r   r   r  )	r   r   r   r   r   rO   r   r   r   rB   r<   r#   r   r     s    ?3A Br<   r   c                v    U  Vs/ s H  n[        U5      PM     snu  p4n[        X4U[        U5      5      $ s  snf )a  Solves the linear equation system given by a tri-diagonal nxn Matrix
A . x = B, right-hand side quantities as vector B. Matrix A is diagonal
matrix defined by 3 diagonals [-1 (a), 0 (b), +1 (c)].

Note: a0 is not used but has to be present, cn-1 is also not used and must
not be present.

If an :class:`ZeroDivisionError` exception occurs, the equation system can
possibly be solved by :code:`BandedMatrixLU(A, 1, 1).solve_vector(B)`

Args:
    A: diagonal matrix [[a0..an-1], [b0..bn-1], [c0..cn-1]] ::

        [[b0, c0, 0, 0, ...],
        [a1, b1, c1, 0, ...],
        [0, a2, b2, c2, ...],
        ... ]

    B: iterable of floats [[b1, b1, ..., bn]

Returns:
    list of floats

Raises:
    ZeroDivisionError: singular matrix

)r    _solve_tridiagonal_matrix)r.   r   r0   r  r  r  s         r#   r   r     s8    8 !""1tAw"GA!$Q1d1g66 #s   6c                   U  Vs/ s H  n[        U5      PM     snu  p4n[        U[        5      (       d$  [        U Vs/ s H  n[        U5      PM     snS9nO[        [        U5      nUR                  [        U5      :w  a  [        S5      e[        UR                  5        Vs/ s H  n[        X4XX5      PM     snS9R                  5       $ s  snf s  snf s  snf )aH  Solves the linear equation system given by a tri-diagonal nxn Matrix
A . x = B, right-hand side quantities as nxm Matrix B. Matrix A is diagonal
matrix defined by 3 diagonals [-1 (a), 0 (b), +1 (c)].

Note: a0 is not used but has to be present, cn-1 is also not used and must
not be present.

If an :class:`ZeroDivisionError` exception occurs, the equation system
can possibly be solved by :code:`BandedMatrixLU(A, 1, 1).solve_vector(B)`

Args:
    A: diagonal matrix [[a0..an-1], [b0..bn-1], [c0..cn-1]] ::

        [[b0, c0, 0, 0, ...],
        [a1, b1, c1, 0, ...],
        [0, a2, b2, c2, ...],
        ... ]

    B: matrix [[b11, b12, ..., b1m],
               [b21, b22, ..., b2m],
               ...
               [bn1, bn2, ..., bnm]]

Returns:
    matrix as :class:`Matrix` object

Raises:
    ZeroDivisionError: singular matrix

rW   z+Row count of matrices A and B has to match.)
r    r+   r   r	   rk   r   r   r   r3  r   )	r.   r   r0   r  r  r  r/   matrix_brz   s	            r#   r   r     s    B !""1tAw"GA!a  q!9q$s)q!9:?~~QFGGCK==?S?C)!7?Sik #!9 Ts   CC$Cc                :   [        U 5      nS/U-  nS/U-  nUS   nUS   U-  US'   [        SU5       H3  nX(S-
     U-  Xh'   X   X   Xh   -  -
  nX8   X   XXS-
     -  -
  U-  XX'   M5     [        US-
  SS5       H  nXX==   XhS-      XXS-      -  -  ss'   M     U$ )a  Solves the linear equation system given by a tri-diagonal
Matrix(a, b, c) . x = r.

Matrix configuration::

    [[b0, c0, 0, 0, ...],
    [a1, b1, c1, 0, ...],
    [0, a2, b2, c2, ...],
    ... ]

Args:
    a: lower diagonal [a0 .. an-1], a0 is not used but has to be present
    b: central diagonal [b0 .. bn-1]
    c: upper diagonal [c0 .. cn-1], cn-1 is not used and must not be present
    r: right-hand side quantities

Returns:
    vector x as list of floats

Raises:
    ZeroDivisionError: singular matrix

r  r   ro   r  )r   r   )	r  r  r  r   nugambetjs	            r#   r3  r3  H  s    4 VAUQYAuqyC1CQ4#:AaD1a[q5CdQTCF]"qtaAh&#- 
 AEB#	E
Q1uX%% $Hr<   c                <    [        X5      u  p#[        XU5      nXBU4$ )a=  Transform matrix A into a compact banded matrix representation.
Returns compact representation as :class:`Matrix` object and
lower- and upper band count m1 and m2.

Args:
    A: input :class:`Matrix`
    check_all: check all diagonals if ``True`` or abort testing
        after first all zero diagonal if ``False``.

)r   r   )r.   	check_allm1m2rY   s        r#   r   r   q  s&     "!/FBaR(A"9r<   c                F   ^ ^ SU U4S jjnSU U4S jjnU" 5       U" 5       4$ )zReturns lower- and upper band count m1 and m2.

Args:
    A: input :class:`Matrix`
    check_all: check all diagonals if ``True`` or abort testing
        after first all zero diagonal if ``False``.

c                    > Sn [        STR                  5       H0  n[        TR                  U5      5      (       a  Un M&  T(       a  M/    U $    U $ Nr   ro   )r   rp   anyr~   )r@  r  r.   r>  s     r#   	detect_m2'detect_banded_matrix.<locals>.detect_m2  sG    q!''"A166!9~~Y	 #
 	r<   c                    > Sn [        STR                  5       H1  n[        TR                  U* 5      5      (       a  Un M'  T(       a  M0    U $    U $ rC  )r   rk   rD  r~   )r?  r  r.   r>  s     r#   	detect_m1'detect_banded_matrix.<locals>.detect_m1  sI    q!''"A1661":Y	 #
 	r<   r   rB   )r.   r>  rE  rH  s   ``  r#   r   r     s(       ;	##r<   c                   U R                   U R                  :w  a  [        S5      e[        5       n[	        USS5       H;  nS/U-  nUR                  U R                  U* 5      5        UR                  U5        M=     UR                  U R                  S5      5        [	        SUS-   5       H:  nU R                  U5      nUR                  S/U-  5        UR                  U5        M<     U$ )zReturns compact banded matrix representation as :class:`Matrix` object.

Args:
    A: matrix to transform
    m1: lower band count, excluding main matrix diagonal
    m2: upper band count, excluding main matrix diagonal

zSquare matrix required.r   r7  r  ro   )rk   rp   rL   r   r   extendr~   r   )r.   r?  r@  rY   r  rz   s         r#   r   r     s     	ww!''122A2q"eai

1661":	S 
 LL1b1fffQi

C519	S  Hr<   c                  J    \ rS rSrSrS	S jr\S
S j5       rSS jrSS jr	Sr
g)r   i  z9Represents a LU decomposition of a compact banded matrix.c                    [         n[        (       a  SSKJn  [	        U5      U l        [	        U5      U l        U" UR                  U R
                  U R                  5      u  U l        U l	        U l
        g )Nr   )lu_decompose)_lu_decomposer   ezdxf.acc.np_supportrN  r   r?  r@  r,   upperlowerrw   )rM   r.   r?  r@  rN  s        r#   rO   BandedMatrixLU.__init__  sL    $992w2w-9!((DGGTWW-U*
DJ
r<   c                4    U R                   R                  S   $ ri   )rQ  rI   rS   s    r#   rk   BandedMatrixLU.nrows  s     zz""r<   c           
     L   [         n[        (       a  SSKJn  [        R
                  " U[        R                  S9n[        U5      U R                  :w  a  [        S5      e[        U" X0R                  U R                  U R                  U R                  U R                  5      5      $ )Solves the linear equation system given by the banded nxn Matrix
A . x = B, right-hand side quantities as vector B with n elements.

Args:
    B: vector [b1, b2, ..., bn]

Returns:
    vector as list of floats

r   )solve_vector_banded_matrixrC   ;Item count of vector B has to be equal to matrix row count.)_solve_vector_banded_matrixr   rP  rX  rE   rF   rG   r   rk   r   r    rQ  rR  rw   r?  r@  )rM   r   rX  xs       r#   r   BandedMatrixLU.solve_vector  s}     &A"9GXXarzz2q6TZZM  &::tzz4::tww
 	
r<   c                    [        US9nUR                  U R                  :w  a  [        S5      e[        UR                  5        Vs/ s H  o0R	                  U5      PM     snS9R                  5       $ s  snf )a  
Solves the linear equation system given by the banded nxn Matrix
A . x = B, right-hand side quantities as nxm Matrix B.

Args:
    B: matrix [[b11, b12, ..., b1m], [b21, b22, ..., b2m],
        ... [bn1, bn2, ..., bnm]]

Returns:
    matrix as :class:`Matrix` object

rW   z,Row count of self and matrix B has to match.)r   rk   r   r   r   r   )rM   r   r5  rz   s       r#   r   BandedMatrixLU.solve_matrix  sb     #>>TZZ'KLL6>mmoFos%%c*oF

)+	Fs   A3)rw   rR  r?  r@  rQ  N)r.   r   r?  r   r@  r   r   r  r   )r   r   r   r   r   rO   r   rk   r   r   r   rB   r<   r#   r   r     s)    CV # #
8r<   r   c                   [         R                  " U [         R                  S9nUR                  S   n[         R                  " XA4[         R                  S9n[         R                  " U4[         R
                  S9nX-   S-   nUn[        U5       HJ  n	[        X-
  U5       H  n
X9   U
   X9   X-
  '   M     US-  n[        Xx-
  S-
  U5       H
  n
SX9   U
'   M     ML     Un[        U5       H  nX;   S   nUn	X:  a  US-  n[        US-   U5       H+  n
[        X:   S   5      [        U5      :  d  M"  X:   S   nU
n	M-     U	S-   Xk'   X:w  a+  [        U5       H  n
X9   U
   X;   U
   sX;   U
'   X9   U
'   M     [        US-   U5       HU  n	X9   S   X;   S   -  nXU   X-
  S-
  '   [        SU5       H  n
X9   U
   XU   U
   -  -
  X9   U
S-
  '   M     SX9   US-
  '   MW     M     X5U4$ )NrC   r   ro   r  )rE   rF   rG   rI   rH   int64r   r   )r.   r?  r@  rQ  r8  rR  rw   mmlr8   r<  r7   dums                r#   rO  rO     s   XXarzz2E [[^AXXqgRZZ8EXXqd"((3EgkBA2Yrvr"A#hqkEHQUO #	Qrvz2&AEHQK '	  	A1Xhqk5FAq1uaA58A;#c(*hqk ! q562Y+08A;(UXa[  q1uaA(1++C"%!HQUQY1b\"'(1+Ahqk0A"AQ ""EHR!V ! ( r<   c                   UR                   S   nU R                   S   U:w  a  [        S5      eUnUnXE-   S-   n	Un
[        U5       HW  nX;   S-
  nX:w  a  X   X   sX'   X'   X:  a  U
S-  n
[        US-   U
5       H  nX==   X{   X-
  S-
     X   -  -  ss'   M      MY     Sn
[        US-
  SS5       HD  nX   n[        SU
5       H  nXU   U   XU-      -  -  nM     XU   S   -  X'   X:  d  M?  U
S-  n
MF     U $ )rW  r   rY  ro   r7  )rI   r   r   )r[  rQ  rR  rw   r?  r@  r8  alaura  rb  r7   r<  r8   rc  s                  r#   rZ  rZ  *  s/   $ [[^AwwqzQVWWBBgkBA1XHqL6qtJAD!$5FAq1uaADBE!%!)$qt++D !  	
A1q5"b!dq!Aa58aAh&&C U1X~6FA " Hr<   )r   zIterable[list])r   r%   )r7   r   r8   r   r   r-   )rA   )r  r-   r  r-   r  r-   r   r   )
r  r-   r  r-   r  r-   r  r-   r   r   )r.   r  r   r  r   r   )r.   r  r   r   r   r   )r.   r%   r   r   r   r   )
r  r   r  r   r  r   r   r   r   r   )T)r.   r   r   ztuple[Matrix, int, int])r.   r   r   r   )r.   r   r?  r   r@  r   r   r   )r.   r(   r?  r   r@  r   r   z tuple[NDArray, NDArray, NDArray])r[  r(   rQ  r(   rR  r(   rw   r(   r?  r   r@  r   r   r(   )6
__future__r   typingr   r   r   r   r   r	   r
   typing_extensionsr   r  	functoolsr   	itertoolsr   r5   rb   numpyrE   numpy.typingnpt	ezdxf.accr   __all__r$   r-   r%   __annotations__r&   r   r'   r(   rG   r1   r   r   ABCr   r   r   r   r   r   r   r   r3  r   r   r   r   rO  rZ  rB   r<   r#   <module>rs     s   #   ( 
       $
 T%[)
I )#E%*$56 ) 6c?y "[[, ,2 3/ /,R1 R1jSWW P"+\8"9$"B& "BJ7@++ 4++\&&"&'2&7B&&R $>8AV AH'T,,, , 	,
 	, 	, ,r<   