
    ]hFQ                        S r SSKrSSK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Jr  SSK	J
r
  SSKJrJrJrJrJrJr  SSKJr  SSKJrJrJrJr  SS	KJr  SS
KJr  / SQrSSS.r/ SQr\\ \RB                  S4   r" " S S5      r#S\ S\#S\\ \4   4S jr$    S%S\\ \
4   S\%S\\\ \4      S\\\ \4      S\"S\ 4S jjr&SSSSSS.S\\ \RB                  4   S \%S!\\%\ \\    4   S"\'S#\%S\\\ \4      SS4S$ jjr(g)&z.
Makefile options for stanc and C++ compilers
    N)copy)datetime)Path)AnyDictIterableListOptionalUnion)
get_logger)	EXTENSIONcmdstan_pathcmdstan_versioncmdstan_version_before)
do_command)SanitizedOrTmpFilePath)
OO0O1Oexperimentalallow-undefined
use-openclzwarn-uninitializedinclude-pathsnamezwarn-pedanticr   r   )allow_undefinedinclude_paths)z	debug-lexzdebug-parsez	debug-astzdebug-decorated-astzdebug-generate-dataz	debug-mirzdebug-mir-prettyzdebug-optimized-mirzdebug-optimized-mir-prettyzdebug-transformed-mirzdebug-transformed-mir-prettyzdump-stan-math-signatureszauto-formatzprint-canonicalz	print-cppohelpversionc            
          \ rS rSrSrSSSS.S\\\\4      S\\\\4      S\	SS4S	 jjr
S\4S
 jrS\S\4S jrS\4S jr\S\\\\\\\\   4   4   4S j5       r\S\\\\\4   4   4S j5       r\S\4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\SS4S jrS\\   S\\   4S jrSS\\   S\\   4S jjrSrg)CompilerOptionsF   z
User-specified flags for stanc and C++ compiler.

Attributes:
    stanc_options - stanc compiler flags, options
    cpp_options - makefile options (NAME=value)
    user_header - path to a user .hpp file to include during compilation
Nstanc_optionscpp_optionsuser_headerr$   r%   r&   returnc                j    Ub  UO0 U l         Ub  UO0 U l        Ub  [        U5      U l        gSU l        g)zInitialize object.N )_stanc_options_cpp_optionsstr_user_header)selfr$   r%   r&   s       hC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\cmdstanpy/compilation.py__init__CompilerOptions.__init__P   s;     0=/Hmb+6+BK0;0GC,R    c                 N    SR                  U R                  U R                  5      $ )Nz stanc_options={}, cpp_options={})formatr*   r+   r.   s    r/   __repr__CompilerOptions.__repr__\   s&    188!2!2
 	
