U
    L?h                     @   s   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
dZdd Zdd ZdS )    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
     u@c                 C   s   | | | d d d  S )N      g      ? )dataZlimr   r   e/var/www/html/venv/lib/python3.8/site-packages/sympy/utilities/_compilation/tests/test_compilation.pynpy)   s    r   c               
   C   s   t std tstd ddlm}  |  s2td dt  gd}d }zBtt	|d	\}}t j

d
}||}t|}t ||stW 5 |r|d rt|d  X d S )Nznumpy not installed.zcython not installed.r   has_cNo C compiler found.Zc99)Zstdinclude_dirs	build_dir)compile_kwargsi   )r   r   r	   sympy.utilities._compilationr   Zget_includeshutilrmtreer   	_sources1randomZsigmoidr   ZallcloseAssertionError)r   Z
compile_kwinfomodr   Zres_modZres_npyr   r   r    test_compile_link_import_strings-   s"    
r   c              	   C   s.  ddl m} | std t| }tjd|d\}}t|d}|d W 5 Q R X t|g|d\}t	||d}t
j|stztd	d
g}W n tjk
r   Y n"X td	|g}	d|	dksttsd S tjd|d\}}
t|
d}|d W 5 Q R X t|
g|g|d}|ddks*td S )Nr   r   r   z.c)dirZwtzH
        int foo(int bar) {
            return 2*bar;
        }
        )cwdnmz--helpZfoozutf-8z.pyxz;cdef extern int foo(int)
def _foo(arg):
    return foo(arg))Z
extra_objsr      *   )r   r   r   strtempfilemkstempopenwriter   r   ospathexistsr   
subprocesscheck_outputCalledProcessErrordecoder	   r   Z_foo)Ztmpdirr   r   Z_handle	file_pathZofhobjZobj_path_Znm_outZpyx_pathr   r   r   r   test_compile_sourcesD   s.    r4   )r
   )r   r*   r-   r&   Zsympy.externalr   Zsympy.testing.pytestr   Z(sympy.utilities._compilation.compilationr   r   r   r   r   r	   r   r   r   r4   r   r   r   r   <module>   s   
