K iddlZddlZddlmZddlmZddlmZddl m Z ddlm Z ddl m Z ddlmZdd lmZmZddlZe d ZGd d eeZd Zy)N) version_tuple)Iterable)Mul)S)Sqrt) import_module) PRECEDENCE)AbstractPythonCodePrinter ArrayPrinter tensorflowc eZdZdZdZiej dejdejdejdejdejde d ejd ejd ejd ej d ej"dej$dej&dej(dej*dej,diej.dej0dej2dej4dej6dej8dej:dej<dej>dej@dejBdejDdejFd ejHd!ejJd"ejLd#ejNd$ejPd%ejRd&ejTd'ejVd(ejXd)ejZd*iZ.e/e0jbd+,Z1d@fd- Z2fd.Z3e3Z4e3Z5e3Z6e3Z7e3Z8e3Z9e3Z:e3Z;e3Zd0Z?d1Z@d2ZAd3ZBd4ZCd5ZDd6ZEd7ZFd8ZGd9ZHd:ZId;ZJdZMd?ZNxZOS)ATensorflowPrinterz Tensorflow printer which handles vectorized piecewise functions, logical operators, max/min, and relational operators. _tensorflowcodeztensorflow.math.absztensorflow.math.signztensorflow.math.ceilztensorflow.math.floorztensorflow.math.logztensorflow.math.exptensorflow.math.sqrtztensorflow.math.cosztensorflow.math.acosztensorflow.math.sinztensorflow.math.asinztensorflow.math.tanztensorflow.math.atanztensorflow.math.atan2ztensorflow.math.coshztensorflow.math.acoshztensorflow.math.sinhztensorflow.math.asinhztensorflow.math.tanhztensorflow.math.atanhztensorflow.math.realztensorflow.math.imagztensorflow.math.angleztensorflow.math.erfztensorflow.math.lgammaztensorflow.math.equalztensorflow.math.not_equalztensorflow.math.greaterztensorflow.math.lessztensorflow.math.less_equalztensorflow.math.greater_equalztensorflow.math.logical_andztensorflow.math.logical_orztensorflow.math.logical_notztensorflow.math.maximumztensorflow.math.minimumztensorflow.math.addztensorflow.math.multiplyztensorflow.linalg.traceztensorflow.linalg.detN)tensorflow_versionct|||jd}|trtj}||_y)Nr)super__init__ _settingsr __version__r)selfsettingsversion __class__s _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/printing/tensorflow.pyrzTensorflowPrinter.__init__Ss9 "..!56 ?z ,,G")c>|jjt|d}|t||S|j Dcgc]}|j |}}t|dk(r|j|d|ddS|j||Scc}w)N(r)) mappinggettyper _print_Basicargs_printlen_module_format_expand_fold_binary_op)rexpropargchildrenrs r_print_Functionz!TensorflowPrinter._print_Function[s \\  d4j$ / :7'- -04 :DKK$:: x=A ##B'   ..r8< <;sBcz|jd}dj||j|jS)Nztensorflow.linalg.inv{}({}))r(formatr&r,)rr*r+s r_print_Inversez TensorflowPrinter._print_Inversets1  !8 9r4;;txx#899rc|j}|r)t|tdkr|jd}n|jd}dj||j |j S)Nz1.14ztensorflow.matrix_transposez"tensorflow.linalg.matrix_transposer0)rrr(r1r&r,)rr*rr+s r_print_Transposez"TensorflowPrinter._print_Transposexsa)) }W- f0EE$$%BCB$$%IJBr4;;txx#899rc|j}td|Dr tdfd|j|S)Nc3<K|]}t|tywN) isinstancer).0is r z6TensorflowPrinter._print_Derivative..s:1z!X&:sz1derivation by multiple variables is not supportedc|sj|Sjdd||dddj|ddS)Nztensorflow.gradientsr, z)[0])r&r()r*r%runfolds rr?z3TensorflowPrinter._print_Derivative..unfoldsN{{4((''(>?4cr+KKR) r) variablesanyNotImplementedErrorr*)rr*r@r?s` @r_print_Derivativez#TensorflowPrinter._print_Derivatives>NN : : :%&YZ Z dii++rc  |j}|rt|tdkrd}nd}ddlm}|jdj\}}t |jdk(rAdj |j||j||j|dSdj |j||j||j||j||jddS)Nz1.0ztensorflow.selectztensorflow.wherer) Piecewiserz{}({}, {}, {})) rr$sympy.functions.elementary.piecewiserEr%r'r1r(r&)rr*rtensorflow_piecewiserEeconds r_print_Piecewisez"TensorflowPrinter._print_Piecewises)) }W- e0DD#6 #5 B))A,##4 tyy>Q #**##$89 D! A    &&    4 5 KK  KKN KK 499QR=1 2 4 4rc:|j\}}|jtjk(r0dj |j d|j |Sdj |j d|j ||j |S)Nr0rz {}({}, {})ztensorflow.math.pow)r%exprHalfr1r(r&)rr*baserLs r _print_PowzTensorflowPrinter._print_PowsII c 88qvv ??##$:;T[[=NP P""    5 6 KK t{{3/1 1rc4|jrdnd}ddj|jDcgc]6}ddj|Dcgc]}|j|c}zdz8c}}zdz}|j |d|dScc}wcc}}w)Nztensorflow.Variableztensorflow.constant[r>]rr ) free_symbolsjointolistr&r()rr* tensorflow_fr:jdatas r_print_MatrixBasez#TensorflowPrinter._print_MatrixBases040A0A,G\ 499VZVaVaVcdQRc$))Q,GT[[^,G"HHLdeefii    -   -HdsB BB B cTddlm}|jDcgc]}t||s|}}|jDcgc] }||vs| }}|rA|j t j |tdd|jd|S|jd|Scc}wcc}w)Nr) MatrixExprr*tensorflow.linalg.matmul) sympy.matrices.expressionsr[r%r8 parenthesizerfromiterr r))rr*r[r,mat_argsr%s r _print_MatMulzTensorflowPrinter._print_MatMuls9#'99LC 3 0KCLL#yy@Cx,?@@ !!#,,t"4j6GH++.:  ..*H6 6M@sB B  B%B%cV|jd|jg|jzS)Nr])r)rNrL)rr*s r _print_MatPowzTensorflowPrinter._print_MatPows)** & DHH(<> >rcg}|jD]"}|j|j|$dj|S)N )r%appendr&rT)rr*retsubexprs r_print_CodeBlockz"TensorflowPrinter._print_CodeBlocks=yy -G JJt{{7+ , -yy~rc<d|j|jdS)Nztensorflow.math.is_nan(r r&r%rrLs r _print_isnanzTensorflowPrinter._print_isnan!(chh)?(@BBrc<d|j|jdS)Nztensorflow.math.is_inf(r rlrms r _print_isinfzTensorflowPrinter._print_isinfrorr z linalg.einsumzmath.add transposeoneszerosr7)P__name__ __module__ __qualname____doc__ printmethodsympyAbssignceilingfloorlogrLrcosacossinasintanatanatan2coshacoshsinhasinhtanhatanhreimr,erfloggammaEqNeStrictGreaterThanStrictLessThanLessThan GreaterThanAndOrNotMaxMinMatAddHadamardProductTrace Determinantr!dictr _default_settingsrr. _print_Expr_print_Application_print_MatrixExpr_print_Relational _print_Not _print_And _print_Or_print_HadamardProduct _print_Trace_print_Determinantr2r4rCrJrOrYrbrdrjrnrq_module_einsum_add _transpose_ones_zeros __classcell__)rs@rrrsk$K5 (5 *5  - 5  , 5  (5  (5 $5  (5  *5  (5  *5  (5  *5  ,!5$  *%5&  ,'5(  *)5*  ,+5,  *-5.  ,/52 (354 (556  *75<  (=5> 0?5B )C5D -E5F !:G5H 4I5J 4K5L :M5P  0Q5R .S5T  0U5V  , ,  + 9 . 3i5Gn!33 * ="K('' J JI,"L(:: ,4, 1  6>CCGG DJ E Frrc :t|}|j|Sr7)rdoprint)r*rprinters rtensorflow_coders)G ??4  r) sympy.codegenrzsympy.codegen.cfunctionssympy.external.importtoolsrcollections.abcrsympy.core.mulrsympy.core.singletonrrsympy.externalrsympy.printing.precedencer sympy.printing.pycoder r r rrrrrsG4$")(0I < ( K &?K\!r