r2   otherc                    U R                  5       (       a  Uc  g[        U[        5      (       d  gU R                  UR                  :H  =(       a9    U R
                  UR                  :H  =(       a    U R                  UR                  :H  $ )z$Overrides the default implementationTF)	is_empty
isinstancer!   r*   r$   r+   r%   r-   r&   )r.   r8   s     r/   __eq__CompilerOptions.__eq__a   so    ==??u}%115#6#66 7!!U%6%667!!U%6%66	
r2   c                 x    U R                   0 :H  =(       a%    U R                  0 :H  =(       a    U R                  S:H  $ )zTrue if no options specified.r)   )r*   r+   r-   r5   s    r/   r:   CompilerOptions.is_emptym   s=     2% (!!R'(!!R'	
r2   c                     U R                   $ )zStanc compiler options.)r*   r5   s    r/   r$   CompilerOptions.stanc_optionsu   s     """r2   c                     U R                   $ )zC++ compiler options.)r+   r5   s    r/   r%   CompilerOptions.cpp_optionsz           r2   c                     U R                   $ )zuser header.)r-   r5   s    r/   r&   CompilerOptions.user_header   rD   r2   c                 d    U R                  5         U R                  5         U R                  5         g)zE
Check compiler args.
Raise ValueError if invalid options are found.
N)validate_stanc_optsvalidate_cpp_optsvalidate_user_headerr5   s    r/   validateCompilerOptions.validate   s(    
 	  " !!#r2   c                    U R                   c  g/ nSnSn[        R                  5        H  u  pEX@R                   ;   d  M  U(       aO  [        5       R	                  SUU5        [        U R                   U   5      U R                   U'   U R                   U	 Ml  [        5       R	                  SU5        M     U R                   R                  5        GH   u  pgU[        ;   a-  [        5       R                  SU5        UR                  U5        M=  U[        ;  a  [        SU 35      eUS:X  aY  Un[        U[        5      (       a  UR                  S5      nM  [        U[        5      (       d  [        S	[        U5       S
35      eM  US:X  a)  U R                   c  SS0U l        M  SU R                   S'   M  UR#                  S5      (       d  M  U(       a  [        5       R	                  S5        GM  SnGM#     U H  nU R                   U	 M     Ub  U V	s/ s H+  n	[$        R&                  R)                  U	5      (       a  M)  U	PM-     n
n	[+        U
5      (       a)  [        SR-                  SR/                  U
5      5      5      eU Vs/ s H?  n[$        R&                  R1                  [$        R&                  R3                  U5      5      PMA     snU R                   S'   ggs  sn	f s  snf )zs
Check stanc compiler args and consistency between stanc and C++ options.
Raise ValueError if bad config is found.
NFz4compiler option "%s" is deprecated, use "%s" insteadz9compiler option "%s" is deprecated and should not be usedzignoring compiler option: %szunknown stanc compiler option: r   ,z=Invalid include-paths, expecting list or string, found type: .r   STAN_OPENCLTRUEr   z^More than one of (O, O1, O2, Oexperimental)optimizations passed. Only the last one willbe usedTzinvalid include paths: {}, )r*   STANC_DEPRECATED_OPTSitemsr   warningr   STANC_IGNORE_OPTSinfoappend
STANC_OPTS
ValueErrorr;   r,   splitlisttyper+   
startswithospathexistsanyr4   joinabspath
expanduser)r.   ignorepaths
has_o_flag
deprecatedreplacementkeyvaloptdir	bad_pathsr`   s               r/   rH   #CompilerOptions.validate_stanc_opts   s    &
'<'B'B'D#J000L((N"#
 8<++J78D''4 ++J7L((-" (E$ ++113HC''!!"@#Fc"J& #B3%!HII'c3''IIcNE#C..$//3Cyk<  /
 $$$,)6(?D%7=D%%m4$$L((" "&J9 4< C##C( (-IRWW^^C5HII9~~ /66tyy7KL 
 GL4FKd 2 24 89e4D0 I4s   (K;K AKc                     U R                   c  gS H^  nXR                   ;   d  M  SU R                   S'   U R                   U   n[        U[        5      (       a  US:  d  MO  [        U SU S35      e   g)zC
Check cpp compiler args.
Raise ValueError if bad config is found.
N)OPENCL_DEVICE_IDOPENCL_PLATFORM_IDrQ   rP   r   z- must be a non-negative integer value, found rO   )r+   r;   intrZ   )r.   rk   rl   s      r/   rI   !CompilerOptions.validate_cpp_opts   s    
 $=C'''39!!-0'',!#s++sQw$%  ""%a)  >r2   c                    U R                   S:w  Gaw  [        R                  R                  U R                   5      (       a.  [        R                  R	                  U R                   5      (       d  [        SU R                    S35      eU R                   SS S:w  a  [        SU R                    35      eSU R                  ;  a  S	U R                  S'   [        R                  R                  U R                   5      U l         S
U R                   ;   a  [        S5      eSU R                  ;   aE  U R                   U R                  S   :w  a(  [        SU R                    SU R                  S    35      eU R                   U R                  S'   gg)z>
User header exists.
Raise ValueError if bad config is found.
r)   zUser header file z cannot be foundN.hppz"Header file must end in .hpp, got r   T z9User header must be in a location with no spaces in path!USER_HEADERz/Disagreement in user_header C++ options found!
rR   )	r-   r_   r`   ra   isfilerZ   r*   rd   r+   r5   s    r/   rJ   $CompilerOptions.validate_user_header   sn   
 "t0011GGNN4#4#455 '(9(9'::JK    %/ 89J9J8KL  !(;(;;9=##$56 "0A0A BDd''' O 
 !2!22%%):):=)II F(()D,=,=m,L+MO 
 04/@/@Dm,? #r2   c                    UR                   b  U R                  c  UR                   U l        OUR                   R                  5        H  u  p#US:X  ak  [        U[        5      (       a:  [        U[
        5      (       d%  U H  nU R                  [        U5      5        M     MZ  U R                  [        U5      5        Mv  X0R                  U'   M     UR                  b1  UR                  R                  5        H  u  p#X0R                  U'   M     UR                  S:w  a#  U R                  S:X  a  UR                  U l	        ggg)z1Adds options to existing set of compiler options.Nr   r)   )
r$   r*   rT   r;   r   r,   add_include_pathr%   r+   r-   )r.   new_optsrk   rl   r`   s        r/   addCompilerOptions.add  s   !!-""*&.&<&<# ( 6 6 < < >HCo-%c844Z> > ), $ 5 5c$i @ ), !11#c(;36++C0 !? +$00668),!!#& 9  B&4+<+<+B ( 5 5D ,C&r2   r`   c                     [         R                  R                  [         R                  R                  U5      5      nSU R                  ;  a  U/U R                  S'   gXR                  S   ;  a  U R                  S   R                  U5        gg)z6Adds include path to existing set of compiler options.r   N)r_   r`   rd   re   r*   rX   )r.   r`   s     r/   r~    CompilerOptions.add_include_path$  sr    wwrww11$78$"5"55486D0,,_==077= >r2   filename_in_msgc           	         / nUb  UR                  SU 35        U R                  b  [        U R                  5      S:  a  U R                  R                  5        Ht  u  p4US:X  a9  UR                  SSR	                  S U R                  S    5       5      -   5        MD  US:X  a  UR                  SU 35        M`  UR                  S	U 35        Mv     U$ )
Nz--filename-in-msg=r   r   z--include-paths=rN   c              3   T   #    U  H  n[        U5      R                  5       v   M      g 7fN)r   as_posix).0ps     r/   	<genexpr>0CompilerOptions.compose_stanc.<locals>.<genexpr>8  s'      )MA !%Q 0 0 2 2)Ms   &(r   z--name=z--)rX   r*   lenrT   rc   )r.   r   optsrk   rl   s        r/   compose_stancCompilerOptions.compose_stanc,  s    &KK,_,=>?*s43F3F/G!/K //557/)KK*(()-)<)<_)M F]KK'#0KK"SE
+ 8 r2   c                 6   U R                  U5       Vs/ s H  nSUR                  SS5      -   PM     nnU R                  bR  [        U R                  5      S:  a9  U R                  R	                  5        H  u  pEUR                  U SU 35        M     U$ s  snf )z
Format makefile options as list of strings.

Parameters
----------
filename_in_msg : str, optional
    filename to be displayed in stanc3 error messages
    (if different from actual filename on disk), by default None
zSTANCFLAGS+=ry   z\ r   =)r   replacer+   r   rT   rX   )r.   r   flagr   rk   rl   s         r/   composeCompilerOptions.composeD  s     **?;
; T\\#u55; 	 
 (S1B1B-Ca-G --335se1SEN+ 6
s   B)r+   r*   r-   )r'   N)r   r!   r'   Nr   ) __name__
__module____qualname____firstlineno____doc__r
   r   r,   r   OptionalPathr0   r6   boolr<   r:   propertyr   rt   r   r$   r%   r&   rK   rH   rI   rJ   r   r~   r	   r   r   __static_attributes__ r2   r/   r!   r!   F   st    3704$(
P  S#X/
P d38n-	
P
 "
P 

P
# 



C 

D 


$ 
 #tCtS#x}/L)M$MN # # !T#uT3Y'7"78 ! ! !S ! !$GR"$AL6.>S >T >Xc] tCy 0x} S	  r2   r!   	stan_filecompiler_optionsr'   c                 n   [         R                  R                  [        5       SS[        -   5      /UR                  S5      -   S[        U 5      /-   n[        R                  " USSSS9nUR                  (       a  [        SU  S	UR                   35      e[        R                  " UR                  5      nU$ )
z
Get source info for Stan program file.

This function is used in the implementation of
:meth:`CmdStanModel.src_info`, and should not be called directly.
binstancNz--infoTFcapture_outputtextcheckz*Failed to get source info for Stan model ''. Console:
)r_   r`   rc   r   r   r   r,   
subprocessrun
returncoderZ   stderrjsonloadsstdout)r   r   cmdprocresults        r/   src_infor   X  s     
lneWy-@	AB

(
(
.	/ S^
$	%  >>#dUKD{-}6
 	
 "ZZ4FMr2   Fsrcforcer$   r%   r&   c                   ^ [        U 5      R                  5       n U R                  5       (       d  [        SU  35      e[	        UUUS9nUR                  5         U R                  [        5      nUR                  5       (       a  [        R                  R                  U5      mU /nUR                  [        [        U 5      U5      R                  S/ 5      5        [        U4S jU 5       5      nU(       d+  U(       d$  [!        5       R#                  S5        [        U5      $ Sn	[%        [        U 5      5       u  p[        R                  R'                  U
5      S   [        -   n[        R                  R'                  U5      S   S-   n[        R                  R                  U5      (       a  [        R(                  " U5        [        R                  R                  U5      (       a0  [!        5       R#                  S	U5        [        R(                  " U5        [!        5       R+                  S
U
U5        [        R,                  " S[.        R0                  " 5       S:w  a  SOS5      nU/nUR                  UR3                  U R4                  S95        UR7                  [        U5      R9                  5       5        [:        R<                  " 5       n [?        U[A        5       US9  URG                  5       n[!        5       R#                  SU5        U	(       d7  U(       a  [H        RJ                  " X5        [!        5       R+                  SU5        SU;   aw  URM                  S5      nU Vs/ s H  nURO                  S5      (       d  M  UPM     nn[!        5       RQ                  S[S        U5      5        [!        5       RQ                  U5        U	(       a6  SU;   d  SU;   a  [!        5       RQ                  S5        [        SU  SU 35      e[        U5      sSSS5        $ ! [B         a+  nURE                  S[        U5       S35        Sn	 SnAGNfSnAff = f! URG                  5       nf = fs  snf ! , (       d  f       g= f)a<  
Compile the given Stan program file.  Translates the Stan code to
C++, then calls the C++ compiler.

By default, this function compares the timestamps on the source and
executable files; if the executable is newer than the source file, it
will not recompile the file, unless argument ``force`` is ``True``
or unless the compiler options have been changed.

:param src: Path to Stan program file.

:param force: When ``True``, always compile, even if the executable file
    is newer than the source file.  Used for Stan models which have
    ``#include`` directives in order to force recompilation when changes
    are made to the included files.

:param stanc_options: Options for stanc compiler.
:param cpp_options: Options for C++ compiler.
:param user_header: A path to a header file to include during C++
    compilation.
zstan file does not exist: r#   included_filesc              3   h   >#    U  H'  n[         R                  R                  U5      T:  v   M)     g 7fr   )r_   r`   getmtime)r   included_fileexe_times     r/   r   $compile_stan_file.<locals>.<genexpr>  s,      
!/ GG]+h6!/s   /2z%found newer exe file, not recompilingFr   rx   zRemoving %sz%compiling stan file %s to exe file %sMAKEWindowsmakezmingw32-make)r   )r   cwdfd_out
TNzConsole output:
%szcompiled model executable: %sWarningz'Stan compiler has produced %d warnings:PCHzprecompiled headerzCmdStan's precompiled header (PCH) files may need to be rebuilt.Please run cmdstanpy.rebuild_cmdstan().
If the issue persists please open a bug reportzFailed to compile Stan model 'r   )*r   resolvera   rZ   r!   rK   with_suffixr   r_   r`   r   extendr   r,   getrb   r   debugr   splitextremoverW   getenvplatformsystemr   r   rX   r   ioStringIOr   r   RuntimeErrorwritegetvalueshutilr   r[   r^   rU   r   )r   r   r$   r%   r&   r   
exe_targetr   out_of_datecompilation_failedr   	is_copiedexe_filehpp_filer   r   souteconsolelinesxwarningsr   s                         @r/   compile_stan_filer   q  s   : s)


C::<<5cU;<<&#
 +J77##J/SX/0445ErJ	
  
!/
 
 5LFGz?" 
 C	)-Ci77##I.q1I=77##H-a06977>>(##IIh77>>(##L}h7IIh3	
 yyoo'94F.
 f

#++CHH+EF

4>**,-{{}	&3LN4@
 mmoG0':!H1L=zJMM$'E#(D5aALL,C5HDL  9H L  )#77#B$$E 05FwiP  :s 
*	)6  	&JJCF82'!%	& mmoG EQ 
*	)sW   6FQ&PBQ&!Q!?Q!BQ&
Q	 Q>QQ		QQQ&&
Q4N   T)overwrite_filecanonicalizemax_line_lengthbackupr$   r   r   r   r   c                   [        U 5      R                  5       n U R                  5       (       d  [        SU  35      e [        R
                  R                  [        5       SS[        -   5      /[        US9R                  S5      -   [        U 5      /-   nU(       a  [        SS5      (       aX  [        U[        5      (       a  UR                  S5        O[        S	S
R!                  [#        5       =(       d    S5      -   S-   5      e[        U[        5      (       a  UR                  SU-   5        OJ[        U[$        5      (       a$  UR                  SSR                  U5      -   5        OUR                  S5        [        SS5      (       a  U(       d  UR                  S5        [        SS5      (       d  UR                  SU 35        O7US:w  a1  [        SSR!                  [#        5       =(       d    S5      -   S-   5      e[&        R(                  " USSSS9nUR*                  (       a#  [-        5       R/                  UR*                  5        UR0                  nU(       ai  U(       aa  U(       aH  [2        R4                  " U [        U 5      S-   [6        R8                  " 5       R;                  S5      -   5        U R=                  U5        gg[?        U5        g! [        [@        4 a  n	[A        S5      U	eSn	A	ff = f)a  
Run stanc's auto-formatter on the model code. Either saves directly
back to the file or prints for inspection

:param stan_file: Path to Stan program file.
:param overwrite_file: If True, save the updated code to disk, rather
    than printing it. By default False
:param canonicalize: Whether or not the compiler should 'canonicalize'
    the Stan model, removing things like deprecated syntax. Default is
    False. If True, all canonicalizations are run. If it is a list of
    strings, those options are passed to stanc (new in Stan 2.29)
:param max_line_length: Set the wrapping point for the formatter. The
    default value is 78, which wraps most lines by the 80th character.
:param backup: If True, create a stanfile.bak backup before
    writing to the file. Only disable this if you're sure you have other
    copies of the file or are using a version control system like Git.
:param stanc_options: Additional options to pass to the stanc compiler.
zFile does not exist: r   r   )r$   N      z--print-canonicalz,Invalid arguments passed for current CmdStanz version({})
Unknownz&--canonicalize requires 2.29 or higherz--canonicalize=rN   z--auto-formatz--max-line-length=r   z4Invalid arguments passed for current CmdStan versionz ({})
z)--max-line-length requires 2.29 or higherTr   z.bak-z%Y%m%d%H%M%SzStanc formatting failed)!r   r   ra   rZ   r_   r`   rc   r   r   r!   r   r,   r   r;   r   rX   r4   r   r   r   r   r   r   rU   r   r   copyfiler   nowstrftime
write_textprintr   )
r   r   r   r   r   r$   r   outr   r   s
             r/   format_stan_filer     s}   6 Y'')I0<==<=WW\\,.%91DEFM:HHNO 9~ 	 %a,,lD11JJ23$F*11+-: C	C  lC00JJ0<?@h77JJ0388L3IIJJJ23 'q"--,JJ'%a,,JJ+O+<=>"F""?#4#A	BC=>  nnSDM::L  ,OO!I!"",,.11.AB $$V,  &M% =451<=s   JK K K3"K..K3)FNNN))r   r   r   r_   r   r   r   r   r   pathlibr   typingr   r   r   r	   r
   r   cmdstanpy.utilsr   cmdstanpy.utils.cmdstanr   r   r   r   cmdstanpy.utils.commandr   cmdstanpy.utils.filesystemr   rY   rS   rV   r,   PathLiker   r!   r   r   r   rt   r   r   r2   r/   <module>r      s   
  	       = = &  / =
 )$ 
 * S"++t+,O Od&5	#s(^6 .2,0 $s	sDy	ss DcN+s $sCx.)	s
 s 	sr !49.2\=S"++%&\= \= c8C=01	\=
 \= \= DcN+\= 
\=r2   