1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
U
P±dDRã@s„ddlZddlZddlmZmZmZddlZddlm    Z    Gdd„de    j
ƒZ Gdd„de    j
ƒZ Gdd    „d    e    j
ƒZ Gd
d „d e    j
ƒZdS) éN)Úassert_array_equalÚ assert_equalÚ assert_raises)Úutilc7@s^eZdZdZdZdddgZdZeD]ÀZeZe    dd 
ee¡Z ee   d    e›d
e›d e ›d e›d
e›d    e›d e›d e ›de›d e›d    e›de›de ›de›de›d    e›de›de ›de›de›d    e›de›de ›de›de›d3¡7Zq"ej de¡dd„ƒZej dedd…¡dd„ƒZej de¡d d!„ƒZej de¡d"d#„ƒZej de¡d$d%„ƒZdS)&ÚTestCharacterStringú.f90Ztest_character_stringÚ1Ú3ÚstarÚú(*))r
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    
        ÚlengthcCs\ddi ||¡}t|j|jd|ƒ}ddddœ|}t||ƒtjttt    |ƒƒdd    ƒdS)
Nr r
r ÚaÚabcÚabcdeabcdeabcde©rr    r
Úu1©Údtype)
ÚgetÚgetattrÚmoduleÚfprefixrÚnpÚarrayÚlistÚmapÚord©ÚselfrÚfsuffixÚfr©r'úVd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\numpy/f2py/tests/test_character.pyÚ
test_inputLszTestCharacterString.test_inputNéÿÿÿÿcCsR|}t|j|jd|ƒ}dddœ|}t|tjttt|ƒƒddƒ|     ¡ƒdS)Nrrr)rr    rr)
rrrrrrr r!r"Úencoder#r'r'r(Ú test_outputUs ÿzTestCharacterString.test_outputcCsn|}t|j|jd|ƒ}tjddddœ|ddddœ|gd    d
}tjd d „|Dƒd d
}t||ƒ|ƒdS)NrrrrrÚAÚABCÚABCDEABCDEABCDEÚSrcSsg|]}dd„|Dƒ‘qS)cSsg|]}|‘qSr'r'©Ú.0Úcr'r'r(Ú
<listcomp>hszCTestCharacterString.test_array_input.<locals>.<listcomp>.<listcomp>r'©r2Úsr'r'r(r4hsz8TestCharacterString.test_array_input.<locals>.<listcomp>r©rrrrrr©r$rr%r&rÚexpectedr'r'r(Útest_array_input_sÿþz$TestCharacterString.test_array_inputcCsn|}t|j|jd|ƒ}tjddddœ|ddddœ|gd    d
}tjd d „|Dƒd d
}t||ƒ|ƒdS)Nrrrrrr-r.r/r0rcSsg|]}dd„|Dƒ‘qS)cSsg|]}|‘qSr'r'r1r'r'r(r4tszDTestCharacterString.test_array_output.<locals>.<listcomp>.<listcomp>r'r5r'r'r(r4tsz9TestCharacterString.test_array_output.<locals>.<listcomp>rr7)r$rr%r&r9rr'r'r(Útest_array_outputksÿþz%TestCharacterString.test_array_outputcCs|}t|j|jd|ƒ}tjddddœ|ddddœ|gd    d
d dœ|d d ddœ|ggdd}tjdd„|Dƒdd d}t||ƒ|ƒdS)Nrrrrrr-r.r/r&ZfghZfghijfghijfghijÚFZFGHZFGHIJFGHIJFGHIJr0rcSsg|]}dd„|Dƒ‘qS)cSsg|]}dd„|Dƒ‘qS)cSsg|]}|‘qSr'r'r1r'r'r(r4szQTestCharacterString.test_2d_array_input.<locals>.<listcomp>.<listcomp>.<listcomp>r')r2Úitemr'r'r(r4szFTestCharacterString.test_2d_array_input.<locals>.<listcomp>.<listcomp>r')r2Úrowr'r'r(r4sz;TestCharacterString.test_2d_array_input.<locals>.<listcomp>r©rÚorderr7r8r'r'r(Útest_2d_array_inputws ÿÿþüÿz'TestCharacterString.test_2d_array_input)Ú__name__Ú
__module__Ú __qualname__ÚsuffixrZ length_listÚcoderr%ÚdictrÚclengthÚtextwrapÚdedentÚpytestÚmarkÚ parametrizer)r,r:r;rAr'r'r'r(rsˆ
þþýþþþþýþþþþýþþþþýþþþþýþþ9 
 
     
 
rc3@s¤eZdZdZdZe de›de›de›de›de›de›d    e›d
e›d e›d e›d e›de›de›de›de›de›de›de›de›de›de›de›de›de›d1¡Zej     
dddg¡dd „ƒZ d!d"„Z ej     
dddd#g¡d$d%„ƒZ d&d'„Zej     
dddd#g¡d(d)„ƒZd*d+„Zd,d-„Zd.d/„Zej     
dddg¡d0d1„ƒZd2d3„Zej     
dddg¡d4d5„ƒZej     
dddg¡d6d7„ƒZd8d9„Zej     d:¡d;d<„ƒZd=d>„Zd?S)@Ú TestCharacterrZtest_characterú
       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
    rr3ÚS1cCs¨t|j|jdƒ}t|tjd|dƒtdƒƒt|tjd|dƒtdƒƒt|tjdg|dƒtdƒƒt|tjd|dƒtdƒƒt|tjdgg|dƒtdƒƒdS)NÚ_inputrróar)rrrrrrr"©r$rr&r'r'r(r)òs zTestCharacter.test_inputc
