id!PddlZddlZddlmZmZmZddlZddlm Z Gdde j Z Gdde j Z Gdd e j Z Gd d e j ZdS) N)assert_array_equal assert_equal assert_raises)utilc2eZdZdZdZgdZdZeD]ZeZe d eeZ ee j dgdeded e d ededed ed e d ed eded ede ded ededede dedededede dededz ZejdedZejdedddZejdedZejdedZejdedZdS)TestCharacterString.f90test_character_string13star(*))rz 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 (ddi||}t|j|jdz|z}dddd|}t ||t jttt|d dS) Nrrraabcabcdeabcdeabcder u1dtype) getgetattrmodulefprefixrnparraylistmapordselfrfsuffixfrs T/opt/cloudlinux/venv/lib/python3.11/site-packages/numpy/f2py/tests/test_character.py test_inputzTestCharacterString.test_inputLs&/%%ff55 DK !9G!C D DE; 7 7 ?11Q44$s3{{*;*;4!H!H!HIIIIINc |}t|j|jdz|z}ddd|}t|t jt tt|d| dS)Nrrr)r r rr) rr r!rr"r#r$r%r&encoder's r+ test_outputzTestCharacterString.test_outputUs DK !:W!D E EE " "6 *11RXd3sA;;&7&7tDDDEE88:: ' ' ' ' 'r-c|}t|j|jdz|z}tjdddd|dddd|gd }tjd |Dd }t |||dS) Nrrrrr AABCABCDEABCDEABCDESrc&g|]}d|DS)cg|]}|Sr9.0cs r+ zCTestCharacterString.test_array_input...hs^^^Aa^^^r-r9r;ss r+r=z8TestCharacterString.test_array_input..hs"777^^^^^777r-rrr r!r"r#rr(rr)r*rexpecteds r+test_array_inputz$TestCharacterString.test_array_input_s DK!?'!I J J HCe[AA&Ie[AA&I" $ $ $877Q777tDDD11Q44*****r-c|}t|j|jdz|z}tjdddd|dddd|gd }tjd |Dd }t |||dS) Nrrrrr r3r4r5r6rc&g|]}d|DS)cg|]}|Sr9r9r:s r+r=zDTestCharacterString.test_array_output...tsnnnQqnnnr-r9r>s r+r=z9TestCharacterString.test_array_output..ts"777nn!nnn777r-rr@)r(rr)r*rBrs r+test_array_outputz%TestCharacterString.test_array_outputks DK0@!@7!J K K8UK 8 8 @UK 8 8 @ BILNNN H77h777t D D D11Q44*****r-cF|}t|j|jdz|z}tjdddd|dddd|gd d d d|d d dd|ggd}tjd|Ddd }t |||dS)Nrrrrr r3r4r5r*fghfghijfghijfghijFFGHFGHIJFGHIJFGHIJr6rc&g|]}d|DS)c&g|]}d|DS)cg|]}|Sr9r9r:s r+r=zQTestCharacterString.test_2d_array_input....s///Qq///r-r9)r;items r+r=zFTestCharacterString.test_2d_array_input...s'@@@D//$///@@@r-r9)r;rows r+r=z;TestCharacterString.test_2d_array_input..s'NNNS@@C@@@NNNr-rrorderr@rAs r+test_2d_array_inputz'TestCharacterString.test_2d_array_inputws DK0B!BW!L M M HSukBB6J ukBB6JL ukBB6J ukBB6JLM     8NNANNN"&c33311Q44*****r-)__name__ __module__ __qualname__suffixr! length_listcoderr)dictrclengthtextwrapdedentjoinpytestmark parametrizer,r1rCrGrUr9r-r+rrs F%G$$$K D; ; $E"""&&vv66 7! 7! 7! 7! 7! 7! 7! 7! 7! 7! $+7! 7! 7! 7! 7! 7! 7! 7!  7! 7! 7! 7! )07! 7! 7! 7! 7! 7! 7! 7! &-7! 7! 7! 7! 7! 7! 7! 7! " #7! 7! 7! 7! "*1#7! 7! 7! 7! &'7! 7! 7! 7! &+2'7! 7! 7! 7! *+7! 7! 7! 7! 8 97! 7! 7! 7! 8/697! 7! 7! 7! <=7! 7! 7! 7! <,3=7! 7! 7! 7! >?7! 7! 7! 7! P Q7! 7! 7! 7! P07Q7! 7! 7! 7! TU7! 7! 7! 7! T.5U7! 7! 7! 7! XY7! 7! 7! 7! l m7! 7! 7! 7! l29m7! 7! 7! 7! 7! 7! 7 7 7 r [X{33JJ43J [X{3B3'788''98' [X{33 + +43 + [X{33 + +43 + [X{33 + +43 + + +r-rceZdZdZdZejdgdededededed ed ed ed ed edededededededededededededededZe j dddgd Z d!Z e j dgd"d#Zd$Ze j dgd"d%Zd&Zd'Zd(Ze j dddgd)Zd*Ze j dddgd+Ze j dddgd,Zd-Ze j d.d/Zd0Zd1S)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 rr<S1ct|j|jdz}t|t jd|t dt|t jd|t dt|t jdg|t dt|t jd|t dt|t jdgg|t ddS)N_inputrrar)rr r!rr"r#r&r(rr*s r+r,zTestCharacter.test_inputs DK!8 9 9QQrx511122CHH===QQrxE22233SXX>>>QQrxU33344c#hh???QQrxU33344c#hh???QQrx#u55566CAAAAAr-ct|j|jdz}t|dt dt|dt dt|ddt|ddt|ddt|dt dt|d t dt|dgt dt|t jdt dt|t jdgt dt jd}t||t dt jdg}t||t d |gt|jd #t$r-}t| d sYd}~nd}~wwxYw |d t|jd #t$r.}t| dsYd}~dSd}~wwxYw)Nrjrrkrrr-absabz! should have failed on empty listz got 0-listaz should have failed on int valuez got int instance) rr r!rr&r"r# SystemErrorrV IndexErrorstrendswith TypeErrorr(r*rmsgs r+test_input_variazTestCharacter.test_input_varias DK!8 9 9QQsVVSXX&&&QQtWWc$ii(((QQrUUAQQsVVQQQuXXq!!!QQtWWc#hh'''QQuXXs3xx(((QQuXXs3xx(((QQrx~~&&C111QQrx''((#c((333 HSMMQQqTT3s88$$$ HcUOOQQqTT3s88$$$ P AbEEE NNNOO O    s88$$]33         O AbEEE MMMNN N    s88$$%899        s0 H11 I(;#I##I(, J K#KK)r<rhU1c t|j|jdz}t|t jgd|t jt ttddt|t jgd|t jt ttdddS)N _array_inputrbr<rri1rkbc) rr r!rr"r#r$r%r&rls r+rCzTestCharacter.test_array_inputs DK!> ? ?11RXoooUCCCDD8DS%$9$9FFF H H H11RX&8&8&8FFFGG8DS%$9$9FFF H H H H Hr-c 8t|j|jdz}t|gdt jt ttddt|gdt jt ttdd |gdt|j d#t$r.}t| d sYd}~dSd}~wwxYw) Nr{r|rr~rrrr}r<d" should have failed on wrong input)th dimension must be fixed to 3 but got 4)rr r!rr"r#r$r%r&rqrV ValueErrorrsrt)r(r*rws r+test_array_input_variaz$TestCharacter.test_array_input_varia(sR DK!> ? ?11___--8DS%$9$9FFF H H H11///008DS%$9$9FFF H H H C A""" # # # :AAACC C    s88$$?AA        s= C!! D+#DDct|j|jdz}tjgdgdg|d}||dkr tjn tj}t|||dS)N_2d_array_inputr|rer*rKrSry) rr r!r"r#viewuint32uint8r)r(rr*rrBs r+rUz!TestCharacter.test_2d_array_input9s DK0A!A B B Hooo%oo'.33 @ @ @66u}}"))"(CC11Q44*****r-ct|j|jdz}t|t ddt|dddS)N_outputrkrrn)rr r!rr&r(r*s r+r1zTestCharacter.test_outputBsV DK !9 : :QQs4yy\\4(((QQqTT5!!!!!r-c t|j|jdz}t|t t t dtjt dddS)N _array_outputrrhr) rr r!rr$r%r&r"r#rs r+rGzTestCharacter.test_array_outputHsj DK!? @ @11T#c5//22338DKKt<<< > > > > >r-ct|j|jdz}t|ddt|ddt|dddS)N _input_outputrkrrrnrr r!rrs r+test_input_outputzTestCharacter.test_input_outputNsh DK!? @ @QQtWWd###QQsVVT"""QQrUUE"""""r-c8t|j|jdz}tjt d|}||dt |tjt d|j||dddt |tjt d|jtjdg|}||dt |tjdg|jdS) N_inoutrrr3AbcBABc)rr r!r"r#r$rr)r(rr*rs r+ test_inoutzTestCharacter.test_inoutUs DK!8 9 9 HT%[[ . . . !S 1bhtE{{!'BBBCCC !ABB% 1bhtE{{!'BBBCCC HeWE * * * !S 1bhwag>>>?????r-c*t|j|jdz}tjdd}||dt |tjd|jtjdgd}||dt |tjdg|j |ddt|jd#t$r.}t| dsYd}~dSd}~wwxYw) NrrS3rr3rz should have failed on str valuez got 3-str) rr r!r"r#rrrqrVrrsrtrvs r+test_inout_variazTestCharacter.test_inout_variacs4 DK!8 9 9 HU$ ' ' ' !S 1bhuAG<<<=== HeWD ) ) ) !S 1bhwag>>>??? O AeSMMM MMMNN N    s88$$\22        s7 C D$#D  Dct|j|jdz}tjgd|d}tjgd|d}|||t ||tjgd|}||dd|t |tjgd |tjgdg|d}|||t |tjgdg|tjgd|d} |||t |jd #t$r.}t| d sYd}~dSd}~wwxYw) N _array_inoutr3rCrKrSr|rrr)rr3rrrr) rr r!r"r#rrqrVrrsrt)r(rr*nrrws r+test_array_inoutzTestCharacter.test_array_inoutus DK!> ? ? H___E = = = H___E = = = !Q1a   H))) 7 7 7 !ABB% 1bh';';';5IIIJJJ Hooo&e3 ? ? ? !Q1bh'8FFFGGG H)))c B B B C AaGGG :AAACC C    s88$$?AA        s% E F#E;;Fct|j|jdz}tjgdgdg|d}tjgdgdg|d}|||t ||dS)N_2d_array_inoutr)DErKrKrSr|rr@)r(rr*rrs r+test_2d_array_inoutz!TestCharacter.test_2d_array_inouts DK0A!A B B Hooo%oo'  - - - Hooo%oo'  - - - !Q1a     r-crt|j|jdz}t|dddS)N_returnrrkrrs r+ test_returnzTestCharacter.test_returns8 DK !9 : :QQsVVT"""""r-z*fortran function returning array segfaultsct|j|jdz}tjt dd}t |||dS)N _array_returnrrhr)rr r!r"r#r$r)r(r*rs r+test_array_returnzTestCharacter.test_array_returnsR DK!? @ @ HT%[[ - - -11Q44#####r-ct|j|jdz}t|dt|dddS)N _optionalrkBrrs r+ test_optionalzTestCharacter.test_optionalsN DK !; < <QQSS$QQtWWd#####r-N)rVrWrXrYr!r^r_r`r[rarbrcr,rxrCrrUr1rGrrrrrrskiprrr9r-r+reres& FG 8?eeeeeeeeee  eeeeeeeeeeeeeeee()eeee,-eeee67eeee:;eeeeBCeeeeFGeeeeVWeeeeZ[eeeenoeeeerseeee@AeeeeDEeeeeRSeeeeVWeeeejkeeeenoeeeez{eeee~eeeeHIeeeeeee e DN [WsDk22BB32B!O!O!OF [W&7&7&788HH98HCCC" [W&7&7&788++98+""" >>> ### [WsDk22 @ @32 @OOO$ [WsDk22CC32C6 [WsDk22 ! !32 !###  [BCC$$DC$ $$$$$r-receZdZdZdZejdedededededed ed ed ed ed ededZdZdZ dZ dZ e j dddgdZdS)TestMiscCharacterr test_misc_characterrga(_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 ||dS)N_gh18684abcdefghijS5rr@)r(r*xys r+ test_gh18684zTestMiscCharacter.test_gh18684sV DK !: ; ; Hgw't 4 4 4 AaDD1a     r-ct|j|jdz}t|jjjjtjdtt|jjjd|ddt|jjjdd|ddt|jjjdd dS) N_gh6308r rrsabcde12345s12345) rr r!r_BLNK_namerr"lenrs r+ test_gh6308zTestMiscCharacter.test_gh6308 s DK !9 : :T[',2BHTNNCCCS+0112666 '1 T[',Q/::: '1 T[',Q/:::::r-c rt|j|jdz}dtdt jdfdtdt jdft jgdd td t jdfgd td t jd fd d gtdt jdffD]H\}}||}|D]#\}}tt|||$IdS)N_gh4519rr9rh)shapertextS4)r 2r r))r r34S2r)) rr r!r\r"rr#itemsr)r(r*rrBrkvs r+ test_gh4519zTestMiscCharacter.test_gh4519s< DK !9 : :d28D>>:::;Bbhtnn===>///666D7779!!!D7779b4d"(4..AAABD / /KAx!A (( / /1WQ]]A.... / / /r-ct|j|jdz}t|ddt|ddt|dddS)N_gh3425abCsABCrr-abC12dsABC12Drrs r+ test_gh3425zTestMiscCharacter.test_gh3425&sj DK !9 : : QQuXXv&&&QQrUUC   QQx[[),,,,,r-statenewoldcbt|j|jdz|z\}}t|dtt |dd\}}t|dtt |dt t fddS)N_character_bc_rkrrrcdS)Nrr9)r*sr+z5TestMiscCharacter.test_character_bc..;s4r-)rr r!rrr Exception)r(rr<rr*s @r+test_character_bcz#TestMiscCharacter.test_character_bc/s DK0@!@5!H I Iqss1QSVVQqww1QSVVQi11111r-N)rVrWrXrYr!r^r_r[rrrrrarbrcrr9r-r+rrs F#G 8?LLLLLLL"#LL&'LL67LL:;LLRSLLVWLLtuLLxyLLVWLLLL L D\!!! ; ; ;/// --- [Wuen55 2 265 2 2 2r-rceZdZejddddgZejjdZ ejjdZ dS)TestStringScalarArrtestssrcstringzscalar_string.f90c|jjj|jjjfD] }d}|j|ksJd}|j|ksJ!dS)Nr9z|S8)r string_testrstring77rrr(outrBs r+ test_charzTestStringScalarArr.test_charAsfK+2K+46 ) )CH9((((H9(((((  ) )r-c|jjj|jjjfD] }d}|j|ksJd}|j|ksJ!dS)N)rz|S12)r rstrarrstrarr77rrrs r+ test_char_arrz!TestStringScalarArr.test_char_arrJsfK+2K+46 ) )CH9((((H9(((((  ) )r-N) rVrWrXrgetpathsourcesrarbslowrrr9r-r+rr>sot|GUH6IJJKG [))) [)))))r-r)rar^ numpy.testingrrrnumpyr"numpy.f2py.testsrF2PyTestrrerrr9r-r+rs( IIIIIIIIII!!!!!!{+{+{+{+{+$-{+{+{+|g$g$g$g$g$DMg$g$g$T K2K2K2K2K2 K2K2K2\)))))$-)))))r-