U
    e,M                     @   sr   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	 G dd de	j
ZG dd de	j
ZG dd	 d	e	j
ZdS )
    N)assert_array_equalassert_equalassert_raises)utilc                7   @   s^  e Zd ZdZdZdddgZdZeD ]ZeZe	dd
eeZe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e d3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.f90Z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abcdeabcdeabcder   r	   r
   u1dtype)
getgetattrmodulefprefixr   nparraylistmapordselfr   fsuffixfr    r'   `/var/www/html/assets/scripts/venv/lib/python3.8/site-packages/numpy/f2py/tests/test_character.py
test_inputL   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_outputU   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   s   g | ]}d d |D qS )c                 S   s   g | ]}|qS r'   r'   .0cr'   r'   r(   
<listcomp>h   s     zCTestCharacterString.test_array_input.<locals>.<listcomp>.<listcomp>r'   r2   sr'   r'   r(   r4   h   s     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.   r/   r0   r   c                 S   s   g | ]}d d |D qS )c                 S   s   g | ]}|qS r'   r'   r1   r'   r'   r(   r4   t   s     zDTestCharacterString.test_array_output.<locals>.<listcomp>.<listcomp>r'   r5   r'   r'   r(   r4   t   s     z9TestCharacterString.test_array_output.<locals>.<listcomp>r   r7   )r$   r   r%   r&   r9   r   r'   r'   r(   test_array_outputk   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.   r/   r&   ZfghZfghijfghijfghijFZFGHZFGHIJFGHIJFGHIJr0   r   c                 S   s   g | ]}d d |D qS )c                 S   s   g | ]}d d |D qS )c                 S   s   g | ]}|qS r'   r'   r1   r'   r'   r(   r4      s     zQTestCharacterString.test_2d_array_input.<locals>.<listcomp>.<listcomp>.<listcomp>r'   )r2   itemr'   r'   r(   r4      s     zFTestCharacterString.test_2d_array_input.<locals>.<listcomp>.<listcomp>r'   )r2   rowr'   r'   r(   r4      s     z;TestCharacterString.test_2d_array_input.<locals>.<listcomp>r   r   orderr7   r8   r'   r'   r(   test_2d_array_inputw   s      z'TestCharacterString.test_2d_array_input)__name__
__module____qualname__suffixr   Zlength_listcoder   r%   dictr   Zclengthtextwrapdedentpytestmarkparametrizer)   r,   r:   r;   rA   r'   r'   r'   r(   r      s   
9

	

r   c                3   @   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e de de de de de de de de de de de d1Zej	
dddgdd  Zd!d" Zej	
dddd#gd$d% Zd&d' Zej	
dddd#gd(d) Zd*d+ Zd,d- Zd.d/ Zej	
dddgd0d1 Zd2d3 Zej	
dddgd4d5 Zej	
dddgd6d7 Zd8d9 Zej	d:d;d< Zd=d> Zd?S )@TestCharacterr   Ztest_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
    r   r3   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 n6 tk
rF } zt|	d
s6 W 5 d }~X Y nX t
|j dz|d W n6 tk
r } zt|	ds W 5 d }~X Y nX t
|j dd S )NrP   r   rQ   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SystemErrorrB   	TypeErrorr$   r&   r   msgr'   r'   r(   test_input_varia   s6    
zTestCharacter.test_input_variaU1c                 C   sz   t | j| jd }t|tjdddg|dtjtttddd t|tjdd	d
g|dtjtttddd d S )N_array_inputr   br3   r   r   i1rQ      b   c)	r   r   r   r   r   r   r    r!   r"   rR   r'   r'   r(   r:     s    zTestCharacter.test_array_inputc              
   C   s   t | j| jd }t|dddgtjtttddd t|dd	d
