K iUTddlZddlZddlZddlmZddlmZmZm Z ejjGddejZ GddejZGdd ejZGd d ejZGd d ejZejjGddejZejjGddejZejjGddejZy)N)util)assert_array_equal assert_equal assert_raisesceZdZdZdZgdZdZeD]ZeZddijeeZ ee jdjgdeded e d ededed ed e d ed eded ede ded ededede dedededede dededz Zejj!dedZejj!dedddZejj!dedZejj!dedZejj!dedZy)TestCharacterString.f90test_character_string13starr(*)z subroutine _input_z(c, o, n) character*z, intent(in) :: c integer n !f2py integer, depend(c), intent(hide) :: n = slen(c) integer*1, dimension(n) :: o !f2py intent(out) o o = transfer(c, o) end subroutine _output_z, intent(out) :: c integer n integer*1, dimension(n), intent(in) :: o !f2py integer, depend(o), intent(hide) :: n = len(o) c = transfer(o, c) end subroutine _array_input_z;(c, o, m, n) integer m, i, n character*aH, intent(in), dimension(m) :: c !f2py integer, depend(c), intent(hide) :: m = len(c) !f2py integer, depend(c), intent(hide) :: n = f2py_itemsize(c) integer*1, dimension(m, n), intent(out) :: o do i=1,m o(i, :) = transfer(c(i), o(i, :)) end do end subroutine _array_output_z!(c, o, m, n) character*a, intent(out), dimension(m) :: c integer n integer*1, dimension(m, n), intent(in) :: o !f2py character(f2py_len=n) :: c !f2py integer, depend(o), intent(hide) :: m = len(o) !f2py integer, depend(o), intent(hide) :: n = shape(o, 1) do i=1,m c(i) = transfer(o(i, :), c(i)) end do end subroutine _2d_array_input_zH(c, o, m1, m2, n) integer m1, m2, i, j, n character*a, intent(in), dimension(m1, m2) :: c !f2py integer, depend(c), intent(hide) :: m1 = len(c) !f2py integer, depend(c), intent(hide) :: m2 = shape(c, 1) !f2py integer, depend(c), intent(hide) :: n = f2py_itemsize(c) integer*1, dimension(m1, m2, n), intent(out) :: o do i=1,m1 do j=1,m2 o(i, j, :) = transfer(c(i, j), o(i, j, :)) end do end do end subroutine z lengthc ddij||}t|j|jdz|z}dddd|}t ||t j ttt|d y) Nrrraabcabcdeabcdeabcder u1dtype) getgetattrmodulefprefixrnparraylistmapordselfrfsuffixfrs e/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/numpy/f2py/tests/test_character.py test_inputzTestCharacterString.test_inputOsk&/%%ff5 DKK !9G!C DE; 7 ?1Q4$s3{*;4!HINc |}t|j|jdz|z}ddd|}t|t j t tt|d|jy)Nrrr)r r rr) rr r!rr"r#r$r%r&encoder's r+ test_outputzTestCharacterString.test_outputXsb DKK !:W!D EE "6 *1RXXd3sA;&7tDE88: 'r-c,|}t|j|jdz|z}tjdddd|dddd|gd }tj|Dcgc] }t |c}d }t |||ycc}w) Nrrrrr AABCABCDEABCDEABCDESrrrr r!r"r#r$r)r(rr)r*rsexpecteds r+test_array_inputz$TestCharacterString.test_array_inputbs DKK!?'!I J HHCe[A&Ie[A&I" $88a0T!W0=1Q4*1#Bc,|}t|j|jdz|z}tjdddd|dddd|gd }tj|Dcgc] }t |c}d }t |||ycc}w) Nrrrrr r3r4r5r6rrr7)r(rr)r*r9r8rs r+test_array_outputz%TestCharacterString.test_array_outputns DKK0@!@7!J K88UK 8 @UK 8 @ BILN HHx0!d1g0 =1Q4*1r;c ~|}t|j|jdz|z}tjdddd|dddd|gd d d d|d d dd|ggd}tj|Dcgc]}|Dcgc] }t |c}c}}dd }t |||ycc}wcc}}w)Nrrrrr r3r4r5r*fghfghijfghijfghijFFGHFGHIJFGHIJFGHIJr6rrrorderr7)r(rr)r*rrowitemr9s r+test_2d_array_inputz'TestCharacterString.test_2d_array_inputzs DKK0B!BW!L M HHSukB6J ukB6JL ukB6J ukB6JLM   88QGcS9Td4j9G"&c31Q4*:Gs6 B9 ?B4B9 4B9 )__name__ __module__ __qualname__suffixr! length_listcoderr)rclengthtextwrapdedentjoinpytestmark parametrizer,r1r:r=rHr-r+rr slF%G$K D; 5/%%ff5 7! 7! %7! 97! #7! $+97! -7! I7! 7!  y7! !(7! )0y7! 17! 97! %7! &-I7! .7! I7! 7! " y#7! "!)#7! "*1 #7! "2#7! &9'7! &*'7! &+2'7! &3'7! *I+7! *+7! 8 y97! 8!.97! 8/6Y97! 8797! <9=7! <+=7! <,3)=7! <4=7! >I?7! > ?7! P yQ7! P!/Q7! P07iQ7! P8Q7! T9U7! T-U7! T.5IU7! T6U7! XIY7! X Y7! l ym7! l!1m7! l29 m7! l: m7! 7 7  ; z [[X{3J4J [[X{3B'78'9' [[X{3 +4 + [[X{3 +4 + [[X{3 +4 +r-rcleZdZdZdZej djgdededededed ed ed ed ed edededededededededededededededZe jjdddgd Z d!Z e jjdgd"d#Zd$Ze jjdgd"d%Zd&Zd'Zd(Ze jjdddgd)Zd*Ze jjdddgd+Ze jjdddgd,Zd-Ze jj3d.d/Zd0Zy1)2 TestCharacterr test_characterr subroutine z_input(c, o) character, intent(in) :: c integer*1 o !f2py intent(out) o o = transfer(c, o) end subroutine z_input subroutine z_output(c, o) character :: c integer*1, intent(in) :: o !f2py intent(out) c c = transfer(o, c) end subroutine z_output subroutine z_input_output(c, o) character, intent(in) :: c character o !f2py intent(out) o o = c end subroutine z!_input_output subroutine z_inout(c, n) character :: c, n !f2py intent(in) n !f2py intent(inout) c c = n end subroutine z_inout function z_return(o) result (c) character :: c character, intent(in) :: o c = transfer(o, c) end function z_return subroutine z_array_input(c, o) character, intent(in) :: c(3) integer*1 o(3) !f2py intent(out) o integer i do i=1,3 o(i) = transfer(c(i), o(i)) end do end subroutine z _array_input subroutine a'_2d_array_input(c, o) character, intent(in) :: c(2, 3) integer*1 o(2, 3) !f2py intent(out) o integer i, j do i=1,2 do j=1,3 o(i, j) = transfer(c(i, j), o(i, j)) end do end do end subroutine z#_2d_array_input subroutine z_array_output(c, o) character :: c(3) integer*1, intent(in) :: o(3) !f2py intent(out) c do i=1,3 c(i) = transfer(o(i), c(i)) end do end subroutine z!_array_output subroutine z_array_inout(c, n) character :: c(3), n(3) !f2py intent(in) n(3) !f2py intent(inout) c(3) do i=1,3 c(i) = n(i) end do end subroutine z _array_inout subroutine a _2d_array_inout(c, n) character :: c(2, 3), n(2, 3) !f2py intent(in) n(2, 3) !f2py intent(inout) c(2. 3) integer i, j do i=1,2 do j=1,3 c(i, j) = n(i, j) end do end do end subroutine z!_2d_array_inout function z_array_return(o) result (c) character, dimension(3) :: c character, intent(in) :: o(3) do i=1,3 c(i) = o(i) end do end function z_array_return function z_optional(o) result (c) character, intent(in) :: o !f2py character o = "a" character :: c c = o end function z_optional rcS1c0t|j|jdz}t|t j d|t dt|t j d|t dt|t j dg|t dt|t j d|t dt|t j dgg|t dy)N_inputrrar)rr r!rr"r#r&r(rr*s r+r,zTestCharacter.test_inputs DKK!8 9Qrxx512CH=QrxxE23SX>QrxxU34c#h?QrxxU34c#h?Qrxx#u56CAr-ct|j|jdz}t|dt dt|dt dt|ddt|ddt|ddt|dt dt|d t dt|dgt dt|t j dt dt|t j dgt dt j d}t||t dt j dg}t||t d |gt|jd #t$r%}t|jd sYd}~nd}~wwxYw |d t|jd #t$r%}t|jdsYd}~yd}~wwxYw)Nr^rr_rrr-absabz! should have failed on empty listz got 0-listaz should have failed on int valuez got int instance) rr r!rr&r"r# SystemErrorrI IndexErrorstrendswith TypeErrorr(r*rmsgs r+test_input_variazTestCharacter.test_input_varias DKK!8 9QsVSX&QtWc$i(QrUAQsVQQuXq!QtWc#h'QuXs3x(QuXs3x(Qrxx~&C1Qrxx'(#c(3 HHSMQqT3s8$ HHcUOQqT3s8$ P bE  ,MNO O  s8$$]34   O bE  ,LMN N  s8$$%89: s0!G G/ G**G/3H IH<<I)r[r\U1c t|j|jdz}t|t j gd|t j t ttddt|t j gd|t j t ttddy)N _array_inputrbr[rri1r_bc) rr r!rr"r#r$r%r&r`s r+r:zTestCharacter.test_array_input"s DKK!> ?1RXXoUCD88DS%$9F H1RXX&8FG88DS%$9F Hr-c t|j|jdz}t|gdt j t ttddt|gdt j t ttdd |gdt|jd#t$r%}t|jd sYd}~yd}~wwxYw) Nrorprrrrrsrrqr[d" should have failed on wrong input)th dimension must be fixed to 3 but got 4)rr r!rr"r#r$r%r&rerI ValueErrorrgrh)r(r*rks r+test_array_input_variaz$TestCharacter.test_array_input_varia+s DKK!> ?1_-88DS%$9F H1/088DS%$9F H C " # ::,@AC C  s8$$?AA s% C C5C00C5ct|j|jdz}tjgdgdg|d}|j |dk(rtj ntj}t|||y)N_2d_array_inputrprxer*rArDrm) rr r!r"r#viewuint32uint8r)r(rr*rr9s r+rHz!TestCharacter.test_2d_array_input<sf DKK0A!A B HHo%'.33 @66u}"))"((C1Q4*r-ct|j|jdz}t|t ddt|ddy)N_outputr_rrb)rr r!rr&r(r*s r+r1zTestCharacter.test_outputEs; DKK !9 :Qs4y\4(QqT5!r-c t|j|jdz}t|t t t dtjt ddy)N _array_outputrr\r) rr r!rr$r%r&r"r#rs r+r=zTestCharacter.test_array_outputKsG DKK!? @1T#c5/2388DKt< >r-ct|j|jdz}t|ddt|ddt|ddy)N _input_outputr_rrrbrr r!rrs r+test_input_outputzTestCharacter.test_input_outputQsE DKK!? @QtWd#QsVT"QrUE"r-ct|j|jdz}tjt d|}||dt |tjt d|j||dddt |tjt d|jtjdg|}||dt |tjdg|jy) N_inoutrrr3AbcBABc)rr r!r"r#r$rr)r(rr*rs r+ test_inoutzTestCharacter.test_inoutXs DKK!8 9 HHT%[ . !S 1bhhtE{!''BC !AB% 1bhhtE{!''BC HHeWE * !S 1bhhwagg>?r-ct|j|jdz}tjdd}||dt |tjd|j tjdgd}||dt |tjdg|j  |ddt|jd#t$r%}t|jdsYd}~yd}~wwxYw) NrrS3rr3rz should have failed on str valuez got 3-str) rr r!r"r#rrrerIr{rgrhrjs r+test_inout_variazTestCharacter.test_inout_variafs DKK!8 9 HHU$ ' !S 1bhhuAGG<= HHeWD ) !S 1bhhwagg>? O eSM  ,LMN N  s8$$\23 s= C D 'DD ct|j|jdz}tjgd|d}tjgd|d}|||t ||tjgd|}||dd|t |tjgd |tjgdg|d}|||t |tjgdg|tjgd|d} |||t |jd #t$r%}t|jd sYd}~yd}~wwxYw) N _array_inoutr3rCrArDrprwrr)rr3rrryrz) rr r!r"r#rrerIr{rgrh)r(rr*nrrks r+test_array_inoutzTestCharacter.test_array_inoutxs1 DKK!> ? HH_E = HH_E = !Q1a HH) 7 !AB% 1bhh';5IJ HHo&e3 ? !Q1bhh'8FG HH)c B C aG ::,@AC C  s8$$?AA s D99 E'E""E'ct|j|jdz}tjgdgdg|d}tjgdgdg|d}|||t ||y)N_2d_array_inoutr)DErArArDrprrr r!r"r#r)r(rr*rrs r+test_2d_array_inoutz!TestCharacter.test_2d_array_inoutsm DKK0A!A B HHo%'  - HHo%'  - !Q1a r-cnt|j|jdz}t|ddy)N_returnrr_rrs r+ test_returnzTestCharacter.test_returns) DKK !9 :QsVT"r-z*fortran function returning array segfaultsct|j|jdz}tjt dd}t |||y)N _array_returnrr\rr7)r(r*rs r+test_array_returnzTestCharacter.test_array_returns= DKK!? @ HHT%[ -1Q4#r-ct|j|jdz}t|dt|ddy)N _optionalr_Brrs r+ test_optionalzTestCharacter.test_optionals5 DKK !; <QS$QtWd#r-N)rIrJrKrLr!rPrQrRrNrSrTrUr,rlr:r|rHr1r=rrrrrrskiprrrVr-r+rXrXs FG 8??ee e)ee i e   e)eeie e)ee(i)e( )e,)-e,-e6i7e6 7e: ;e:;eBICeBCeF)GeFGeViWeV WeZ)[eZ [enioen oer)serse@iAe@ AeD)EeDEeRiSeR SeV)WeV Wejikej ken oenoezI{ez{e~ e~eHIIeHIee DN [[WsDk2B3B!OF [[W&78H9HC" [[W&78+9+" > # [[WsDk2 @3 @O$ [[WsDk2C3C6 [[WsDk2 !3 !#  [[BC$D$ $r-rXceZdZdZdZej dedededededed ed ed ed ed ededZejjdZ dZ dZ dZejjdddgdZy)TestMiscCharacterr test_misc_characterrZa(_gh18684(x, y, m) character(len=5), dimension(m), intent(in) :: x character*5, dimension(m), intent(out) :: y integer i, m !f2py integer, intent(hide), depend(x) :: m = f2py_len(x) do i=1,m y(i) = x(i) end do end subroutine z_gh18684 subroutine z_gh6308(x, i) integer i !f2py check(i>=0 && i<12) i character*5 name, x common name(12) name(i + 1) = x end subroutine z_gh6308 subroutine z_gh4519(x) character(len=*), intent(in) :: x(:) !f2py intent(out) x integer :: i ! Uncomment for debug printing: !do i=1, size(x) ! print*, "x(",i,")=", x(i) !end do end subroutine z_gh4519 pure function aq_gh3425(x) result (y) character(len=*), intent(in) :: x character(len=len(x)) :: y integer :: i do i = 1, len(x) j = iachar(x(i:i)) if (j>=iachar("a") .and. j<=iachar("z") ) then y(i:i) = achar(j-32) else y(i:i) = x(i:i) endif end do end function z_gh3425 subroutine aO_character_bc_new(x, y, z) character, intent(in) :: x character, intent(out) :: y !f2py character, depend(x) :: y = x !f2py character, dimension((x=='a'?1:2)), depend(x), intent(out) :: z character, dimension(*) :: z !f2py character, optional, check(x == 'a' || x == 'b') :: x = 'a' !f2py callstatement (*f2py_func)(&x, &y, z) !f2py callprotoargument character*, character*, character* if (y.eq.x) then y = x else y = 'e' endif z(1) = 'c' end subroutine z%_character_bc_new subroutine aG_character_bc_old(x, y, z) character, intent(in) :: x character, intent(out) :: y !f2py character, depend(x) :: y = x[0] !f2py character, dimension((*x=='a'?1:2)), depend(x), intent(out) :: z character, dimension(*) :: z !f2py character, optional, check(*x == 'a' || x[0] == 'b') :: x = 'a' !f2py callstatement (*f2py_func)(x, y, z) !f2py callprotoargument char*, char*, char* if (y.eq.x) then y = x else y = 'e' endif z(1) = 'c' end subroutine z_character_bc_old ct|j|jdz}tjddgd}||}t ||y)N_gh18684abcdefghijS5rr)r(r*xys r+ test_gh18684zTestMiscCharacter.test_gh18684sE DKK !: ; HHgw't 4 aD1a r-ct|j|jdz}t|jjj j tj dtt|jjj d|ddt|jjj dd|ddt|jjj dd y) N_gh6308r rrsabcde12345s12345) rr r!r_BLNK_namerr"lenrs r+ test_gh6308zTestMiscCharacter.test_gh6308s DKK !9 :T[['',,22BHHTNCS++00126 '1 T[['',,Q/: '1 T[['',,Q/:r-c t|j|jdz}ddtjddfddtjddftj gdd d tjddfgd d tjd dfd d gdtjddffD];\}}||}|j D]\}}tt|||=y)N_gh4519rrVr\)shapertextS4)r 2r r))r r34S2r))rr r!r"rr#itemsr)r(r*rr9rkvs r+ test_gh4519zTestMiscCharacter.test_gh4519s DKK !9 :RXXd^<=2?@/6"((4.9;!"((4.9;bTBHHTNCDF /KAx!A ( /1WQ]A. / /r-ct|j|jdz}t|ddt|ddt|ddy)N_gh3425abCsABCrr-abC12dsABC12Drrs r+ test_gh3425zTestMiscCharacter.test_gh3425*sG DKK !9 : QuXv&QrUC Qx[),r-statenewoldc&t|j|jdz|z\}}t|dtt |dd\}}t|dtt |dt t fdy)N_character_bc_r_rrtrcdS)NrurV)r*sr+z5TestMiscCharacter.test_character_bc..?s 4r-)rr r!rrr Exception)r(rr[rr*s @r+test_character_bcz#TestMiscCharacter.test_character_bc3st DKK0@!@5!H Is1QSVQw1QSVQi1r-N)rIrJrKrLr!rPrQrNrSrTslowrrrrrUrrVr-r+rrs F#G 8?? )i ) i )i Y I)i )i WLL D\ [[!! ;/ - [[Wuen5 26 2r-rcDeZdZejddddgZdZdZy)TestStringScalarArrtestssrcstringzscalar_string.f90c|jjj|jjjfD](}d}|j|k(sJd}|j |k(r(Jy)NrVz|S8)r string_testrstring77rrr(outr9s r+ test_charzTestStringScalarArr.test_charEsgKK++22KK++446 )CH99( ((H99( ((  )r-c|jjj|jjjfD](}d}|j|k(sJd}|j |k(r(Jy)N)rz|S12)r rstrarrstrarr77rrrs r+ test_char_arrz!TestStringScalarArr.test_char_arrMsgKK++22KK++446 )CH99( ((H99( ((  )r-N)rIrJrKrgetpathsourcesrrrVr-r+rrBs&t||GUH6IJKG))r-rc>eZdZejddddgZdZy)TestStringAssumedLengthrrrz gh24008.fc<|jjddy)Njoebob)r greet)r(s r+ test_gh24008z$TestStringAssumedLength.test_gh24008Xs %'r-N)rIrJrKrrrrrVr-r+rrUs t||GUHkBCG(r-rc>eZdZejddddgZdZy)TestStringOptionalInOutrrrz gh24662.f90cv|jjtjdd}|jj|d|j j vsJt jt5d}|jj|dddy#1swYyxYw)NhiS32rz output stringHi) r string_inout_optionalr"r#tobytesdecoderSraisesr)r(raas r+ test_gh24662z$TestStringOptionalInOut.test_gh24662_s ))+ HHT ' ))!,!))+"4"4"6666 ]]9 % 2B KK - -b 1 2 2 2s B//B8N)rIrJrKrrrrrVr-r+rr[s t||GUHmDEG2r-rcjeZdZejddddejddddgZdZdZy) TestNewCharHandlingrrrz gh25286.pyf gh25286.f90_char_handling_testcH|jjd}|dk(sJyNTrr charintr(infos r+ test_gh25286z TestNewCharHandling.test_gh25286r"{{""3'qyyr-NrIrJrKrrr module_namerrVr-r+rris?  WeX}= WeX}=G(Kr-rcjeZdZejddddejddddgZdZdZy) TestBCCharHandlingrrrzgh25286_bc.pyfrrcH|jjd}|dk(sJyr r rs r+rzTestBCCharHandling.test_gh25286rr-NrrVr-r+rrvs@  WeX/?@ WeX}=G(Kr-r)rPrSnumpyr"numpy.f2py.testsr numpy.testingrrrrTrF2PyTestrrXrrrrrrrVr-r+rs !II{+$--{+{+|g$DMMg$T L2 L2^)$--)&(dmm(  2dmm 2 2 $--     r-