o 6a@s@dZddlZddlmZGdddZddZdd d Zd ddd d dZe dkre deej de e de e deej dddde e deej dddde e deej dddd e e deej dddd e e deej ddddd e ded d d d dSdS)z:Prints type-coercion tables for the built-in NumPy types N) namedtuplec@s.eZdZddZddZddZedZdS) GenericObjectcCs ||_dSN)v)selfrrE/usr/lib/python3/dist-packages/numpy/testing/print_coercion_tables.py__init__ s zGenericObject.__init__cC|Srrrotherrrr__add__ zGenericObject.__add__cCr rrr rrr__radd__rzGenericObject.__radd__ON)__name__ __module__ __qualname__r r rnpdtyperrrrr s rcCstddd|D]}t|ddqt|D]@}t|dd|D]2}t||dr,d}n t||dr6d}nt||dr@d }n t||d rJd }nd}t|ddq tqdS) NX endequiv#safe= same_kind~unsafe.)printrcan_cast)ntypescharrowcolcastrrrprint_cancast_tables&  r)Fc CsFtddd|D]}t|ddqt|D]}|dkrt}nt|}t|dd|D]p}|dkr5t} nt|} z<|rHtj||g|d} n||} | |} |r\t| j| jj}nt| | } t | tj rm| jj}ntt | j}Wnt yd}Ynt yd}Yn tyd}Ynwt|ddq,tqdS) N+rrr)r!@r)r"rr obj2sctypearray promote_typesrr%add isinstancendarraytype ValueError OverflowError TypeError) r$inputfirstvalueinputsecondvalue firstarrayuse_promote_typesr%r&rowtyper'coltyperowvaluecolvaluevaluerrrprint_coercion_table*sF          r@Tr#legacyflagsc sddlm}dddddd}dd d d d d ddd}tdgd}|ddd|}it|D]Y}|d|d|dvrLi|d<|d} ||d}|dr^dnd}d}|drj|dO}|drr|dO}|drz|dO}||}||||d| |d<q0tjdfd d!} t| d"d.fd$d% } |rttd&t| d#|rttd't| d|rtt|dd(|dd)|dd*|dd+t| d,d-Sd-S)/z[Prints new casts, the values given are default "can-cast" values, not actual ones. r)get_all_cast_informationrrrr!)ru▗u█u▚u▐u▄u▜u▙u▟)rrErFrHrG cast_inforArfromtocastingrBLrequires_pyapirEsupports_unalignedrFno_floatingpoint_errorsrHAllcs@t|j}z|j}Wn tytj}Ynw||jfSr)rrr3indexr%r4inf)xrindx)typesrrsorters    z$print_new_cast_table..sorter)keyr#cstdddD] }tt|jjddqtD](}tt|jjdd|i}D]}tt|||ddq0tqdS)Nrrr)r"rrr3r%getgetattr)fielddtfrom_dtr&to_dt)dtypes no_cast_infotablerr print_tables  z)print_new_cast_table..print_tablezDCasting: # is equivalent, = is safe, ~ is same-kind, and . is unsafez+L denotes a legacy cast . a non-legacy one.z : no flags, z : PyAPI, z: supports unaligned, z: no-float-errorsrCN)r#) numpy.core._multiarray_testsrDrsetr0r typecodessortedr") r#rBrCrD cast_table flags_tablerLcastsr(to_dictrZrer)rbrcrdrYrprint_new_cast_tableSst            rn__main__zcan castrTzJIn these tables, ValueError is '!', OverflowError is '@', TypeError is '#'zscalar + scalarzscalar + neg scalarzarray + scalarzarray + neg scalarr/zNew casting type promotion:)F) __doc__numpyr collectionsrrr)r@rnrr"rhrrrrs<  )_