gtjtttddd z|ddddg W n2 t	k
r } zt
|ds W 5 d }~X Y nX t|j dd S )Nr`   r   ra   r3   r   rb   r   rQ   rc   rd   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"   
ValueErrorrX   rY   rZ   rB   )r$   r&   r]   r'   r'   r(   test_array_input_varia(  s"    
z$TestCharacter.test_array_input_variac                 C   s^   t | j| jd }tjdddgdddgg|dd	}||d
krDtjntj}t||| d S )NZ_2d_array_inputr   ra   r3   re   er&   r<   r?   r_   )	r   r   r   r   r   viewZuint32Zuint8r   )r$   r   r&   r   r9   r'   r'   r(   rA   9  s     z!TestCharacter.test_2d_array_inputc                 C   s6   t | j| jd }t|tdd t|dd d S )N_outputrQ   r   rT   )r   r   r   r   r"   r$   r&   r'   r'   r(   r,   B  s    zTestCharacter.test_outputc                 C   s<   t | j| jd }t|tttdtjtddd d S )NZ_array_outputr   rO   r   )	r   r   r   r   r    r!   r"   r   r   rm   r'   r'   r(   r;   H  s    zTestCharacter.test_array_outputc                 C   s@   t | j| jd }t|dd t|dd t|dd d S )NZ_input_outputrQ   r   r   rT   r   r   r   r   rm   r'   r'   r(   test_input_outputN  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   BZABc)r   r   r   r   r   r    r   r   )r$   r   r&   r   r'   r'   r(   
test_inoutU  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 n2 tk
r } zt|	ds W 5 d }~X Y nX t
|j dd S )	Nrp   r   ZS3r   r-   rq   z
 got 3-strz  should have failed on str value)r   r   r   r   r   r   r   rh   rX   rY   rZ   rB   r\   r'   r'   r(   test_inout_variac  s    

zTestCharacter.test_inout_variac              
   C   sF  t | j| jd }tjdddg|dd}tjddd	g|dd}||| t|| tjddd	d
g|d}||dd  | t|tjddddg|d tjddd	gg|dd}||| t|tjdddgg|d tjddd	d
g|dd}z||| W n6 tk
r0 } zt|ds  W 5 d }~X Y nX t	|j
 dd S )NZ_array_inoutr-   rs   Cr<   r?   r   ra   r3   re   r   rr   rf   rg   )r   r   r   r   r   r   rh   rX   rY   rZ   rB   )r$   r   r&   nr   r]   r'   r'   r(   test_array_inoutu  s,    



zTestCharacter.test_array_inoutc                 C   sj   t | j| jd }tjdddgdddgg|dd}tjd	d
dgdddgg|dd}||| t|| d S )NZ_2d_array_inoutr-   rs   rv   DEr<   r?   r   ra   r3   re   rj   r&   r7   )r$   r   r&   rw   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 )NZ_returnr   rQ   rn   rm   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 )NZ_array_returnr   rO   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 )NZ	_optionalrQ      Brn   rm   r'   r'   r(   test_optional  s    zTestCharacter.test_optionalN)rB   rC   rD   rE   r   rH   rI   rF   rJ   rK   rL   r)   r^   r:   ri   rA   r,   r;   ro   rt   ru   rx   r{   r|   skipr}   r   r'   r'   r'   r(   rM      s   
g
	#






rM   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dd Zdd Z	dd Z
dd Zejdddgdd ZdS )TestMiscCharacterr   Ztest_misc_characterrN   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
         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 )NZ_gh18684abcdeZfghijS5r   r7   )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 )
NZ_gh6308r      r   r   s   abcdeZ12345   s   12345)	r   r   r   r   Z_BLNK_namer   r   lenrm   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dd	d
gddtdtddfdd	dgtdtddfddgtdtddffD ]2\}}||}| D ]\}}tt ||| qqd S )NZ_gh4519r   r'   rO   )shaper   textZS4r   2r	   r   )   Z34ZS2r   )   )	r   r   r   rG   r   r   r   itemsr   )r$   r&   r   r9   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 )NZ_gh3425ZabCs   ABCr   rS   ZabC12ds   ABC12Drn   rm   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 )NZ_character_bc_rQ   rr   rc   r   c                      s    dS )Nrd   r'   r'   r&   r'   r(   <lambda>:  rS   z5TestMiscCharacter.test_character_bc.<locals>.<lambda>)r   r   r   r   r   r   	Exception)r$   r   r3   r   r'   r   r(   test_character_bc.  s    


z#TestMiscCharacter.test_character_bcN)rB   rC   rD   rE   r   rH   rI   rF   r   r   r   r   rJ   rK   rL   r   r'   r'   r'   r(   r     sB   
M	r   )rJ   rH   Znumpy.testingr   r   r   numpyr   Znumpy.f2py.testsr   ZF2PyTestr   rM   r   r'   r'   r'   r(   <module>   s   ~  ,