
    -iW                     `    S r SSKrSSKrSSKrSSKrSSKJr  SSKrSSK	J
r
Jr   " S S5      rg)z:Base classes for low memory simplicial complex structures.    N)cache   )VertexCacheFieldVertexCacheIndexc                       \ rS rSrSr  SS jrS rSS jr  SS jrSS jr	SS	 jr
SS
 jrS rS rS rS rSS jrSS jrSS jrSrg)Complex   a&  
Base class for a simplicial complex described as a cache of vertices
together with their connections.

Important methods:
    Domain triangulation:
            Complex.triangulate, Complex.split_generation
    Triangulating arbitrary points (must be traingulable,
        may exist outside domain):
            Complex.triangulate(sample_set)
    Converting another simplicial complex structure data type to the
        structure used in Complex (ex. OBJ wavefront)
            Complex.convert(datatype, data)

Important objects:
    HC.V: The cache of vertices and their connection
    HC.H: Storage structure of all vertex groups

Parameters
----------
dim : int
    Spatial dimensionality of the complex R^dim
domain : list of tuples, optional
    The bounds [x_l, x_u]^dim of the hyperrectangle space
    ex. The default domain is the hyperrectangle [0, 1]^dim
    Note: The domain must be convex, non-convex spaces can be cut
          away from this domain using the non-linear
          g_cons functions to define any arbitrary domain
          (these domains may also be disconnected from each other)
sfield :
    A scalar function defined in the associated domain f: R^dim --> R
sfield_args : tuple
    Additional arguments to be passed to `sfield`
vfield :
    A scalar function defined in the associated domain
                   f: R^dim --> R^m
               (for example a gradient function of the scalar field)
vfield_args : tuple
    Additional arguments to be passed to vfield
symmetry : None or list
        Specify if the objective function contains symmetric variables.
        The search space (and therefore performance) is decreased by up to
        O(n!) times in the fully symmetric case.

        E.g.  f(x) = (x_1 + x_2 + x_3) + (x_4)**2 + (x_5)**2 + (x_6)**2

        In this equation x_2 and x_3 are symmetric to x_1, while x_5 and
         x_6 are symmetric to x_4, this can be specified to the solver as:

        symmetry = [0,  # Variable 1
                    0,  # symmetric to variable 1
                    0,  # symmetric to variable 1
                    3,  # Variable 4
                    3,  # symmetric to variable 4
                    3,  # symmetric to variable 4
                    ]

constraints : dict or sequence of dict, optional
    Constraints definition.
    Function(s) ``R**n`` in the form::

        g(x) <= 0 applied as g : R^n -> R^m
        h(x) == 0 applied as h : R^n -> R^p

    Each constraint is defined in a dictionary with fields:

        type : str
            Constraint type: 'eq' for equality, 'ineq' for inequality.
        fun : callable
            The function defining the constraint.
        jac : callable, optional
            The Jacobian of `fun` (only for SLSQP).
        args : sequence, optional
            Extra arguments to be passed to the function and Jacobian.

    Equality constraint means that the constraint function result is to
    be zero whereas inequality means that it is to be
    non-negative.constraints : dict or sequence of dict, optional
    Constraints definition.
    Function(s) ``R**n`` in the form::

        g(x) <= 0 applied as g : R^n -> R^m
        h(x) == 0 applied as h : R^n -> R^p

    Each constraint is defined in a dictionary with fields:

        type : str
            Constraint type: 'eq' for equality, 'ineq' for inequality.
        fun : callable
            The function defining the constraint.
        jac : callable, optional
            The Jacobian of `fun` (unused).
        args : sequence, optional
            Extra arguments to be passed to the function and Jacobian.

    Equality constraint means that the constraint function result is to
    be zero whereas inequality means that it is to be non-negative.

workers : int  optional
    Uses `multiprocessing.Pool <multiprocessing>`) to compute the field
     functions in parallel.
Nc                    Xl         X l        Uc  S/U-  U l        OX l        XPl        X0l        X@l        Ub  X`l        / U l        / U l        [        U[        [        -  5      (       d  U4nU HK  nUS   S;   d  M  U R                  R                  US   5         U R                  R                  US   5        MM     [        U R                  5      U l        [        U R                  5      U l        OS U l        S U l        SU l        SU l        / U l        Uc  U R                  b\  Ub&  [#        X4U R                  U R                  US9U l        OBU R                  b%  [#        X4U R                  U R                  US9U l        O['        5       U l        / U l        [+        U R,                  5      U l        g ! [         a     U R                  R                  S5         GMm  f = f)	N)        g      ?typeineqfunargs r   )field
field_argsg_consg_cons_argsworkers)dimdomainboundssymmetrysfieldsfield_argsmin_consr   g_args
isinstancetuplelistappendKeyErrorgen
perm_cycleHr   Vr   
V_non_symmr   _split_edge
split_edge)	selfr   r   r   r   r   constraintsr   conss	            T/var/www/html/venv/lib/python3.13/site-packages/scipy/optimize/_shgo_lib/_complex.py__init__Complex.__init__t   s    >%.3.DK K  &
 "'MDKDKk54<88*n#<F+KK&&tE{3/**4<8	 $  ,DK,DKDKDK   DKK$; !)156:kk29; ()156:kk29;
 &'DF 0 01M $ /**2../s   F00%GGc                     U R                   $ N)r%   )r*   s    r-   __call__Complex.__call__   s    vv    c              #     #    [        U5      n[        U5      nU R                  U     U R                  U   nUR                  v   U R                  U   R                  U R                  U   5        Uv   U R                  U   //n[        R                  " [        U5      5      n	US   U	S'   U R                  [        U	5         n	U R                  U   R                  U	5        U	R                  v   U	//n
/ n[        USS 5       GH  u  pUR                  / 5        U
R                  / 5         US     USUS-     Vs/ s H  oSS PM	     nnU
SUS-     Vs/ s H  oSS PM	     nn[        [        X5      5       GH  u  nu  nn[        [        UU5      5       GHq  u  nu  nn[        UR                  5      n[        UR                  5      nXlS-      UUS-   '   XlS-      UUS-   '   U R                  [        U5         nUR                  U5        UR                  v   U R                  [        U5         nUR                  U5        UR                  U5        UR                  U5        UR                  UU45        XS-      R                  U5        XS-      R                  U5        XS-      R                  U5        XS-      R                  U5        UU   R                  U5        U
U   R                  U5        UR                  v   GMt     GM     [        R                  " U5      nU H  n[        US   R                  5      n[        US   R                  5      nXlS-      UUS-   '   XlS-      UUS-   '   U R                  [        U5         nU R                  [        U5         nUS   R                  U5        UR                  U5        UR                  US   U45        UR                  UU45        M     GM      AAA
AAAU(       a~  U R                  U   nU R                  U   nUR                  U5        U R                  XV5      nUR                   H  nUR                  U5        M     UR                  v   UR                  $ Uv   U$ s  snf s  snf ! [         Ga    X   nX   nXnn[        [        UU5      5       GHq  u  nu  nn[        UR                  5      nXlS-      UUS-   '   U R                  [        U5         nUR                  U5        UR                  U5        UR                  UU45        XS-      R                  U5        XS-      R                  U5        UR                  U R                  U   5        UR                  v   [        R                  " U5      nU H  nUS   R                  U   Xl   :X  d  M  [        US   R                  5      nXlS-      UUS-   '   U R                  [        U5         nUS   R                  U5        UR                  US   U45        M     GMt      GM=  f = f! [         a     GNKf = f7f)z3Generate initial triangulation using cyclic productr   r   N)r   r&   xconnectcopyr    	enumerater!   zip
IndexErrorUnboundLocalError
disconnectr)   nn)r*   r   originsupremumcentroidvotvutvoC0xa_voC1xab_Cir6   cC0xcC1xjVLVUkvlvua_vla_vuab_Ccvpb_vab_vvsvcvs                                  r-   cyclic_productComplex.cyclic_product   s     FmHosVVC[dd
sDFF3K(	 s}oyyf&a&QvveDk"sD!ffvh fQRj)DAJJrNJJrNg7 !&)&1q5k2k!k2&)&1q5k2k!k2#,S_#=KAxB'0R'=8B#BDDz#BDDz&)a%jQU&)a%jQU#vveDk2 

4("ff#vveDk2 

4( T* 

4(RJ/ E
))"-E
))"-E
))$/E
))$/ Ad+Ad+ #ffM (> $>V 		$Br!uww-C1=D!$UCAJ"%!e*DQK&&s,C66%+.DqEMM$'KK% KKA.KKd,  u *^	
 BBMM"*BUU		" $$J44KIJy 32z  #7vvB#,SR[#9KAxB:D"%!e*DQK  66%+.D JJt$
 JJt$KKT
+AJ%%b)AJ%%d+LL-&&L IIdOE#a5771:/#'1=D*-!e*DQK#'66%+#6DqEMM$/ !KKA6 $- $:	#7Z ! 		sv   D*Y-R<R
RR$JR;YY BY
RD-YA0Y=YYY
YYYYc                    Uc  U R                   nU R                   Vs/ s H  oUS   PM	     nnX`l        U R                   Vs/ s H  oUS   PM	     nnXpl        Uc  U R                  nO[        R                  " U R                  5      n[        U5       H  u  pYXYLd  M  U R                  X%      S   /X'   U R                  X%      S   /X'   U R                  X%      U R                  X)      Ld  M^  [        R                  " SU SU	 SU SU R                  X%       SU	 SU R                  X)       S	35        U R                  X)      X'   M     Ucq  U R                  XXs5      U l	        U R                   H  nU  M      U R                  R                  [        U R                  5      [        U R                  5      45        Ok U R                     [        U R                   R"                  5      U:  a:  [%        U R                  5        [        U R                   R"                  5      U:  a  M:  U(       a:  U R                   R"                   H   n
U R                   U
   R)                  5         M"     gs  snf s  snf ! [        [        4 a3    [        U R                  5      [        U R                  5      4/U l
         Nf = f! [        [        4 a    U R                  XUU5      U l	         GNf = f! [&         a     U R                  R                  [        U R                  5      [        U R                  5      45         GN! [        [        4 a5    [        U R                  5      [        U R                  5      4/U l
          GNVf = ff = f)
a  
Triangulate the initial domain, if n is not None then a limited number
of points will be generated

Parameters
----------
n : int, Number of points to be sampled.
symmetry :

    Ex. Dictionary/hashtable
    f(x) = (x_1 + x_2 + x_3) + (x_4)**2 + (x_5)**2 + (x_6)**2

    symmetry = symmetry[0]: 0,  # Variable 1
               symmetry[1]: 0,  # symmetric to variable 1
               symmetry[2]: 0,  # symmetric to variable 1
               symmetry[3]: 3,  # Variable 4
               symmetry[4]: 3,  # symmetric to variable 4
               symmetry[5]: 3,  # symmetric to variable 4
                }
centroid : bool, if True add a central point to the hypercube
printout : bool, if True print out results

NOTES:
------
Rather than using the combinatorial algorithm to connect vertices we
make the following observation:

The bound pairs are similar a C2 cyclic group and the structure is
formed using the cartesian product:

H = C2 x C2 x C2 ... x C2 (dim times)

So construct any normal subgroup N and consider H/N first, we connect
all vertices within N (ex. N is C2 (the first dimension), then we move
to a left coset aN (an operation moving around the defined H/N group by
for example moving from the lower bound in C2 (dimension 2) to the
higher bound in C2. During this operation connection all the vertices.
Now repeat the N connections. Note that these elements can be connected
in parallel.
Nr   r   z	Variable z( was specified as symmetric to variable z, however, the bounds z = z and zE do not match, the mismatch was ignored in the initial triangulation.)r   r   r?   r@   r8   r9   loggingwarningr[   cptriangulated_vectorsr!   r   AttributeErrorr"   lenr&   r   nextStopIteration	print_out)r*   nr   rA   printoutrI   r?   r@   cboundsrL   rZ   s              r-   triangulateComplex.triangulateg  s@   V }}H $,1A$,"&++.+QaD+. kkGii,G!(+:"&++hk":1"=!>GJ #'++hk":1"=!>GJHK0 KK45)A3 7AAB D889s ;,,0KK,D+EU1#+,,0KK,D+E FE)F G &*[[%=
# ,& 9))'8NDGWW E))00%2D272F2H I8
	I$&&,,'!+M $&&,,'!+  VV\\q	##% " 	G -.H #H- E.3DKK.@.3DMM.B.D -E)E #H- 8--gx.688 ! II--44eDKK6H6;DMM6J6L M&1 I272D272F2H 1ID--I	Is^   I0I5?AI: K  AK/ :A J=<J= (K,+K,/
N	:AM  A N N	NN	c                    Uc   U R                     U R                  5         g [        U R                  R                  5      U-   n[        U R                  R                  5      U:  aH   U R                      [        U R                  5        [        U R                  R                  5      U:  a  MH  g ! [         a3  n[        U5      S:X  a  U R	                  U R
                  S9   S nAg e S nAff = f! [        [        [        4 aH    U R                   S   nU R                  " USU R                  06U l
        [        U R                  5         Nf = f! [        [        4 a    U R	                  X0R
                  5         Nf = f)N8'Complex' object has no attribute 'triangulated_vectors')r   r   r   )ra   
refine_allrb   strrj   r   rc   r&   r   rd   rlsre   r"   refine_local_spacer   )r*   rg   aentrU   s        r-   refineComplex.refine  sC   9
))! " $&&,,"$4 ))#N $&&,,"$* 	A " r7 7 7$$dmm$<* 'x@ #2215B#66O4;;ODHN#
 #H- 4
   ]]34sN   B0 (E 5C0 0
C-:(C('C((C-0AE
E EE +E>=E>c                 t    U R                     [        R                  " U R                   5      n[        U5       H;  u  p4U R                  " USU R                  06U l        U R
                   H  nU  M     M=     g! [         a4  n[        U5      S:X  a  U R                  U R                  US9   SnAge SnAff = f)z0Refine the entire domain of the current complex.r   rm   )r   rA   N)
ra   r8   r9   rq   r   rp   rb   ro   rj   r   )r*   	centroidstvsrI   rU   rr   s         r-   rn   Complex.refine_all  s    	%%))D556C"322BKt{{KA " ( 	  	2w 3 3  $--) L 	 	s   A6A9 9
B7)B21B22B7c           
   #   2/  #    [         R                   " U5      n[         R                   " U5      nSu  pxn	[        U5      n
[        U5      n[        U5      n[        U5      n[        U5       H  u  pX   X   :  d  M  X   X'   X   X'   M     [        U5      n[        U5      nU R                  U   nU R                  U   nU R                  UR                  UR                  5      n[         R                   " UR                  5      n[         R                   " [        U5      5      nUS   US'   [        U5      U R                  R                  ;  a  U R                  U   nU R                  U   nU R                  UR                  UR                  5      n[         R                   " UR                  5      n[         R                   " [        U5      5      nUS   US'   U R                  [        U5         nOU R                  [        U5         nU R                  UR                  UR                  5      nUR                  U5        UR                  v   U//nU//nU//n/ n/ n[        USS  5       GH3  u  nnUR                  / 5        UR                  / 5        UR                  / 5         [        U5      nUUS-      UUS-   '   US US-     Vs/ s H  nUS S  PM
     nnUS US-     Vs/ s H  nUS S  PM
     n nUS US-     Vs/ s H  nUS S  PM
     n!n[         R                   " U5      n"[         R                   " U5      n#[        U5      U R                  R                  ;  a  [        e[        U5      n$UUS-      U$US-   '   [        U$5      U R                  R                  ;  a  [        eU# GH  n%[        U%S   R                  5      n&[        U%S   R                  5      n'[        U%S   R                  5      n([        U%S   R                  5      n)UUS-      U&US-   '   UUS-      U'US-   '   UUS-      U(US-   '   UUS-      U)US-   '   U R                  [        U&5         n&U&R                  U5        U&v   U R                  U%S   R                  U&R                  5      n*U*R                  U&5        U*R                  U%S   5        U*R                  U%S   5        U*R                  U%S   5        U*R                  v   U R                  [        U'5         n'U&R                  U'5        U*R                  U'5        U'v   U R                  [        U(5         n(U&R                  U(5        U*R                  U(5        U R                  U(R                  U'R                  5      n+U&R                  U+5        U(v   U R                  [        U)5         n)U&R                  U)5        U*R                  U)5        U R                  U%S   R                  U)R                  5      n,U R                  U'R                  U)R                  5      n-U R                  U(R                  U)R                  5      n.U&R                  U.5        U,R                  v   U-R                  v   U)v   U R                  U%S   R                  U&R                  5      n*U*R                  U5        U*R                  v   U R                  U%S   R                  U'R                  5      n/U*R                  U5        U*R                  U/5        U/R                  v   U R                  U%S   R                  U(R                  5      n0U*R                  U5        U*R                  U05        U0R                  v   U R                  U%S   R                  U)R                  5      n1U*R                  U5        U*R                  U15        U1v   XxU	U'U(U)/n2[        R                  " U2S5      n3U3 H/  n4U R                  U4S   R                  U4S   R                  5        M1     UR                  U*U%S   U'U	U)45        UR                  U*UU'U	U)45        GM     U" GH_  n%[        U%S   R                  5      n&[        U%S   R                  5      n'[        U%S   R                  5      n([        U%S   R                  5      n5[        U%S   R                  5      n)UUS-      U&US-   '   UUS-      U'US-   '   UUS-      U(US-   '   UUS-      U5US-   '   UUS-      U)US-   '   U R                  [        U&5         n&U&R                  U5        U&v   U R                  U%S   R                  U&R                  5      n*U*R                  U&5        U*R                  U%S   5        U*R                  U%S   5        U*R                  U%S   5        U*R                  U%S   5        U*R                  v   U R                  [        U'5         n'U&R                  U'5        U*R                  U'5        U'v   U R                  [        U(5         n(U&R                  U(5        U*R                  U(5        U(v   U R                  [        U55         n5U&R                  U55        U*R                  U55        U R                  U(R                  U5R                  5        U5v   U R                  [        U)5         n)U&R                  U)5        U*R                  U)5        U R                  U%S   R                  U)R                  5      n,U R                  U'R                  U)R                  5      n-U,R                  v   U-R                  v   U)v   U R                  U%S   R                  U&R                  5      n*U*R                  U5        U*R                  v   U R                  U%S   R                  U'R                  5      n/U*R                  U5        U*R                  U/5        U/R                  v   U R                  U%S   R                  U(R                  5      n0U*R                  U5        U*R                  U05        U0R                  v   U R                  U%S   R                  U5R                  5      n6U*R                  U5        U*R                  U65        U6v   U R                  U%S   R                  U)R                  5      n1U*R                  U5        U*R                  U15        U1v   U%u  n7pxnn	XxUU	U'U(U5U)/n2[        R                  " U2S5      n3U3 H/  n4U R                  U4S   R                  U4S   R                  5        M1     UR                  U&U'U(U5U)45        UR                  U*U/U0U6U145        UR                  U*U%S   U'U	U)45        UR                  U*UU(UU545        GMb     [        [        UU U!5      5       GH  u  n8u  n9n:n;[        [        U9U:U;5      5       GH  u  n<u  nn=n[        UR                  5      n[        UR                  5      n	UUS-      UUS-   '   UUS-      XS-   '   U R                  [        U5         nU R                  [        U	5         n	U R                  UR                  U	R                  5      n7U R                  UR                  UR                  5        U7R                  U5        U7R                  U=5        U7R                  U5        U7R                  U5        U7R                  U5        U7R                  U	5        U7R                  v   U R                  UR                  UR                  5      n>U>R                  U5        U7R                  U>5        U>R                  v   U R                  UR                  U	R                  5      n?U?R                  U5        U7R                  U?5        U?R                  v   U R                  UR                  U	R                  5      n@U@R                  U5        U@R                  U75        UR                  U7XxUU	45        UUS-      R                  U5        UUS-      R                  U=5        UUS-      R                  U5        UUS-      R                  U>5        UUS-      R                  U75        UUS-      R                  U?5        UUS-      R                  U5        UUS-      R                  U@5        UUS-      R                  U	5        UU8   R                  U>5        UU8   R                  U5        UU8   R                  U75        UU8   R                  U@5        UU8   R                  U?5        UU8   R                  U	5        U@R                  v   GM     GM     GM6      AAAAA" U R                   R#                  [        U5      [        U5      45        U HF  nU R                   R                  [        UR                  5      [        UR                  5      45        MH     U(       Ga  ['        5       nB/ nCU HL  nU R)                  UR                  UR                  5      nD UDR#                  WB5        WCR                  WD5        MN     WC H  nD UDR#                  WB5        M     [        UWC5       Hw  u  nnDU R                  UR                  UR                  5      nEWBR-                  UE5         UDR#                  UB5        WD H  nFWER                  UF5        M     WER                  v   My     O Uv   g s  snf s  snf s  snf ! [         Ga    W" GH  n%[        U%S   R                  5      n5[        U%S   R                  5      n)UUS-      U5US-   '   UUS-      U)US-   '   U R                  [        U)5         n)U)v   U R                  U%S   R                  U)R                  5      n*U)v   U*R                  U%S   5        U*R                  U%S   5        U*R                  U%S   5        U*R                  U%S   5        U*R                  v   U R                  [        U55         n5U5v   U R                  U%S   R                  U5R                  5      n6U R                  U%S   R                  U)R                  5      n1U R                  U6R                  U1R                  5      nAU6v   U1v   UAv   U%u  n7pxnn	XxUU	U5U)/n2[        R                  " U2S5      n3U3 H/  n4U R                  U4S   R                  U4S   R                  5        M1     GM     UU   nUU   n UU   n!UU U!n;n:n9[        [        U9U:U;5      5       GH  u  n<u  nn=n[        UR                  5      n	UUS-      XS-   '   U R                  [        U	5         n	UR                  v   U R                  UR                  U	R                  5      n7U R                  UR                  UR                  5        U7R                  U5        U7R                  U=5        U7R                  U5        U7R                  U5        U7R                  U	5        U7R                  v   U R                  UR                  U	R                  5      n?U?R                  U5        U7R                  U?5        U?R                  v   UUS-      R                  U5        UUS-      R                  U?5        UUS-      R                  U	5        UR                  U7XxU	/5        U	R                  v   GM      GM  f = f! [         a     GNf = f! [$         a     GNf = f! [*         a     GNf = f! [*         a     GM  f = f! [*         a     GNf = f7f)N)NNNr   r            )r8   r    r9   r   r&   r)   r6   r>   r   r7   r!   r;   	itertoolscombinationsr:   r<   ra   remove
ValueErrorsetvpoolr"   add)Gr*   r?   r@   r   rA   origin_c
supremum_crP   rQ   rS   s_ovs_origins_sv
s_supremumrI   virB   rC   rD   rX   vcosup_setrR   c_vCoxCcxCuxrH   s_ab_Cr6   t_a_vlcCoxcCcxcCuxrT   s_ab_Cct_a_vuvectorsbc_vcb_vlb_vuba_vud_bc_vcb_vl_cos_vss_vb_vu_cd_b_vld_b_vud_ba_vucomb	comb_itervecsba_vld_ba_vlc_vcrL   rM   VCrN   rO   rY   c_vlc_vua_vcd_ba_vcvcn_set
c_nn_listsc_nnvcnvnnsG                                                                          r-   rq   Complex.refine_local_space  s    99V$YYx(
 ( F|<H~(^
x(EAw "g $
 )
 HoJVVC[VVC[oobddBDD) ))CFF# yyc#a&Q;dffll*BB//"$$-C ii'G99T#Y'D!fDG66%+&D66%+&DoobddDFF+Ceetfugvh fQRj)DAqJJrNJJrNJJrN|!c #AE
q1u
 '*&1q5k2k!k2&)&1q5k2k!k2&)&1q5k2k!k2 		$ ))F+
 =4$$c #AE
q1u=4$$&G .E
-D
-D .E#&q1u:E!a%L"%a!e*DQK"%a!e*DQK#&q1u:E!a%L FF5<0EMM#&K #oogajllEGGDGOOE*OOGAJ/OOGAJ/OOGAJ/!))O66%+.DMM$'OOD)J66%+.DMM$'OOD)!__TVVTVV<FMM&)J FF5<0EMM%(OOE*  ??71:<<AD??466577;D!__TVVUWW=FMM&)&&L&&LK #oogajllEGGDGOOC(!))O!__WQZ\\466BFOOC(OOF+ ((N!__WQZ\\466BFOOC(OOF+ ((N"oogajllEGGDGOOC(OOG,!M D $/D ) 6 6tQ ?I )Q		4799= !* KK'!*dD% HIKK"dD% @AW  'Z  %G .E
-D
-D .E .E#&q1u:E!a%L"%a!e*DQK"%a!e*DQK#&q1u:E!a%L#&q1u:E!a%L FF5<0EMM#&K #oogajllEGGDGOOE*OOGAJ/OOGAJ/OOGAJ/OOGAJ/!))O66%+.DMM$'OOD)J66%+.DMM$'OOD)J FF5<0EMM%(OOE*OODFFEGG4K FF5<0EMM%(OOE*??71:<<AD??466577;D&&L&&LK #oogajllEGGDGOOC(!))O!__WQZ\\466BFOOC(OOF+ ((N!__WQZ\\466BFOOC(OOF+ ((N"oogajllEGGDGOOC(OOG,!M"oogajllEGGDGOOC(OOG,!M/6,D"$D$ $u6D ) 6 6tQ ?I )Q		4799= !* KKdE5 ABKK&&'7 KLKK'!*dD% HIKK"dD% @A]  %` (1T41F'GOA|B+4SR_+E<BB#BDDz#BDDz&)!a%jQU&)!a%jU#vveDk2#vveDk2  $rttTVV<bdd3S)R(R(R(T*T*"ff#rttTVV<S)T*"ff#rttTVV<S)T*"ff#tvvtvv>S)T* T24$>? AE
))"-AE
))"-AE
))"-AE
))$/AE
))$/AE
))$/AE
))$/AE
))$/AE
))$/ Ad+Ad+Ad+Ad+Ad+Ad+ #ffu ,F (HA *J
		%%,,eHo.3J.?.A B B%%,,eCEElE"$$K-HI  eGJzz#%%.KK( !!$'  #KK( #  4DooceeRTT2C KK(  CKK$  ee 5 	[ 322\  E!$G .E .E#&q1u:E!a%L#&q1u:E!a%L FF5<0EK"oogajllEGGDGKOOGAJ/OOGAJ/OOGAJ/OOGAJ/!))O FF5<0EK"oogajllEGGDG"oogajllEGGDG"oogiiCG!M!M!M/6,D"$D$!!#D !* 6 6tQ ?I )Q		4799= !*7  %> 1v1v1v!4B'0RR'AOA|B:D"%a!e*DQK  66%+.D&&L??2448DOOBDD"$$/LL%LL$LL$LL$LL&66N??244+/663DLL%LL&66N AJ%%b)AJ%%d+AJ%%d+ MM4"67&&LC (BIE!\ ! 		  		          s\  A6A^<H-A^*#AMAL8AM(AL=7AMAMzAMF"A^F(A] F./A] GBA^I)A]#I:A^JA]4J&AA^K4A^L3A^L8AMMO2A\>\9A^\=A\>\>A^]
