
    Qiu                         d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
mZmZmZ  ed          Z ed          ZddgZdd
Zd Z ed          d             ZdS )    N)import_module)skipskip_under_pyodide)compile_link_import_py_extcompile_link_import_stringscompile_sourcesget_abspathnumpycython)z	sigmoid.cz
#include <math.h>

void sigmoid(int n, const double * const restrict in,
             double * const restrict out, double lim){
    for (int i=0; i<n; ++i){
        const double x = in[i];
        out[i] = x*pow(pow(x/lim, 8)+1, -1./8.);
    }
}
)z_sigmoid.pyxaw  
import numpy as np
cimport numpy as cnp

cdef extern void c_sigmoid "sigmoid" (int, const double * const,
                                      double * const, double)

def sigmoid(double [:] inp, double lim=350.0):
    cdef cnp.ndarray[cnp.float64_t, ndim=1] out = np.empty(
        inp.size, dtype=np.float64)
    c_sigmoid(inp.size, &inp[0], &out[0], lim)
    return out
     u@c                 $    | | |z  dz  dz   dz  z  S )N      g      ? )datalims     /var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/sympy/utilities/_compilation/tests/test_compilation.pynpyr   )   s    $s(QqD)))    c                  v   t           st          d           t          st          d           ddlm}   |             st          d           dt                                           gd}d }	 t          t          |          \  }}t           j                            d	          }|	                    |          }t          |          }t                               ||          sJ 	 |r$|d
         rt          j        |d
                    d S d S d S # |r#|d
         rt          j        |d
                    w w w xY w)Nznumpy not installed.zcython not installed.r   has_cNo C compiler found.c99)stdinclude_dirs)compile_kwargsi   	build_dir)r
   r   r   sympy.utilities._compilationr   get_includer   	_sources1randomsigmoidr   allcloseshutilrmtree)r   
compile_kwinfomodr   res_modres_npys          r    test_compile_link_import_stringsr,   -   se    %#$$$ &$%%%222222577 %#$$$1B1B1D1D0EFFJD-/	*UUU	T|"";//++d##d))~~gw////// 	-D% 	-M${+,,,,,	- 	- 	- 	-4 	-D% 	-M${+,,,,	- 	-s   ,A9D (D8z(Emscripten does not support subprocessesc                     t          j                    } ddlm}  |            st	          d           t          |           }t          j        d|          \  }}t          |d          5 }|                    d           d d d            n# 1 swxY w Y   t          |g|          \  }t          ||          }t          j                            |          sJ 	 t          j        d	d
g          }t          j        d	|g          }	d|	                    d          v sJ n# t          j        $ r Y nw xY wt$          sd S t          j        d|          \  }}
t          |
d          5 }|                    d           d d d            n# 1 swxY w Y   t'          |
g|g|          }|                    d          dk    sJ d S )Nr   r   r   z.c)dirwtzH
        int foo(int bar) {
            return 2*bar;
        }
        )cwdnmz--helpfoozutf-8z.pyxz;cdef extern int foo(int)
def _foo(arg):
    return foo(arg))
extra_objsr      *   )tempfilemkdtempr   r   r   strmkstempopenwriter   r	   ospathexists
subprocesscheck_outputdecodeCalledProcessErrorr   r   _foo)tmpdirr   r   _handle	file_pathofhobjobj_path_nm_outpyx_pathr)   s               r   test_compile_sourcesrM   D   s}   F222222577 %#$$$FI!)$I>>>GY	i		 #		  	 	 	               I;I666DC3I...H7>>(#####/#T8$455 ($)9::g.......	 (      (Y???GX	h		 +		 ) 	+ 	+ 	++ + + + + + + + + + + + + + + %hZXJR[
\
\
\C88B<<2s6   +BBBD% %D76D7,FFF)r   )r%   r<   r?   r6   sympy.externalr   sympy.testing.pytestr   r   (sympy.utilities._compilation.compilationr   r   r   r	   r
   r   r!   r   r,   rM   r   r   r   <module>rQ      s#    				      ( ( ( ( ( ( 9 9 9 9 9 9 9 9 K  K  K  K  K  K  K  K  K  K  K  Kg	x	 	 
	8* * * *- - -. >??# # @?# # #r   