ó
    Eñi¬6  ã                   óð   • S SK r S SKJrJr  S SKrS SKJr   " S S\5      r " S S\5      r	 " S S	\5      r
 " S
 S5      r " S S\5      r " S S\5      r " S S\5      r " S S5      r " S S5      rg)é    N)ÚABCÚabstractmethod)Ú
MapWrapperc                   óT   • \ rS rSrSrSS jrS rS r\S 5       r	\S 5       r
S	 rS
rg)Ú
VertexBaseé	   z
Base class for a vertex.
Nc                 ó–   • Xl         [        U R                   5      U l        Ub  [        U5      U l        O[        5       U l        X0l        g)zË
Initiation of a vertex object.

Parameters
----------
x : tuple or vector
    The geometric location (domain).
nn : list, optional
    Nearest neighbour list.
index : int, optional
    Index of vertex.
N)ÚxÚhashÚsetÚnnÚindex)Úselfr
   r   r   s       Ú]/home/mande/repo/quber/.venv/lib/python3.13/site-packages/scipy/optimize/_shgo_lib/_vertex.pyÚ__init__ÚVertexBase.__init__   s6   € ð ŒÜ˜Ÿ™“LˆŒ	à‰>Ü˜"“gˆD�Gä“eˆDŒGà�
ó    c                 ó   • U R                   $ ©N)r   ©r   s    r   Ú__hash__ÚVertexBase.__hash__$   s   € Ø�y‰yÐr   c                 ó²   • US;  a  [        [        U 5       SU S35      eUS:X  a1  [        R                  " U R                  5      U l        U R
                  $ g )N)Úx_az object has no attribute 'Ú'r   )ÚAttributeErrorÚtypeÚnpÚarrayr
   r   )r   Úitems     r   Ú__getattr__ÚVertexBase.__getattr__'   sY   € Ø�wÓÜ ¤D¨£J <ð 0%Ø%) F¨!ð"-ó .ð .à�5‹=Ü—x’x §¡Ó'ˆDŒHØ—8‘8ˆOð r   c                 ó   • [        S5      e©NzKThis method is only implemented with an associated child of the base class.©ÚNotImplementedError©r   Úvs     r   ÚconnectÚVertexBase.connect/   ó   € ä!ð #Hó Ið 	Ir   c                 ó   • [        S5      er$   r%   r'   s     r   Ú
disconnectÚVertexBase.disconnect4   r+   r   c                 ór   • U R                   U l        U R                  R                  U 5        U R                  $ )z»Returns the star domain ``st(v)`` of the vertex.

Parameters
----------
v :
    The vertex ``v`` in ``st(v)``

Returns
-------
st : set
    A set containing all the vertices in ``st(v)``
)r   ÚstÚaddr   s    r   ÚstarÚVertexBase.star9   s(   € ð —'‘'ˆŒØ�‰�‰�DÔØ�w‰wˆr   )r   r   r   r0   r
   r   ©NN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r!   r   r)   r-   r2   Ú__static_attributes__© r   r   r   r   	   sG   † ñôò.òð ñIó ðIð ñIó ðIõr   r   c                   óL   ^ • \ rS rSrSr  S	U 4S jjrS rS rS rS r	Sr
U =r$ )
ÚVertexScalarFieldéK   zu
Add homology properties of a scalar field f: R^n --> R associated with
the geometry built from the VertexBase class
c                 ó>   >• [         TU ]  XUS9  SU l        SU l        g)aÑ  
Parameters
----------
x : tuple,
    vector of vertex coordinates
field : callable, optional
    a scalar field f: R^n --> R associated with the geometry
nn : list, optional
    list of nearest neighbours
index : int, optional
    index of the vertex
field_args : tuple, optional
    additional arguments to be passed to field
g_cons : callable, optional
    constraints on the vertex
g_cons_args : tuple, optional
    additional arguments to be passed to g_cons

©r   r   TN)Úsuperr   Ú	check_minÚ	check_max)	r   r
   Úfieldr   r   Ú
field_argsÚg_consÚg_cons_argsÚ	__class__s	           €r   r   ÚVertexScalarField.__init__Q   s'   ø€ ô* 	‰Ñ˜¨ÐÑ/ð ˆŒØˆ�r   c                 óÒ   • XLac  XR                   ;  aS  U R                   R                  U5        UR                   R                  U 5        SU l        SU l        SUl        SUl        ggg)zlConnects self to another vertex object v.

