Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Nov 20, 2020. It is now read-only.
forked from carvalho/numlua
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumlua.h
More file actions
Latest commit
256 lines (226 loc) · 6.93 KB
/
Copy pathnumlua.h
File metadata and controls
256 lines (226 loc) · 6.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/* {=================================================================
*
* numlua.h
* Numeric Lua
* Luis Carvalho (lexcarvalho@gmail.com)
* See Copyright Notice at the bottom of this file
*
* ==================================================================} */
#ifndefnumlua_h
#definenumlua_h
#defineH5_NO_DEPRECATED_SYMBOLS/* use HDF5 1.8 */
#include<lua.h>
#include<lauxlib.h>
#include<math.h>
#include<complex.h>
#include<fftw3.h>
#include<hdf5.h>
#include"blas.h"
#include"lapack.h"
#defineNUMLUA_VERSION "NumericLua 0.3"
#defineNUMLUA_API extern
#ifLUA_VERSION_NUM <= 501
#definelua_rawlen lua_objlen
#definenl_register(L,l,n) luaL_openlib(L,NULL,l,n)
#defineluaL_newlibtable(L,l) \
lua_createtable(L, 0, sizeof(l)/sizeof((l)[0]) - 1)
#defineluaL_newlib(L,l) (luaL_newlibtable(L,l), nl_register(L,l,0))
#definelua_setuservalue lua_setfenv
#definelua_getuservalue lua_getfenv
NUMLUA_APIvoidnl_require (lua_State*L, constchar*modname,
lua_CFunctionopenf, intglb);
#definelua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX)
#else
#definelua_number2int(i,n) ((i)=(int)(n))
#definenl_register luaL_setfuncs
#definenl_require luaL_requiref
#endif
NUMLUA_APIintnl_typeerror (lua_State*L, intnarg, constchar*tname);
NUMLUA_APIintnl_opmode;
#definenl_inplace(L,n) \
(lua_isnoneornil(L,(n)) ? nl_opmode : lua_toboolean(L,(n)))
#defineNUMLUA_LIBNAME "numlua"
#defineCOMPLEX_LIBNAME "complex"
#defineMATRIX_LIBNAME "matrix"
#defineFFT_LIBNAME "fft"
#defineRNG_LIBNAME "rng"
#defineSTAT_LIBNAME "stat"
#defineMATHX_LIBNAME "mathx"
#definenl_getmetatable(L,mt) (lua_pushlightuserdata(L, (mt)), \
lua_rawget(L, LUA_REGISTRYINDEX))
typedefstruct {
intld; /* leading dimension */
intstep; /* per dimension stride */
} nl_Section;
/* nl_Buffer */
typedefunion {
intbint[1];
lua_Numberbnum[1];
} buf_Number;
typedefstruct {
intsize;
intbusy; /* status */
buf_Numberdata;
} nl_Buffer;
#definenl_freebuffer(nb) ((nb)->busy = 0)
NUMLUA_APInl_Buffer*nl_getbuffer (lua_State*L, intsize);
NUMLUA_APIvoidnl_getbuffertable (lua_State*L);
NUMLUA_APIintnl_releasebuffer (lua_State*L, intthreshold);
NUMLUA_APIintluaopen_numlua_base (lua_State*L);
NUMLUA_APIintluaopen_numlua (lua_State*L);
/* complex */
typedefdoublecomplexnl_Complex;
#defineCPX(x) ((nl_Complex *) (x))
NUMLUA_APIlua_Numberclogabs (nl_Complexc);
#definecunm(c) (-(c))
#definecadd(a,b) ((a) + (b))
#definecsub(a,b) ((a) - (b))
#definecmul(a,b) ((a) * (b))
#definecdiv(a,b) ((a) / (b))
#defineceq(a,b) ((a) == (b))
#defineclt(a,b) \
(creal(a)<creal(b) || ((creal(a)==creal(b))&&(cimag(a)<cimag(b))))
#definecgt(a,b) \
(creal(a)>creal(b) || ((creal(a)==creal(b))&&(cimag(a)>cimag(b))))
NUMLUA_APInl_Complexnl_tocomplex (lua_State*L, intnarg, int*iscomplex);
NUMLUA_APInl_Complexnl_checkcomplex (lua_State*L, intnarg);
NUMLUA_APInl_Complexnl_optcomplex (lua_State*L, intnarg, nl_Complexdef);
NUMLUA_APInl_Complex*nl_newcomplex (lua_State*L);
NUMLUA_APInl_Complex*nl_pushcomplex (lua_State*L, nl_Complexc);
NUMLUA_APIintluaopen_numlua_complex (lua_State*L);
/* matrix */
typedefstruct {
intiscomplex;
intndims;
intstride; /* internal for indexing */
intsize; /* overall size (product of dims) */
nl_Section*section;
lua_Number*data;
intdim[1];
} nl_Matrix;
NUMLUA_APInl_Matrix*nl_tomatrix (lua_State*L, intnarg);
NUMLUA_APInl_Matrix*nl_checkmatrix (lua_State*L, intnarg);
NUMLUA_APInl_Matrix*nl_pushmatrix (lua_State*L, intiscomplex,
intndims, int*dim, intstride, intsize, lua_Number*data);
NUMLUA_APIintnl_msshift (nl_Matrix*m, inteo);
#definenl_mshift(m,i) \
(((m)->section) ? nl_msshift((m),(i)) : ((i) * (m)->stride))
intluaopen_numlua_lmatrix (lua_State*L);
/* rng */
NUMLUA_APIintluaopen_numlua_rng (lua_State*L);
/* fft */
NUMLUA_APIintluaopen_numlua_fft (lua_State*L);
/* stat */
NUMLUA_APIintluaopen_numlua_stat (lua_State*L);
/* C99 mathx */
NUMLUA_APIlua_Numbernl_lse (lua_Numberw1, lua_Numberw2);
NUMLUA_APIintluaopen_numlua_mathx (lua_State*L);
/* BLAS level 1 */
#defineDSWAP dswap_
#defineZSWAP zswap_
#defineDCOPY dcopy_
#defineZCOPY zcopy_
#defineDSCAL dscal_
#defineZSCAL zscal_
#defineZDSCAL zdscal_
#defineDAXPY daxpy_
#defineZAXPY zaxpy_
#defineDDOT ddot_
#defineZDOTC zdotc_
#defineZDOTU zdotu_
#defineDNRM2 dnrm2_
#defineDZNRM2 dznrm2_
#defineDASUM dasum_
#defineDZASUM dzasum_
#defineIDAMAX idamax_
#defineIZAMAX izamax_
/* BLAS level 2 */
#defineDTRMV dtrmv_
#defineDTRSV dtrsv_
#defineZTRMV ztrmv_
#defineZTRSV ztrsv_
#defineZHER zher_
#defineDSYR dsyr_
#defineDGER dger_
#defineZGERC zgerc_
#defineDGEMV dgemv_
#defineZGEMV zgemv_
/* BLAS level 3 */
#defineDTRMM dtrmm_
#defineDTRSM dtrsm_
#defineZTRMM ztrmm_
#defineZTRSM ztrsm_
#defineZHERK zherk_
#defineDSYRK dsyrk_
#defineDGEMM dgemm_
#defineZGEMM zgemm_
/* LAPACK */
/* chol */
#defineDPOTRF dpotrf_
#defineZPOTRF zpotrf_
/* lu */
#defineDGETRF dgetrf_
#defineZGETRF zgetrf_
/* inv */
#defineDTRTRI dtrtri_
#defineZTRTRI ztrtri_
#defineDPOTRI dpotri_
#defineZPOTRI zpotri_
#defineDGETRI dgetri_
#defineZGETRI zgetri_
/* rcond */
#defineDTRCON dtrcon_
#defineZTRCON ztrcon_
#defineDPOCON dpocon_
#defineZPOCON zpocon_
#defineDGECON dgecon_
#defineZGECON zgecon_
/* svd */
#defineZGESVD zgesvd_
#defineDGESVD dgesvd_
/* qr */
#defineZGEQRF zgeqrf_
#defineDGEQRF dgeqrf_
#defineZGEQP3 zgeqp3_
#defineDGEQP3 dgeqp3_
#defineZUNGQR zungqr_
#defineDORGQR dorgqr_
/* eig */
#defineZHEEV zheev_
#defineDSYEV dsyev_
#defineZGEEV zgeev_
#defineDGEEV dgeev_
/* balance */
#defineZGEBAL zgebal_
#defineDGEBAL dgebal_
/* ls */
#defineZGELSY zgelsy_
#defineDGELSY dgelsy_
#defineZGELSS zgelss_
#defineDGELSS dgelss_
/* {=================================================================
*
* Copyright (c) 2005 Luis Carvalho
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* ==================================================================} */
#endif