o
    >~#gU                     @   s   d dl Z d dlZd dlmZmZmZ d dlZd dlm	Z	 e j
jG dd de	jZG dd de	jZG dd	 d	e	jZG d
d de	jZG dd de	jZe j
jG dd de	jZe j
jG dd de	jZe j
jG dd de	jZdS )    N)assert_array_equalassert_equalassert_raises)utilc                   @   s  e Zd ZdZdZg dZdZeD ]ZeZe	dd
eeZeedg de de d	e d
e de de de d	e de de de de de de de de de de de de de de de de de d7 Zqejdedd Zejdedd dd Zejdedd Zejded d! Zejded"d# ZdS )$TestCharacterString.f90test_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	
        lengthc                 C   s\   ddi ||}t| j| jd | }dddd| }t||tjttt	|dd	 d S )
Nr   r   r   aabcabcdeabcdeabcder	   u1dtype)
getgetattrmodulefprefixr   nparraylistmapordselfr   fsuffixfr    r(   /var/www/static.ux5.de/https/Moving-Object-Detection-with-OpenCV/env/lib/python3.10/site-packages/numpy/f2py/tests/test_character.py
test_inputM   s   &zTestCharacterString.test_inputNc                 C   sR   |}t | j| jd | }ddd| }t|tjttt|dd|	  d S )Nr   r   r   )r
   r   r   r   )
r   r   r   r   r   r    r!   r"   r#   encoder$   r(   r(   r)   test_outputV   s   zTestCharacterString.test_outputc                 C   sn   |}t | j| jd | }tjdddd| dddd| gd	d
}tjdd |D dd
}t||| d S )Nr   r   r   r   r	   AABCABCDEABCDEABCDESr   c                 S      g | ]	}d d |D qS )c                 S      g | ]}|qS r(   r(   .0cr(   r(   r)   
<listcomp>i       zCTestCharacterString.test_array_input.<locals>.<listcomp>.<listcomp>r(   r5   sr(   r(   r)   r7   i       z8TestCharacterString.test_array_input.<locals>.<listcomp>r   r   r   r   r   r    r   r%   r   r&   r'   r   expectedr(   r(   r)   test_array_input`   s   z$TestCharacterString.test_array_inputc                 C   sn   |}t | j| jd | }tjdddd| dddd| gd	d
}tjdd |D dd
}t||| d S )Nr   r   r   r   r	   r.   r/   r0   r1   r   c                 S   r2   )c                 S   r3   r(   r(   r4   r(   r(   r)   r7   u   r8   zDTestCharacterString.test_array_output.<locals>.<listcomp>.<listcomp>r(   r9   r(   r(   r)   r7   u   r;   z9TestCharacterString.test_array_output.<locals>.<listcomp>r   r<   )r%   r   r&   r'   r>   r   r(   r(   r)   test_array_outputl   s   z%TestCharacterString.test_array_outputc                 C   s   |}t | j| jd | }tjdddd| dddd| gd	d
dd| dddd| ggdd}tjdd |D ddd}t||| d S )Nr   r   r   r   r	   r.   r/   r0   r'   fghfghijfghijfghijFFGHFGHIJFGHIJFGHIJr1   r   c                 S   r2   )c                 S   r2   )c                 S   r3   r(   r(   r4   r(   r(   r)   r7      r8   zQTestCharacterString.test_2d_array_input.<locals>.<listcomp>.<listcomp>.<listcomp>r(   )r5   itemr(   r(   r)   r7      r;   zFTestCharacterString.test_2d_array_input.<locals>.<listcomp>.<listcomp>r(   )r5   rowr(   r(   r)   r7      r;   z;TestCharacterString.test_2d_array_input.<locals>.<listcomp>r   r   orderr<   r=   r(   r(   r)   test_2d_array_inputx   s   z'TestCharacterString.test_2d_array_input)__name__
__module____qualname__suffixr   length_listcoder   r&   dictr   clengthtextwrapdedentjoinpytestmarkparametrizer*   r-   r?   r@   rJ   r(   r(   r(   r)   r      s    		((**,669

	

r   c                   @   s  e Zd ZdZdZedg de de de de de d	e d
e de de de de de de de de de de de de de de de de de dZe	j
dddgd d! Zd"d# Ze	j
dg d$d%d& Zd'd( Ze	j
dg d$d)d* Zd+d, Zd-d. Zd/d0 Ze	j
dddgd1d2 Zd3d4 Ze	j
dddgd5d6 Ze	j
dddgd7d8 Zd9d: Ze	j
d;d<d= Zd>d? Zd@S )A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
    r   r6   S1c                 C   s   t | j| jd }t|tjd|dtd t|tjd|dtd t|tjdg|dtd t|tjd|dtd t|tjdgg|dtd d S )N_inputr   r      ar   )r   r   r   r   r   r    r#   r%   r   r'   r(   r(   r)   r*      s   $zTestCharacter.test_inputc              
   C   s  t | j| jd }t|dtd t|dtd t|dd t|dd t|dd t|dtd t|d	td t|dgtd t|tdtd t|tdgtd td}t||td tdg}t||td z|g  W n ty } zt|	d
