
    sg                         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 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d Zy)    N)import_module)skip)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
c                 $    | | |z  dz  dz   dz  z  S )N      g      ? )datalims     f/var/www/html/venv/lib/python3.12/site-packages/sympy/utilities/_compilation/tests/test_compilation.pynpyr   )   s    $s(QqD)))    c                     t         st        d       t        st        d       ddlm}   |        st        d       dt         j                         gd}d }	 t        t        |      \  }}t         j                  j                  d	      }|j                  |      }t        |      }t         j                  ||      sJ 	 |r|d
   rt        j                  |d
          y y y # |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*   -   s    #$$%27#$1B1B1D0EFJD-/	*U	T||"";/++d#d)~~gw///D%MM${+, &44D%MM${+, &4s   A'C   #Dc                 
   ddl m}  |       st        d       t        |       }t	        j
                  d|      \  }}t        |d      5 }|j                  d       d d d        t        |g|      \  }t        ||      }t        j                  j                  |      sJ 	 t        j                  d	d
g      }t        j                  d	|g      }	d|	j                  d      v sJ t"        sy t	        j
                  d|      \  }}
t        |
d      5 }|j                  d       d d d        t%        |
g|g|      }|j'                  d      dk(  sJ y # 1 sw Y   xY w# t        j                   $ r Y w xY w# 1 sw Y   UxY w)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      *   )r   r   r   strtempfile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_sourcesrJ   D   st   27#$FI!))$I>GY	i	 #		  	 I;I6DC3I.H77>>(###/##T8$45 (($)9:g.... ((Y?GX	h	 +		 ) 	++ %hZXJR[
\C88B<25  (( + +s*   
E#E  E9E E65E69F)g     u@)r#   r9   r<   r5   sympy.externalr   sympy.testing.pytestr   (sympy.utilities._compilation.compilationr   r   r   r   r	   r
   r   r   r*   rJ   r   r   r   <module>rN      sW     	   ( % K  Kg	x	 
	8*-.!r   