A]]A^]A]]A^]
A] ]A^]A] ] A^]#
A]1]-A^]0A]1]1A^]4
A^]>A^^A^^A^^
A^^A^^A^^A^c                 8   [         R                   " UR                  5      n/ n[        5       nU H2  nUR                  [         R                   " UR                  5      5        M4     [	        X#5       H  u  pSUR                  U5      nU R                  UR                  UR                  5      nU H  nUR                  U5        M     UR                  U5        U H:  n	U R                  UR                  U	R                  5      n
UR                  U
5        M<     M     g)z'Refine the star domain of a vertex `v`.N)
r8   r>   r   r!   r:   intersectionr)   r6   r7   r   )r*   rZ   r   v1nn
d_v0v1_setv1vnnud_v0v1o_d_v0v1v2d_v1v2s              r-   refine_starComplex.refine_star  s     iioU
BKK		"%%()  CHB$$S)D__QSS"$$/F&x( 'NN6"rtt4v&  ' 	r4   c                    U R                   U   nU R                   U   nUR                  U5         UR                  UR                  -
  S-  UR                  -   nU R                   [        U5         nUR                  U5        UR                  U5        U$ ! [         a@    UR                  UR                  -
  [        R
                  " S5      -  UR                  -   n Nf = f)Ng       @)r&   r=   x_a	TypeErrordecimalDecimalr   r7   )r*   r   r   vctrY   s        r-   r(   Complex._split_edge  s    VVBZVVBZ
b	D66BFF?c)BFF2C VVE#J


2


2	  	D66BFF?gooc&::RVVCC	Ds   )B AC C c                 z   [        U5      n[        U5      nU R                  U   nU R                  U   n[        U5      n[        U5      n[        [	        X45      5       H"  u  n	u  pXy   U:  a  XU	'   X   U
:  d  M  XU	'   M$     [        5       nUR                  UR                  5        UR                  UR                  5        [        R                  " U5      nU HI  n[        UR                  5       H-  u  pXy   Us=::  a  X   ::  a  O  OM   UR                  U5        M/     MK     U$ ! [         a     MD  f = fr1   )r   r&   r    r9   r:   r   updater>   r8   r6   r   r"   )r*   r?   r@   rB   vstrD   rX   blburI   voivsivn_poolcvn_poolvnxis                   r-   r   Complex.vpool  s   FmHoVVC[VVC[
 #Y#Y&s3}5MAzus{1us{1	 6 %ruuruu99W%B"2445B'"%'r* )   $ s   D,,
D:9D:c           
         U R                   S:  az  U Hs  n[        R                  " X0R                   5      nU HJ  nU R                  [	        XS      5         R                  U R                  [	        XS      5         5        ML     Mu     gU HJ  nU R                  [	        XS      5         R                  U R                  [	        XS      5         5        ML     g)z
Convert a vertex-face mesh to a vertex-vertex mesh used by this class

Parameters
----------
vertices : list
    Vertices
simplices : list
    Simplices
r   r   N)r   r~   r   r&   r   r7   )r*   vertices	simplicessedgeses         r-   vf_to_vvComplex.vf_to_vv  s     88a<!..q((;AFF5A$0199uXd^457   	 uXd^,-55FF5A$013  	r4   c           	          Uc  U R                   nOUn[        U5      U R                   R                  ;   a  U R                   U   U R                  ;   a  OgU R                   U     Sn/ nU H  nUR	                  UR
                  5        M      [        R                  " U5      n[        R                  " U5      [        R                  " U5      -
  n[        R                  " [        UR                  S   5      U R                  S-   S9 GH  nSn	[        R                  " USS9 H  n
U R                   [        XZS      5         U R                   [        XZS      5         R                  ;  d  MK  U R                   [        XZS      5         U R                   [        XZS      5         R                  ;  d  M  Sn	  O   U[        U/5         nU	(       a  U R                  USS9(       a  Sn	U	(       d  M  U[        U/5         nU R                  XU5      (       d  GM  Sn  O   U(       a?  W H9  n
U R                   U   R!                  U R                   [        XZ   5         5        M;     U R                  R	                  U R                   U   5        U$ )	a)  
Adds a vertex at coords v_x to the complex that is not symmetric to the
initial triangulation and sub-triangulation.

If near is specified (for example; a star domain or collections of
cells known to contain v) then only those simplices containd in near
will be searched, this greatly speeds up the process.

If near is not specified this method will search the entire simplicial
complex structure.

Parameters
----------
v_x : tuple
    Coordinates of non-symmetric vertex
near : set or list
    List of vertices, these are points near v to check for
NFr   r   )rTr{   )proj)r&   r   r   r'   r!   r6   nparrayr~   r   rangeshaper   r>   deg_simplex
in_simplexr7   )r*   v_xnearstarfound_nnS_rowsrZ   As_ivalid_simplexrI   SA_j0s                r-   connect_vertex_non_symmComplex.connect_vertex_non_symm3  s   & <66DD:%vvc{doo-sAMM!##  &!HHVrxx},))%Q*@,0HHqL:C !M++C15 VVE&1,/0uVaD\23667fqTl 34fqTl 34778$)M 6 ucU|$A##AD#1$)M }u??1400#H7:< s##DFF5+;$<=  	tvvc{+r4   c           
         [         R                  " USS5      US   -
  n[         R                  " [         R                  R	                  U5      5      nUS:X  a  SnUc  X-
  n[        U R                  S-   5       HZ  nSU-  U-  n[         R                  " [         R                  R	                  [         R                  " X6S5      5      5      nXx:X  a  MZ    g   g)a!  Check if a vector v_x is in simplex `S`.

Parameters
----------
S : array_like
    Array containing simplex entries of vertices as rows
v_x :
    A candidate vertex
A_j0 : array, optional,
    Allows for A_j0 to be pre-calculated

Returns
-------
res : boolean
    True if `v_x` is in `S`
r   r   FT)r   deletesignlinalgdetr   r   )	r*   r   r   r   A_11sign_det_A_11ddet_A_jjsign_det_A_j0s	            r-   r   Complex.in_simplex  s    " yyAq!AaD(		d 34A M <7Dtxx!|$AQw.H GGBIIMM"))DEF3H %I JM ( % r4   c                 h    Uc  USS US   -
  n[         R                  R                  U5      S:X  a  gg)a  Test a simplex S for degeneracy (linear dependence in R^dim).

Parameters
----------
S : np.array
    Simplex with rows as vertex vectors
proj : array, optional,
    If the projection S[1:] - S[0] is already
    computed it can be added as an optional argument.
Nr   r   r   TF)r   r   r   )r*   r   r   s      r-   r   Complex.deg_simplex  s9     <QR51Q4<D 99==#%r4   )r%   r&   r'   r   r`   r   r   r   r   r#   r   r?   r$   rp   r   r   r)   r@   r   ra   )NNr   NNr   )T)NNTF)r   r1   )__name__
__module____qualname____firstlineno____doc__r.   r2   r[   rj   rt   rn   rq   r   r(   r   r   r   r   r   __static_attributes__r   r4   r-   r   r      sn    eL CE:;F2PeN ;?"qf&P*yv*""H.KZ.`r4   r   )r  r8   r^   r~   r   	functoolsr   numpyr   _vertexr   r   r   r   r4   r-   <module>r
     s)    @       9| |r4   