s W Y d }~nd }~ww t
|j dz|d W n ty } zt|	ds W Y d }~d S d }~ww t
|j d)Nr]   r   r^   r   r           abs   abz got 0-listz! should have failed on empty lista   z got int instancez  should have failed on int value)r   r   r   r   r#   r   r    
IndexErrorstrendswithSystemErrorrK   	TypeErrorr%   r'   r   msgr(   r(   r)   test_input_varia   sB   
zTestCharacter.test_input_varia)r6   r\   U1c                 C   sv   t | j| jd }t|tjg d|dtjtttddd t|tjg d|dtjtttddd d S )N_array_inputr   br6   r   r   i1r^      b   c)	r   r   r   r   r   r    r!   r"   r#   r_   r(   r(   r)   r?      s   zTestCharacter.test_array_inputc              
   C   s   t | j| jd }t|g dtjtttddd t|g dtjtttddd z|g d W n t	yR } zt
|dsG W Y d }~d S d }~ww t|j d	)
Nrm   rn   r   rp   r   rq   r   ro   r6   d)th dimension must be fixed to 3 but got 4" should have failed on wrong input)r   r   r   r   r   r    r!   r"   r#   
ValueErrorre   rf   rg   rK   )r%   r'   rj   r(   r(   r)   test_array_input_varia)  s(   
z$TestCharacter.test_array_input_variac                 C   sZ   t | j| jd }tjg dg dg|dd}||dkr tjntj}t||| d S )N_2d_array_inputrn   ru   er'   rC   rH   rl   )	r   r   r   r   r    viewuint32uint8r   )r%   r   r'   r   r>   r(   r(   r)   rJ   :  s   
z!TestCharacter.test_2d_array_inputc                 C   s6   t | j| jd }t|tdd t|dd d S )N_outputr^   r   ra   )r   r   r   r   r#   r%   r'   r(   r(   r)   r-   C  s   zTestCharacter.test_outputc                 C   s<   t | j| jd }t|tttdtjtddd d S )N_array_outputr   r\   r   )	r   r   r   r   r!   r"   r#   r   r    r   r(   r(   r)   r@   I  s   zTestCharacter.test_array_outputc                 C   s@   t | j| jd }t|dd t|dd t|dd d S )N_input_outputr^   r   r   ra   r   r   r   r   r   r(   r(   r)   test_input_outputO  s   zTestCharacter.test_input_outputc                 C   s   t | j| jd }tjtd|d}||d t|tjtd|jd ||dd  d t|tjtd|jd tjdg|d}||d t|tjdg|jd d S )	N_inoutr   r   r.   Abc   BABc)r   r   r   r   r    r!   r   r   )r%   r   r'   r   r(   r(   r)   
test_inoutV  s   

zTestCharacter.test_inoutc              
   C   s   t | j| jd }tjddd}||d t|tjd|jd tjdgdd}||d t|tjdg|jd z|dd W n ty[ } zt|	dsP W Y d }~d S d }~ww t
|j d)	Nr   r   S3r   r.   r   z
 got 3-strz  should have failed on str value)r   r   r   r   r    r   r   rx   re   rf   rg   rK   ri   r(   r(   r)   test_inout_variad  s    

zTestCharacter.test_inout_variac              
   C   s.  t | j| jd }tjg d|dd}tjg d|dd}||| t|| tjg d|d}||dd  | t|tjg d	|d tjg dg|dd}||| t|tjg dg|d tjg d|dd}z||| W n ty } zt|d
s W Y d }~d S d }~ww t	|j
 d)N_array_inoutr.   r   CrC   rH   rn   rt   r   r   )r   r.   r   r   rv   rw   )r   r   r   r   r    r   rx   re   rf   rg   rK   )r%   r   r'   nr   rj   r(   r(   r)   test_array_inoutv  s2   



zTestCharacter.test_array_inoutc                 C   sb   t | j| jd }tjg dg dg|dd}tjg dg dg|dd}||| t|| d S )N_2d_array_inoutr   )DErC   rC   rH   rn   r{   r<   )r%   r   r'   r   r   r(   r(   r)   test_2d_array_inout  s   


z!TestCharacter.test_2d_array_inoutc                 C   s$   t | j| jd }t|dd d S )N_returnr   r^   r   r   r(   r(   r)   test_return  s   zTestCharacter.test_returnz*fortran function returning array segfaultsc                 C   s6   t | j| jd }tjtddd}t||| d S )N_array_returnr   r\   r   )r   r   r   r   r    r!   r   )r%   r'   r   r(   r(   r)   test_array_return  s   zTestCharacter.test_array_returnc                 C   s0   t | j| jd }t| d t|dd d S )N	_optionalr^      Br   r   r(   r(   r)   test_optional  s   zTestCharacter.test_optionalN)rK   rL   rM   rN   r   rS   rT   rU   rP   rV   rW   rX   r*   rk   r?   ry   rJ   r-   r@   r   r   r   r   r   r   skipr   r   r(   r(   r(   r)   rY      s    !#+-79@BIKUW]_dg
	#






