1 /*
2 *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 *  Copyright (C) 2008-2008 - DIGITEO - Antoine ELIAS
4 *  Copyright (C) 2010-2011 - DIGITEO - Bruno JOFRET
5 *  Copyright (C) 2018 - Stéphane Mottelet
6  *
7  * Copyright (C) 2012 - 2016 - Scilab Enterprises
8  *
9  * This file is hereby licensed under the terms of the GNU GPL v2.0,
10  * pursuant to article 5.3.4 of the CeCILL v.2.1.
11  * This file was originally licensed under the terms of the CeCILL v2.1,
12  * and continues to be available under such terms.
13  * For more information, see the COPYING file which you should have received
14  * along with this program.
15 *
16 */
17 
18 #ifndef __ELEM_FUNC_GW_HXX__
19 #define __ELEM_FUNC_GW_HXX__
20 
21 #include "cpp_gateway_prototype.hxx"
22 #include "double.hxx"
23 #include "complex"
24 #include "function.hxx"
25 
26 extern "C"
27 {
28 #include "dynlib_elementary_functions_gw.h"
29 }
30 
31 class ElemFuncModule
32 {
33 private :
ElemFuncModule()34     ElemFuncModule() {};
~ElemFuncModule()35     ~ElemFuncModule() {};
36 public :
37     EXTERN_EF_GW static int Load();
Unload()38     EXTERN_EF_GW static int Unload()
39     {
40         return 1;
41     }
42 };
43 
44 CPP_GATEWAY_PROTOTYPE(sci_abs);
45 CPP_GATEWAY_PROTOTYPE(sci_acos);
46 CPP_GATEWAY_PROTOTYPE(sci_acosh);
47 CPP_GATEWAY_PROTOTYPE(sci_asin);
48 CPP_GATEWAY_PROTOTYPE(sci_asinh);
49 CPP_GATEWAY_PROTOTYPE(sci_atan);
50 CPP_GATEWAY_PROTOTYPE(sci_atanh);
51 CPP_GATEWAY_PROTOTYPE(sci_base2dec);
52 CPP_GATEWAY_PROTOTYPE(sci_bitstring);
53 CPP_GATEWAY_PROTOTYPE(sci_ceil);
54 CPP_GATEWAY_PROTOTYPE(sci_clean);
55 CPP_GATEWAY_PROTOTYPE(sci_conj);
56 CPP_GATEWAY_PROTOTYPE(sci_cos);
57 CPP_GATEWAY_PROTOTYPE(sci_cosh);
58 CPP_GATEWAY_PROTOTYPE(sci_cumprod);
59 CPP_GATEWAY_PROTOTYPE(sci_cumsum);
60 CPP_GATEWAY_PROTOTYPE(sci_dec2base);
61 CPP_GATEWAY_PROTOTYPE(sci_diag);
62 CPP_GATEWAY_PROTOTYPE(sci_dsearch);
63 CPP_GATEWAY_PROTOTYPE(sci_exp);
64 CPP_GATEWAY_PROTOTYPE(sci_expm);
65 CPP_GATEWAY_PROTOTYPE(sci_eye);
66 CPP_GATEWAY_PROTOTYPE(sci_floor);
67 CPP_GATEWAY_PROTOTYPE(sci_frexp);
68 CPP_GATEWAY_PROTOTYPE(sci_gsort);
69 CPP_GATEWAY_PROTOTYPE(sci_imag);
70 CPP_GATEWAY_PROTOTYPE(sci_imult);
71 CPP_GATEWAY_PROTOTYPE(sci_int);
72 CPP_GATEWAY_PROTOTYPE(sci_isequal);
73 CPP_GATEWAY_PROTOTYPE(sci_isreal);
74 CPP_GATEWAY_PROTOTYPE(sci_issquare);
75 CPP_GATEWAY_PROTOTYPE(sci_isvector);
76 CPP_GATEWAY_PROTOTYPE(sci_kron);
77 CPP_GATEWAY_PROTOTYPE(sci_linspace);
78 CPP_GATEWAY_PROTOTYPE(sci_log);
79 CPP_GATEWAY_PROTOTYPE(sci_log10);
80 CPP_GATEWAY_PROTOTYPE(sci_log1p);
81 CPP_GATEWAY_PROTOTYPE(sci_matrix);
82 CPP_GATEWAY_PROTOTYPE(sci_max); // Old name sci_maxi
83 CPP_GATEWAY_PROTOTYPE(sci_min); // Old name sci_mini
84 CPP_GATEWAY_PROTOTYPE(sci_nearfloat);
85 CPP_GATEWAY_PROTOTYPE(sci_ones);
86 CPP_GATEWAY_PROTOTYPE(sci_permute);
87 CPP_GATEWAY_PROTOTYPE(sci_prod);
88 CPP_GATEWAY_PROTOTYPE(sci_rand);
89 CPP_GATEWAY_PROTOTYPE(sci_rat);
90 CPP_GATEWAY_PROTOTYPE(sci_real);
91 CPP_GATEWAY_PROTOTYPE(sci_round);
92 CPP_GATEWAY_PROTOTYPE(sci_sign);
93 CPP_GATEWAY_PROTOTYPE(sci_sin);
94 CPP_GATEWAY_PROTOTYPE(sci_sinh);
95 CPP_GATEWAY_PROTOTYPE(sci_size);
96 CPP_GATEWAY_PROTOTYPE(sci_sqrt);
97 CPP_GATEWAY_PROTOTYPE(sci_sum);
98 CPP_GATEWAY_PROTOTYPE(sci_tan);
99 CPP_GATEWAY_PROTOTYPE(sci_tanh);
100 CPP_GATEWAY_PROTOTYPE(sci_tril);
101 CPP_GATEWAY_PROTOTYPE(sci_triu);
102 CPP_GATEWAY_PROTOTYPE(sci_zeros);
103 
104 
105 bool getDimsFromArguments(types::typed_list& in, const std::string& _pstName, int* _iDims, int** _piDims, bool* _alloc);
106 
107 template <class T>
getAsDouble(T * _val)108 types::Double* getAsDouble(T* _val)
109 {
110     types::Double* dbl = new types::Double(_val->getDims(), _val->getDimsArray());
111     double* pOut = dbl->get();
112     typename T::type* pIn = _val->get();
113     int size = dbl->getSize();
114     for (int i = 0; i < size; i++)
115     {
116         pOut[i] = static_cast<double>(pIn[i]);
117     }
118 
119     return dbl;
120 }
121 
122 template <class T>
toInt(types::Double * _dbl)123 T* toInt(types::Double* _dbl)
124 {
125     T* pI = new T(_dbl->getDims(), _dbl->getDimsArray());
126     typename T::type* p = pI->get();
127     double* pdbl = _dbl->get();
128     int size = _dbl->getSize();
129     for (int i = 0; i < size; i++)
130     {
131         p[i] = static_cast<typename T::type>(pdbl[i]);
132     }
133 
134     return pI;
135 }
136 
137 typedef double(*func_real)(double);
138 typedef std::complex<double>(*func_complex)(const std::complex<double>&);
139 
140 types::Double* trigo(types::Double* in, func_real func_r, func_complex func_c, bool forceComplex = false);
141 types::Function::ReturnValue zerosOrOnesFromValue(types::typed_list& in, int _iRetCount, types::typed_list& out, bool value);
142 
143 #endif /* __ELEM_FUNC_GW_HXX__ */
144