Parameters
----------
v : VertexBase or VertexScalarField object
TN)r   r1   rB   rC   r'   s     r   r)   ÚVertexScalarField.connectt   sU   € ð Š=˜Q§g¡gÓ-Ø�G‰G�K‰K˜ŒNØ�D‰D�H‰H�TŒNð "ˆDŒNØ!ˆDŒNØˆAŒKØˆA�Kð .ˆ=r   c                 óÈ   • XR                   ;   aS  U R                   R                  U5        UR                   R                  U 5        SU l        SU l        SUl        SUl        g g )NT)r   ÚremoverB   rC   r'   s     r   r-   ÚVertexScalarField.disconnect…   sN   € Ø—‘‹<Ø�G‰G�N‰N˜1ÔØ�D‰D�K‰K˜Ôð "ˆDŒNØ!ˆDŒNØˆAŒKØˆA�Kð r   c                 ó”   ^ • T R                   (       a+  [        U 4S jT R                   5       5      T l        ST l         T R                  $ )zBCheck whether this vertex is strictly less than all its
neighboursc              3   óV   >#   • U  H  nTR                   UR                   :  v •  M      g 7fr   ©Úf©Ú.0r(   r   s     €r   Ú	<genexpr>Ú.VertexScalarField.minimiser.<locals>.<genexpr>”   ó   øé € Ð:²'¨Q˜DŸF™F Q§S¡SžL²'ùó   ƒ&)F)rB   Úallr   Ú_minr   s   `r   Ú	minimiserÚVertexScalarField.minimiser�   s3   ø€ ð �>�>ÜÔ:°$·'²'Ó:Ó:ˆDŒIØ"ˆDŒNà�y‰yÐr   c                 ó”   ^ • T R                   (       a+  [        U 4S jT R                   5       5      T l        ST l         T R                  $ )zH
Check whether this vertex is strictly greater than all its
neighbours.
c              3   óV   >#   • U  H  nTR                   UR                   :„  v •  M      g 7fr   rQ   rS   s     €r   rU   Ú.VertexScalarField.maximiser.<locals>.<genexpr>Ÿ   rW   rX   F)rC   rY   r   Ú_maxr   s   `r   Ú	maximiserÚVertexScalarField.maximiser™   s3   ø€ ð
 �>�>ÜÔ:°$·'²'Ó:Ó:ˆDŒIØ"ˆDŒNà�y‰yÐr   )r`   rZ   rC   rB   )NNNr;   Nr;   )r5   r6   r7   r8   r9   r   r)   r-   r[   ra   r:   Ú__classcell__©rH   s   @r   r=   r=   K   s1   ø† ñð
 GIØ*,÷!òFò"	ò÷	ð 	r   r=   c                   ó6   ^ • \ rS rSrSr   SU 4S jjrSrU =r$ )ÚVertexVectorFieldé¥   zx