rY   c                   @   s   e Zd ZdZdZede de de de de de d	e d
e de de de de dZej	j
dd Zdd Zdd Zdd Zej	dddgdd ZdS )TestMiscCharacterr   test_misc_characterr[   a(  _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
    c                 C   s:   t | j| jd }tjddgdd}||}t|| d S )N_gh18684abcdefghijS5r   r<   )r%   r'   xyr(   r(   r)   test_gh18684  s   zTestMiscCharacter.test_gh18684c                 C   s~   t | j| jd }t| jjjjtd tt| jjjd |dd t| jjjd d |dd t| jjjd d	 d S )
N_gh6308r      r   r   s   abcde12345   s   12345)	r   r   r   r   _BLNK_namer   r   lenr   r(   r(   r)   test_gh6308  s   

zTestMiscCharacter.test_gh6308c              
   C   s   t | j| jd }dtdtddfdtdtddftjg ddd	td
tddfg dtd
tddfddgtdtddffD ]\}}||}| D ]\}}tt ||| qTqHd S )N_gh4519r   r(   r\   )shaper   textS4)r
   2r   r   )   )r
   r   34S2r   )   )	r   r   r   rQ   r   r   r    itemsr   )r%   r'   r   r>   rkvr(   r(   r)   test_gh4519  s    zTestMiscCharacter.test_gh4519c                 C   s@   t | j| jd }t|dd t|dd t|dd d S )N_gh3425abCs   ABCr   r`   abC12ds   ABC12Dr   r   r(   r(   r)   test_gh3425(  s   zTestMiscCharacter.test_gh3425statenewoldc                    sr   t | j| jd |    \}}t|d tt|d  d\}}t|d tt|d tt fdd d S )N_character_bc_r^   r   rr   r   c                      s    dS )Nrs   r(   r(   r'   r(   r)   <lambda>=  s    z5TestMiscCharacter.test_character_bc.<locals>.<lambda>)r   r   r   r   r   r   	Exception)r%   r   r6   r   r(   r   r)   test_character_bc1  s   


z#TestMiscCharacter.test_character_bcN)rK   rL   rM   rN   r   rS   rT   rP   rV   rW   slowr   r   r   r   rX   r   r(   r(   r(   r)   r     sF    	)+:<K
N
	r   c                   @   s.   e Zd ZeddddgZdd Zdd Zd	S )
TestStringScalarArrtestssrcstringzscalar_string.f90c                 C   B   | j jj| j jjfD ]}d}|j|ksJ d}|j|ksJ q
d S )Nr(   z|S8)r   string_testr   string77r   r   r%   outr>   r(   r(   r)   	test_charC     zTestStringScalarArr.test_charc                 C   r   )N)r      z|S12)r   r   strarrstrarr77r   r   r   r(   r(   r)   test_char_arrK  r   z!TestStringScalarArr.test_char_arrN)rK   rL   rM   r   getpathsourcesr   r   r(   r(   r(   r)   r   @  s    r   c                   @   &   e Zd ZeddddgZdd ZdS )TestStringAssumedLengthr   r   r   z	gh24008.fc                 C   s   | j dd d S )Njoebob)r   greet)r%   r(   r(   r)   test_gh24008V  s   z$TestStringAssumedLength.test_gh24008N)rK   rL   rM   r   r   r   r   r(   r(   r(   r)   r   S  s    r   c                   @   r   )TestStringOptionalInOutr   r   r   zgh24662.f90c                 C   sx   | j   tjddd}| j | d|  v sJ tt d}| j | W d    d S 1 s5w   Y  d S )NhiS32r   zoutput stringHi)	r   string_inout_optionalr   r    tobytesdecoderV   raisesr   )r%   r   aar(   r(   r)   test_gh24662]  s   
"z$TestStringOptionalInOut.test_gh24662N)rK   rL   rM   r   r   r   r   r(   r(   r(   r)   r   Y  s    r   c                   @   8   e Zd ZeddddeddddgZdZdd Zd	S )
TestNewCharHandlingr   r   r   zgh25286.pyfgh25286.f90_char_handling_testc                 C      | j d}|dksJ d S NTr   r   charintr%   infor(   r(   r)   test_gh25286p     z TestNewCharHandling.test_gh25286NrK   rL   rM   r   r   r   module_namer   r(   r(   r(   r)   r   g      r   c                   @   r   )
TestBCCharHandlingr   r   r   zgh25286_bc.pyfr   r   c                 C   r   r   r   r   r(   r(   r)   r   }  r   zTestBCCharHandling.test_gh25286Nr   r(   r(   r(   r)   r   t  r   r   )rV   rS   numpy.testingr   r   r   numpyr   numpy.f2py.testsr   rW   r   F2PyTestr   rY   r   r   r   r   r   r   r(   r(   r(   r)   <module>   s(    ~  , 