Cs°t|j|jdƒ}t|dƒtdƒƒt|dƒtdƒƒt|dƒdƒt|dƒdƒt|dƒdƒt|dƒtdƒƒt|d    ƒtdƒƒt|dgƒtdƒƒt|t d¡ƒtdƒƒt|t dg¡ƒtdƒƒt d¡}t||ƒtdƒƒt dg¡}t||ƒtdƒƒz |gƒWn6tk
rF}zt|ƒ     d
¡s6‚W5d}~XYnXt
|j ›d ƒ‚z |d ƒWn6t k
rš}zt|ƒ     d ¡sŠ‚W5d}~XYnXt
|j ›dƒ‚dS)NrQrrRr róóÚabsabz  got 0-listz! should have failed on empty listéaz got int instancez  should have failed on int value) rrrrr"rrÚ
IndexErrorÚstrÚendswithÚ SystemErrorrBÚ    TypeError©r$r&rÚmsgr'r'r(Útest_input_variaüs6
   zTestCharacter.test_input_variaÚU1cCszt|j|jdƒ}t|tjdddg|dƒtjtttdƒƒddƒt|tjdd    d
g|dƒtjtttdƒƒddƒdS) NÚ _array_inputrÚbr3rrÚi1rRóbóc)    rrrrrrr r!r"rSr'r'r(r:sÿÿzTestCharacter.test_array_inputc
Cs¾t|j|jdƒ}t|dddgƒtjtttdƒƒddƒt|dd    d
gƒtjtttdƒƒddƒz|dddd gƒWn2t    k
r¨}zt
|ƒ  d ¡s˜‚W5d}~XYnXt |j ›d ƒ‚dS)Nrarrbr3rrcrrRrdreÚdú)th dimension must be fixed to 3 but got 4ú" should have failed on wrong input)rrrrrrr r!r"Ú
ValueErrorrYrZr[rB)r$r&r^r'r'r(Útest_array_input_varia(s"ÿÿÿ
ÿz$TestCharacter.test_array_input_variacCs^t|j|jdƒ}tjdddgdddgg|dd    }| |d
krDtjntj¡}t||ƒ|ƒdS) NZ_2d_array_inputrrbr3rfÚer&r<r?r`)    rrrrrÚviewZuint32Zuint8r)r$rr&rr9r'r'r(rA9s ÿÿz!TestCharacter.test_2d_array_inputcCs6t|j|jdƒ}t|tdƒƒdƒt|dƒdƒdS)NÚ_outputrRrrU)rrrrr"©r$r&r'r'r(r,BszTestCharacter.test_outputcCs<t|j|jdƒ}t|tttdƒƒƒtjtdƒddƒdS)NZ _array_outputrrPr)    rrrrr r!r"rrrnr'r'r(r;HsÿzTestCharacter.test_array_outputcCs@t|j|jdƒ}t|dƒdƒt|dƒdƒt|dƒdƒdS)NZ _input_outputrRrr rU©rrrrrnr'r'r(Útest_input_outputNszTestCharacter.test_input_outputcCsªt|j|jdƒ}tjtdƒ|d}||dƒt|tjtdƒ|jdƒ||dd…dƒt|tjtdƒ|jdƒtjdg|d}||dƒt|tjdg|jdƒdS)    NÚ_inoutrrr-ÚAbcéÚBZABc)rrrrrr rr)r$rr&rr'r'r(Ú
test_inoutUs
 
zTestCharacter.test_inoutc
CsÈt|j|jdƒ}tjddd}||dƒt|tjd|jdƒtjdgdd}||dƒt|tjdg|jdƒz|ddƒWn2tk
r²}zt|ƒ     d¡s¢‚W5d}~XYnXt
|j ›dƒ‚dS)    NrqrZS3rr-rrz
 got 3-strz  should have failed on str value) rrrrrrrrirYrZr[rBr]r'r'r(Útest_inout_variacs
 
zTestCharacter.test_inout_variac
CsFt|j|jdƒ}tjdddg|dd}tjddd    g|dd}|||ƒt||ƒtjddd    d
g|d }||d d…|ƒt|tjddddg|d ƒtjddd    gg|dd}|||ƒt|tjdddgg|d ƒtjddd    d
g|dd}z|||ƒWn6tk
r0}zt|ƒ d ¡s ‚W5d}~XYnXt    |j
›dƒ‚dS)NZ _array_inoutr-rtÚCr<r?rrbr3rfrrsrgrh) rrrrrrrirYrZr[rB)r$rr&Únrr^r'r'r(Útest_array_inoutus,
 
 
ÿ
ÿzTestCharacter.test_array_inoutcCsjt|j|jdƒ}tjdddgdddgg|dd}tjd    d
d gd d dgg|dd}|||ƒt||ƒdS)NZ_2d_array_inoutr-rtrwÚDÚEr<r?rrbr3rfrkr&r7)r$rr&rxrr'r'r(Útest_2d_array_inout‘s ÿþ ÿþ
z!TestCharacter.test_2d_array_inoutcCs$t|j|jdƒ}t|dƒdƒdS)NZ_returnrrRrornr'r'r(Ú test_returnszTestCharacter.test_returnz*fortran function returning array segfaultscCs6t|j|jdƒ}tjtdƒdd}t||ƒ|ƒdS)NZ _array_returnrrPr)rrrrrr r)r$r&rr'r'r(Útest_array_return¢szTestCharacter.test_array_returncCs0t|j|jdƒ}t|ƒdƒt|dƒdƒdS)NZ    _optionalrRóBrornr'r'r(Ú test_optional©s zTestCharacter.test_optionalN)rBrCrDrErrIrJrFrKrLrMr)r_r:rjrAr,r;rprurvryr|r}Úskipr~r€r'r'r'r(rN†s’ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ
g
    #
 
 
 
 
 
 
rNc@s¢eZdZdZdZe de›de›de›de›de›de›d    e›d
e›d e›d e›d e›de›d¡Zdd„Zdd„Z    dd„Z
dd„Z e j  dddg¡dd„ƒZdS)ÚTestMiscCharacterrZtest_misc_characterrOa(_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
         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
    cCs:t|j|jdƒ}tjddgdd}||ƒ}t||ƒdS)NZ_gh18684ÚabcdeZfghijÚS5rr7)r$r&ÚxÚyr'r'r(Ú test_gh18684szTestMiscCharacter.test_gh18684cCs~t|j|jdƒ}t|jjjjt d¡ƒtt|jjjƒdƒ|ddƒt|jjjddƒ|ddƒt|jjjdd    ƒdS)
NZ_gh6308r„é rƒrsabcdeZ12345és12345)    rrrrZ_BLNK_ÚnamerrÚlenrnr'r'r(Ú test_gh6308
s
 
zTestMiscCharacter.test_gh6308c
CsÌt|j|jdƒ}dtdt d¡dfdtdt d¡dftjdd    d
gdd td t d¡dfdd    d gtd t d¡dfddgtdt d¡dffD]2\}}||ƒ}| ¡D]\}}tt||ƒ|ƒq¬q”dS)NZ_gh4519rr'rP)ÚshaperÚtextZS4rÚ2r    r)éZ34ZS2r )é)    rrrrGrrrÚitemsr)r$r&r…r9ÚrÚkÚvr'r'r(Ú test_gh4519sÿÿù zTestMiscCharacter.test_gh4519cCs@t|j|jdƒ}t|dƒdƒt|dƒdƒt|dƒdƒdS)NZ_gh3425ZabCsABCr rTZabC12dsABC12Drornr'r'r(Ú test_gh3425%szTestMiscCharacter.test_gh3425ÚstateÚnewÚoldcsrt|j|jd|ƒ‰ˆƒ\}}t|dƒtt|ƒdƒˆdƒ\}}t|dƒtt|ƒdƒtt‡fdd„ƒdS)NZ_character_bc_rRrsrdr‘csˆdƒS)Nrer'r'©r&r'r(Ú<lambda>:rTz5TestMiscCharacter.test_character_bc.<locals>.<lambda>)rrrrr‹rÚ    Exception)r$r˜r3rr'r›r(Útest_character_bc.s
 
 
z#TestMiscCharacter.test_character_bcN)rBrCrDrErrIrJrFr‡rŒr–r—rKrLrMržr'r'r'r(r‚°sBÿÿÿÿÿÿÿÿÿÿÿÿ
M     r‚c@s>eZdZe dddd¡gZejjdd„ƒZ    ejjdd„ƒZ
d    S)
ÚTestStringScalarArrÚtestsÚsrcÚstringzscalar_string.f90cCsB|jjj|jjjfD](}d}|j|ks*t‚d}|j|kst‚qdS)Nr'z|S8)rÚ string_testr¢Zstring77rÚAssertionErrorr©r$Úoutr9r'r'r(Ú    test_char@sÿzTestStringScalarArr.test_charcCsB|jjj|jjjfD](}d}|j|ks*t‚d}|j|kst‚qdS)N)r‰éz|S12)rr£ZstrarrZstrarr77rr¤rr¥r'r'r(Ú test_char_arrIsÿz!TestStringScalarArr.test_char_arrN) rBrCrDrZgetpathÚsourcesrKrLZslowr§r©r'r'r'r(rŸ=s
 
rŸ)rKrIZ numpy.testingrrrÚnumpyrZnumpy.f2py.testsrZF2PyTestrrNr‚rŸr'r'r'r(Ú<module>s ~,