Add homology properties of a scalar field f: R^n --> R^m associated with
the geometry built from the VertexBase class.
r;   c
                 ó6   >• [         T
U ]  XU	S9  [        S5      e)Nr@   z&This class is still a work in progress)rA   r   r&   )r   r
   ÚsfieldÚvfieldrE   Úvfield_argsrF   rG   r   r   rH   s             €r   r   ÚVertexVectorField.__init__«   s#   ø€ ô 	‰Ñ˜¨ÐÑ/ä!Ð"JÓKÐKr   )NNr;   r;   Nr;   NN)r5   r6   r7   r8   r9   r   r:   rc   rd   s   @r   rf   rf   ¥   s!   ø† ñð
 @BØ(,Ø04÷Lõ Lr   rf   c                   ó0   • \ rS rSrSrS rS rS rS rSr	g)	ÚVertexCacheBaseé³   z7Base class for a vertex cache for a simplicial complex.c                 óT   • [         R                  " 5       U l        SU l        SU l        g )Nr   éÿÿÿÿ)ÚcollectionsÚOrderedDictÚcacheÚnfevr   r   s    r   r   ÚVertexCacheBase.__init__µ   s    € ä ×,Ò,Ó.ˆŒ
ØˆŒ	Øˆ�
r   c              #   óT   #   • U R                    H  nU R                   U   v •  M     g 7fr   )rt   r'   s     r   Ú__iter__ÚVertexCacheBase.__iter__»   s$   é € Ø—”ˆAØ—*‘*˜Q‘-Ôñ àùs   ‚&(c                 ó    • U R                   S-   $ )z%Returns the size of the vertex cache.é   ©r   r   s    r   ÚsizeÚVertexCacheBase.sizeÀ   s   € à�z‰z˜A‰~Ðr   c                 ó$  • [        S[        U R                  5       S35      n[        SU-  5        [        S[        U R                  5       S35        [        SU-  5        U R                   H   nU R                  U   R                  5         M"     g )NzVertex cache of size: Ú:Ú=)Úlenrt   ÚprintÚ	print_out)r   Úheadlenr(   s      r   r„   ÚVertexCacheBase.print_outÄ   st   € ÜÐ.¬s°4·:±:«Ð.?¸qÐAÓBˆÜˆc�G‰mÔÜÐ&¤s¨4¯:©:£Ð&7°qÐ9Ô:Üˆc�G‰mÔØ—”ˆAØ�J‰J�q‰M×#Ñ#Ö%ò r   )rt   r   ru   N)
r5   r6   r7   r8   r9   r   rx   r}   r„   r:   r;   r   r   rn   rn   ³   s   † ÙAòòò
õ&r   rn   c                   ó<   ^ • \ rS rSrSrSU 4S jjrS rS rSrU =r	$ )Ú
VertexCubeéÍ   z‡Vertex class to be used for a pure simplicial complex with no associated
differential geometry (single level domain that exists in R^n)c                 ó"   >• [         TU ]  XUS9  g )Nr@   )rA   r   )r   r
   r   r   rH   s       €r   r   ÚVertexCube.__init__Ð   s   ø€ Ü‰Ñ˜¨ÐÒ/r   c                 óš   • XLaG  XR                   ;  a7  U R                   R                  U5        UR                   R                  U 5        g g g r   )r   r1   r'   s     r   r)   ÚVertexCube.connectÓ   s5   € ØŠ=˜Q§g¡gÓ-Ø�G‰G�K‰K˜ŒNØ�D‰D�H‰H�T�Nð .ˆ=r   c                 ó�   • XR                   ;   a7  U R                   R                  U5        UR                   R                  U 5        g g r   )r   rM   r'   s     r   r-   ÚVertexCube.disconnectØ   s0   € Ø—‘‹<Ø�G‰G�N‰N˜1ÔØ�D‰D�K‰K˜Õð r   r;   r4   )
r5   r6   r7   r8   r9   r   r)   r-   r:   rc   rd   s   @r   rˆ   rˆ   Í   s   ø† ñF÷0ò÷
ð r   rˆ   c                   ó2   ^ • \ rS rSrU 4S jrSS jrSrU =r$ )ÚVertexCacheIndexéÞ   c                 ó8   >• [         TU ]  5         [        U l        g)z¢
Class for a vertex cache for a simplicial complex without an associated
field. Useful only for building and visualising a domain complex.

Parameters
----------
N)rA   r   rˆ   ÚVertex)r   rH   s    €r   r   ÚVertexCacheIndex.__init__ß   s   ø€ ô 	‰ÑÔÜ ˆ�r   c                 óØ   •  U R                   U   $ ! [         aN    U =R                  S-  sl        U R                  XR                  S9nX0R                   U'   U R                   U   s $ f = f)Nr{   r|   )rt   ÚKeyErrorr   r”   ©r   r
   r   Úxvals       r   Ú__getitem__ÚVertexCacheIndex.__getitem__ê   s`   € ð		!Ø—:‘:˜a‘=Ð øÜó 	!Ø�JŠJ˜!‰O�JØ—;‘;˜q¯
©
�;Ð3ˆDð !�J‰J�q‰MØ—:‘:˜a‘=Ò ð	!ús   ‚ ‘AA)Á(A))r”   r   )r5   r6   r7   r8   r   rš   r:   rc   rd   s   @r   r‘   r‘   Þ   s   ø† õ	!÷
!ò 
!r   r‘   c                   ó|   ^ • \ rS rSr  SU 4S jjrSS jrS rS rS rS r	S r
S	 rS
 rS rS rS rS rSrU =r$ )ÚVertexCacheFieldé÷   c                 ó  >• [         TU ]  5         SU l        [        U l        Xl        X l        [        X5      U l        X0l	        X@l
        [        X45      U l        [        5       U l        [        5       U l        SU l        XPl        [%        U5      U l        US:X  a8  U R(                  U l        Uc  U R,                  U l        gU R0                  U l        gU R2                  U l        Uc  U R4                  U l        gU R6                  U l        g)aw  
Class for a vertex cache for a simplicial complex with an associated
field.

Parameters
----------
field : callable
    Scalar or vector field callable.
field_args : tuple, optional
    Any additional fixed parameters needed to completely specify the
    field function
g_cons : dict or sequence of dict, optional
    Constraints definition.
    Function(s) ``R**n`` in the form::
g_cons_args : tuple, optional
    Any additional fixed parameters needed to completely specify the
    constraint functions
workers : int  optional
    Uses `multiprocessing.Pool <multiprocessing>`) to compute the field
     functions in parallel.

rq   Fr{   N)rA   r   r   r=   r”   rD   rE   ÚFieldWrapperÚwfieldrF   rG   ÚConstraintWrapperÚwgconsr   ÚgpoolÚfpoolÚsfc_lockÚworkersr   Ú_mapwrapperÚ
proc_gpoolÚprocess_gpoolÚproc_fpool_nogÚprocess_fpoolÚproc_fpool_gÚpproc_gpoolÚpproc_fpool_nogÚpproc_fpool_g)r   rD   rE   rF   rG   r§   rH   s         €r   r   ÚVertexCacheField.__init__ø   sÛ   ø€ ô0 	‰ÑÔØˆŒ
Ü'ˆŒØŒ
Ø$ŒÜ" 5Ó5ˆŒàŒØ&ÔÜ'¨Ó<ˆŒÜ“UˆŒ
ô “UˆŒ
ØˆŒàŒÜ% gÓ.ˆÔà�a‹<Ø!%§¡ˆDÔØ‰~Ø%)×%8Ñ%8�Õ"à%)×%6Ñ%6�Õ"à!%×!1Ñ!1ˆDÔØ‰~Ø%)×%9Ñ%9�Õ"à%)×%7Ñ%7�Õ"r   c                 óœ  •  U R                   U   $ ! [         a°    U =R                  S-  sl        U R                  XR                  X R                  U R
                  U R                  U R                  S9nX0R                   U'   U R                  R                  U5        U R                  R                  U5        U R                   U   s $ f = f)Nr{   )rD   r   r   rE   rF   rG   )rt   r—   r   r”   rD   rE   rF   rG   r¤   r1   r¥   r˜   s       r   rš   ÚVertexCacheField.__getitem__0  s¢   € ð	!Ø—:‘:˜a‘=Ð øÜó 
	!Ø�JŠJ˜!‰O�JØ—;‘;˜q¯
©
°rÇÁØ*.¯/©/Ø&*§k¡kØ+/×+;Ñ+;ð ð =ˆDð
 !�J‰J�q‰MØ�J‰J�N‰N˜4Ô Ø�J‰J�N‰N˜4Ô Ø—:‘:˜a‘=Ò ð
	!ús   ‚ ‘B7CÃ
Cc                 ó@   • U R                   R                  5       nUS	 U$ )NÚpool)Ú__dict__Úcopy)r   Ú	self_dicts     r   Ú__getstate__ÚVertexCacheField.__getstate__?  s"   € Ø—M‘M×&Ñ&Ó(ˆ	Ø�fÐØÐr   c                 ó~   • U R                   b  U R                  5         U R                  5         U R                  5         g r   )rF   rª   r¬   Úproc_minimisersr   s    r   Úprocess_poolsÚVertexCacheField.process_poolsD  s0   € Ø�;‰;Ñ"Ø×ÑÔ Ø×ÑÔØ×ÑÕr   c                 óþ   • SUl         [        U R                  U R                  5       HR  u  p#[        R
                  " U" UR                  /UQ76 S:  5      (       d  M6  [        R                  Ul        SUl           g    g ©NTg        F)	ÚfeasibleÚziprF   rG   r   Úanyr   ÚinfrR   )r   r(   ÚgÚargss       r   Úfeasibility_checkÚ"VertexCacheField.feasibility_checkJ  s[   € ØˆŒ
Ü˜4Ÿ;™;¨×(8Ñ(8Ö9‰GˆAä�vŠv‘a˜Ÿ™�o ’o¨Ñ+×,Ó,Ü—f‘f�”Ø"�”
Ùò :r   c                 óH  •  U R                   " UR                  /U R                  Q76 Ul        U =R                  S-  sl        [        R                  " UR                  5      (       a  [        R                  Ul        gg! [
         a    [        R                  Ul         N]f = f)zzCompute the scalar field values of a vertex object `v`.

Parameters
----------
v : VertexBase or VertexScalarField object
r{   N)	rD   r   rE   rR   ru   r   r   rÄ   Úisnanr'   s     r   Úcompute_sfieldÚVertexCacheField.compute_sfieldS  sp   € ð	Ø—*’*˜QŸU™UÐ5 T§_¡_Ò5ˆAŒCØ�IŠI˜‰N�Iô �8Š8�A—C‘C�=‰=Ü—&‘&ˆA�Cð øô ó 	Ü—&‘&ˆAŽCð	ús   ‚AA? Á?B!Â B!c                 ó„   • U R                   b$  U R                   H  nU R                  U5        M     [        5       U l        g)zProcess all constraints.N)rF   r¤   rÇ   r   r'   s     r   r©   ÚVertexCacheField.proc_gpoolc  s3   € à�;‰;Ñ"Ø—Z”Z�Ø×&Ñ& qÖ)ñ  ô “Uˆ�
r   c                 óú   • / nU R                    H  nUR                  UR                  5        M      U R                  U R                  R
                  U5      n[        U R                   U5       H  u  p$XBl        M     g)z$Process all constraints in parallel.N)r¤   Úappendr   r¨   r£   ÚgconsrÂ   rÁ   )r   Úgpool_lr(   ÚGrÅ   s        r   r®   ÚVertexCacheField.pproc_gpoolk  s_   € àˆØ—”ˆAØ�N‰N˜1Ÿ5™5Ö!ñ ð ×Ñ˜TŸ[™[×.Ñ.°Ó8ˆÜ˜Ÿ
™
 AÖ&‰DˆAØŽJò 'r   c                 ó�   • U R                    H'  nUR                  (       d  M  U R                  U5        M)     [        5       U l         g)z6Process all field functions with constraints supplied.N)r¥   rÁ   rË   r   r'   s     r   r­   ÚVertexCacheField.proc_fpool_gu  s2   € à—”ˆAØ�z�z‰zØ×#Ñ# AÖ&ñ ô “Uˆ�
r   c                 ój   • U R                    H  nU R                  U5        M     [        5       U l         g)z9Process all field functions with no constraints supplied.N)r¥   rË   r   r'   s     r   r«   ÚVertexCacheField.proc_fpool_nog}  s)   € à—”ˆAØ×Ñ Ö"ñ ô “Uˆ�
r   c                 óÄ  • U R                   R                    / nU R                   HF  nUR                  (       a  UR	                  UR
                  5        M1  [        R                  Ul        MH     U R                  U R                   R                  U5      n[        X5       H.  u  pE[        U5      nXPU   l        U =R                  S-  sl        M0     [        5       U l        g)zD
Process all field functions with constraints supplied in parallel.
r{   N)r¡   Úfuncr¥   rÁ   rÐ   r   r   rÄ   rR   r¨   rÂ   Útupleru   r   ©r   Úfpool_lr(   ÚFÚvarR   Úvts          r   r°   ÚVertexCacheField.pproc_fpool_g„  sž   € ð 	�‰×ÒØˆØ—”ˆAØ�z�zØ—‘˜qŸu™uÖ%ä—f‘f�–ñ	 ð
 ×Ñ˜TŸ[™[×-Ñ-¨wÓ7ˆÜ˜–_‰EˆBÜ�r“ˆBØ�‰HŒJØ�IŠI˜‰N�Iñ %ô
 “Uˆ�
r   c                 ót  • U R                   R                    / nU R                   H  nUR                  UR                  5        M      U R                  U R                   R                  U5      n[        X5       H.  u  pE[        U5      nXPU   l        U =R                  S-  sl	        M0     [        5       U l        g)zG
Process all field functions with no constraints supplied in parallel.
r{   N)r¡   rÚ   r¥   rÐ   r   r¨   rÂ   rÛ   rR   ru   r   rÜ   s          r   r¯   Ú VertexCacheField.pproc_fpool_nog—  sŠ   € ð 	�‰×ÒØˆØ—”ˆAØ�N‰N˜1Ÿ5™5Ö!ñ à×Ñ˜TŸ[™[×-Ñ-¨wÓ7ˆÜ˜–_‰EˆBÜ�r“ˆBØ�‰HŒJØ�IŠI˜‰N�Iñ %ô
 “Uˆ�
r   c                 óV   • U  H#  nUR                  5         UR                  5         M%     g)zCheck for minimisers.N)r[   ra   r'   s     r   r¼   Ú VertexCacheField.proc_minimisers§  s   € ãˆAØ�K‰KŒMØ�K‰KŽMò r   )r”   r¨   rD   rE   r¥   rF   rG   r¤   r   r¬   rª   r¦   r¡   r£   r§   )Nr;   Nr;   r{   r   )r5   r6   r7   r8   r   rš   r¹   r½   rÇ   rË   r©   r®   r­   r«   r°   r¯   r¼   r:   rc   rd   s   @r   r�   r�   ÷   sP   ø† ØKMØ÷68ôp!òò
òòò òòòòò&÷ ð r   r�   c                   ó$   • \ rS rSrSrS rS rSrg)r¢   i®  z=Object to wrap constraints to pass to `multiprocessing.Pool`.c                 ó   • Xl         X l        g r   ©rF   rG   )r   rF   rG   s      r   r   ÚConstraintWrapper.__init__°  s   € ØŒØ&Õr   c                 ó°   • Sn[        U R                  U R                  5       H/  u  p4[        R                  " U" U/UQ76 S:  5      (       d  M,  Sn  U$    U$ rÀ   )rÂ   rF   rG   r   rÃ   )r   Úv_x_aÚ	vfeasiblerÅ   rÆ   s        r   rÑ   ÚConstraintWrapper.gcons´  sV   € Øˆ	Ü˜4Ÿ;™;¨×(8Ñ(8Ö9‰GˆAä�vŠv‘a˜�o ’o¨Ñ+×,Ó,Ø!�	ØØÐñ :ð
 Ðr   rè   N)r5   r6   r7   r8   r9   r   rÑ   r:   r;   r   r   r¢   r¢   ®  s   † ÙGò'õr   r¢   c                   ó$   • \ rS rSrSrS rS rSrg)r    i¾  z7Object to wrap field to pass to `multiprocessing.Pool`.c                 ó   • Xl         X l        g r   ©rD   rE   )r   rD   rE   s      r   r   ÚFieldWrapper.__init__À  s   € ØŒ
Ø$�r   c                 óØ   •  U R                   " U/U R                  Q76 n[        R
                  " U5      (       a  [        R                  nU$ ! [         a    [        R                  n NIf = fr   )rD   rE   Ú	Exceptionr   rÄ   rÊ   )r   rë   Úv_fs      r   rÚ   ÚFieldWrapper.funcÄ  sU   € ð	Ø—*’*˜UÐ5 T§_¡_Ò5ˆCô �8Š8�C�=‰=Ü—&‘&ˆCàˆ
øô ó 	Ü—&‘&ŠCð	ús   ‚A ÁA)Á(A)rð   N)r5   r6   r7   r8   r9   r   rÚ   r:   r;   r   r   r    r    ¾  s   † ÙAò%õr   r    )rr   Úabcr   r   Únumpyr   Úscipy._lib._utilr   r   r=   rf   rn   rˆ   r‘   r�   r¢   r    r;   r   r   Ú<module>rù      s€   ðÛ ß #ã å 'ô?�ô ?ôDW˜
ô WôtL˜
ô L÷&ñ &ô4�ô ô"!�ô !ô2t�ô t÷nñ ÷ ò r   