Removed the conditionals to compile without complex LNUM extension. - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
diff options
context:
space:
mode:
authorfrancesco-ST <francesco.abbate@st.com>2011年02月01日 13:16:26 +0100
committerfrancesco-ST <francesco.abbate@st.com>2011年02月01日 13:16:26 +0100
commitef33d2e7047f2092d3c99d969b465201a831b6e6 (patch)
treef07055dcfae5988cec5566b5d0289b1f58a38d0a
parentbd2c1b886cfe9b69a2f8491e700d00639303f798 (diff)
downloadgsl-shell-ef33d2e7047f2092d3c99d969b465201a831b6e6.tar.gz
Removed the conditionals to compile without complex LNUM extension.
The conditionals are no more needed because now the complex number are implemented using an unmodified Lua VM implementation.
Diffstat
-rw-r--r--Makefile 10
-rw-r--r--eigen-systems.c 10
-rw-r--r--igsl.lua 32
-rw-r--r--lua-gsl.c 9
-rw-r--r--makeconfig 1
-rw-r--r--module/draw.lua 75
-rw-r--r--module/example/plot.lua 76
-rw-r--r--module/igsl.lua 277
-rw-r--r--sf_gener.c 4
-rw-r--r--sf_implement.h 2
10 files changed, 14 insertions, 482 deletions
diff --git a/Makefile b/Makefile
index 47be97b5..80474712 100644
--- a/Makefile
+++ b/Makefile
@@ -62,8 +62,8 @@ C_SRC_FILES = gs-types.c lcomplex.c matrix.c matrix_arith.c nlinfit_helper.c \
nlinfit.c lua-utils.c linalg.c \
integ.c ode_solver.c ode.c random.c randist.c \
pdf.c cdf.c sf.c fmultimin.c gradcheck.c fdfmultimin.c \
- multimin.c eigen-systems.c mlinear.c bspline.c interp.c \
- lua-gsl.c
+ multimin.c eigen-systems.c mlinear.c bspline.c interp.c \
+ cmatrix.c cnlinfit.c code.c fft.c lua-gsl.c
LUA_BASE_DIRS =
LUA_BASE_FILES = igsl.lua base.lua integ.lua csv.lua
@@ -96,12 +96,6 @@ ifeq ($(strip $(DISABLE_GAMMA_CORR)), yes)
SUBDIRS_DEFS += -DDISABLE_GAMMA_CORR
endif
-ifeq ($(strip $(ENABLE_COMPLEX)), yes)
- C_SRC_FILES += cmatrix.c cnlinfit.c code.c fft.c
- DEFS += -DLNUM_COMPLEX
- SUBDIRS_DEFS += -DLNUM_COMPLEX
-endif
-
COMPILE = $(CC) $(CFLAGS) $(LUA_CFLAGS) $(DEFS) $(INCLUDES)
CXXCOMPILE = $(CXX) $(CXXFLAGS) -c
diff --git a/eigen-systems.c b/eigen-systems.c
index ff1a0fa4..f7e798d5 100644
--- a/eigen-systems.c
+++ b/eigen-systems.c
@@ -43,22 +43,18 @@ struct eigen_cache {
static int eigen_symm (lua_State *L);
static int eigen_symmv (lua_State *L);
-#ifdef LNUM_COMPLEX
static int eigen_herm (lua_State *L);
static int eigen_hermv (lua_State *L);
static int eigen_nonsymm (lua_State *L);
static int eigen_nonsymmv (lua_State *L);
static int schur_decomp (lua_State *L);
-#endif
static int eigen_cache_free (lua_State *L);
static void eigen_push_cache (lua_State *L);
static struct eigen_symm_cache * eigen_cache_symm_set (lua_State *L, size_t n);
-#ifdef LNUM_COMPLEX
static struct eigen_herm_cache * eigen_cache_herm_set (lua_State *L, size_t n);
static struct eigen_nonsymm_cache * eigen_cache_nonsymm_set (lua_State *L, size_t n);
-#endif
static const struct luaL_Reg eigen_cache_methods[] = {
{"__gc", eigen_cache_free},
@@ -68,13 +64,11 @@ static const struct luaL_Reg eigen_cache_methods[] = {
static const struct luaL_Reg eigen_functions[] = {
{"eigs", eigen_symm},
{"eigsv", eigen_symmv},
-#ifdef LNUM_COMPLEX
{"eigh", eigen_herm},
{"eighv", eigen_hermv},
{"eigns", eigen_nonsymm},
{"eignsv", eigen_nonsymmv},
{"schur", schur_decomp},
-#endif
{NULL, NULL}
};
@@ -167,7 +161,6 @@ eigen_cache_symm_set (lua_State *L, size_t n)
return cache->symm;
}
-#ifdef LNUM_COMPLEX
struct eigen_herm_cache *
eigen_cache_herm_set (lua_State *L, size_t n)
{
@@ -217,7 +210,6 @@ eigen_cache_nonsymm_set (lua_State *L, size_t n)
return cache->nonsymm;
}
-#endif
int
eigen_symm_raw (lua_State *L, int compute_evecs)
@@ -272,7 +264,6 @@ eigen_symmv (lua_State *L)
return eigen_symm_raw (L, 1);
}
-#ifdef LNUM_COMPLEX
static int
eigen_herm_raw (lua_State *L, int compute_evecs)
{
@@ -427,7 +418,6 @@ schur_decomp (lua_State *L)
return 2;
}
-#endif
void
eigen_register (lua_State *L)
diff --git a/igsl.lua b/igsl.lua
index 29098078..0e0d421c 100644
--- a/igsl.lua
+++ b/igsl.lua
@@ -18,12 +18,6 @@
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
--
-if not have_complex then
- conj = |x| x
- real = conj
- imag = |x| 0
-end
-
local cat = table.concat
local insert = table.insert
local fmt = string.format
@@ -161,9 +155,7 @@ end
local function add_matrix_method(s, m)
Matrix[s] = m
- if have_complex then
- cMatrix[s] = m
- end
+ cMatrix[s] = m
end
function ode_iter(s, t0, y0, t1, h, tstep)
@@ -192,23 +184,21 @@ local function hc_print(hc)
return cat(hc_reduce(hc, f, {}), '\n')
end
-if have_complex then
- FFT_hc_mixed_radix.__tostring = hc_print
- FFT_hc_radix2.__tostring = hc_print
-end
+FFT_hc_mixed_radix.__tostring = hc_print
+FFT_hc_radix2.__tostring = hc_print
ODE.iter = ode_iter
-if have_complex then cODE.iter = ode_iter end
+cODE.iter = ode_iter
local function add_matrix_meta_method(key, method)
- local m = new(1,1)
- local mt = getmetatable(m)
+ local m, mt
+ m = new(1,1)
+ mt = getmetatable(m)
+ mt[key] = method
+
+ m = cnew(1,1)
+ mt = getmetatable(m)
mt[key] = method
- if have_complex then
- m = cnew(1,1)
- mt = getmetatable(m)
- mt[key] = method
- end
end
add_matrix_meta_method('__tostring', matrix_to_string)
diff --git a/lua-gsl.c b/lua-gsl.c
index 1e676eb0..073216f3 100644
--- a/lua-gsl.c
+++ b/lua-gsl.c
@@ -100,18 +100,11 @@ luaopen_gsl (lua_State *L)
plot_register (L);
#endif
-#ifdef LNUM_COMPLEX
- lua_pushboolean (L, 1);
- lua_setfield (L, -2, "have_complex");
-
fft_register (L);
matrix_complex_register (L);
ode_complex_register (L);
solver_complex_register (L);
-#else
- lua_pushboolean (L, 0);
- lua_setfield (L, -2, "have_complex");
-#endif
+
lua_pop (L, 1);
return 1;
diff --git a/makeconfig b/makeconfig
index 450ecf64..0a732466 100644
--- a/makeconfig
+++ b/makeconfig
@@ -1,5 +1,4 @@
-ENABLE_COMPLEX = yes
ENABLE_AGG_PLOT = yes
# set this to "yes" if you want to disable gamma correction
diff --git a/module/draw.lua b/module/draw.lua
deleted file mode 100644
index 5ac83be0..00000000
--- a/module/draw.lua
+++ /dev/null
@@ -1,75 +0,0 @@
-
-require 'module/igsl'
-
-draw = {}
-
-function draw.ipath(f)
- local ln = gsl.path()
- ln:move_to(f())
- for x, y in f do
- ln:line_to(x, y)
- end
- return ln
-end
-
-function draw.ipathp(f)
- local ln = gsl.path()
- local success = false
- local x, y
- repeat
- local cont = success
- success, x, y = pcall(f)
- if success and x and y then
- if cont then
- ln:line_to(x, y)
- else
- ln:move_to(x, y)
- end
- end
- until success and (not x or not y)
- return ln
-end
-
-function draw.fxline(f, xi, xs, n)
- n = n and n or 512
- return draw.ipath(gsl.sample(f, xi, xs, n))
-end
-
-function draw.fxplot(f, xi, xs, color, n)
- n = n and n or 512
- color = color and color or 'red'
- local p = gsl.plot()
- p:add_line(draw.ipathp(gsl.sample(f, xi, xs, n)), color)
- p:show()
- return p
-end
-
-local function add_bar(p, lx, rx, y)
- p:move_to(lx, 0)
- p:line_to(rx, 0)
- p:line_to(rx, y)
- p:line_to(lx, y)
- p:close()
-end
-
-function draw.ibars(f)
- local b = gsl.path()
- local lx, ly = f()
- local first = true
- for rx, ry in f do
- local dx = (rx-lx)/2
- if first then add_bar(b, lx-dx, lx+dx, ly); first = false end
- add_bar(b, lx+dx, rx+dx, ry)
- lx, ly = rx, ry
- end
- return b
-end
-
-local bcolors = {'red', 'green', 'blue', 'cyan', 'magenta', 'yellow'}
-local mcolors = {'dark', '', 'light'}
-
-function draw.rainbow(n)
- local p = #bcolors
- local q = floor(n/p) % #mcolors
- return mcolors[q+1] .. bcolors[n % p + 1]
-end
diff --git a/module/example/plot.lua b/module/example/plot.lua
deleted file mode 100644
index 46a88cca..00000000
--- a/module/example/plot.lua
+++ /dev/null
@@ -1,76 +0,0 @@
-
-local function fline(f, xi, xs, color, n)
- color = color and color or 'red'
- n = n and n or 256
- local ln = gsl.line(color)
- ln:move_to(xi, f(xi))
- for x, y in gsl.sample(f, xi, xs, n) do
- ln:line_to(x, y)
- end
- return ln
-end
-
-function demo1()
- local f = function(t) return math.exp(-0.3*t) * math.sin(2*math.pi*t) end
- local p = gsl.cplot()
- p:add( fline(f, 0, 15, 'red', 512) )
- return p
-end
-
-function demo2()
- local f = function(x) return 1/math.sqrt(2*math.pi) * math.exp(-x^2/2) end
- local p = gsl.cplot()
- local b = gsl.poly('darkgreen', 'black')
- for x, y in gsl.sample(f, -3, 3, 15) do
- local hw = 3/15
- b:move_to(x-hw, 0)
- b:line_to(x+hw, 0)
- b:line_to(x+hw, y)
- b:line_to(x-hw, y)
- b:close()
- end
- p:add(b)
- p:add( fline(f, -4, 4) )
- return p
-end
-
-function vonkoch(n)
- local sx = {2, 1, -1, -2, -1, 1}
- local sy = {0, 1, 1, 0, -1, -1}
- local w = {}
- for k=1,n+1 do w[#w+1] = 0 end
- local sh = {1, -2, 1}
- local a = 0
- local x, y = 0, 0
-
- local s = 1 / (3^n)
- for k=1, 6 do
- sx[k] = s * 0.5 * sx[k]
- sy[k] = s * math.sqrt(3)/2 * sy[k]
- end
-
- return function()
- if w[n+1] == 0 then
- x, y = x + sx[a+1], y + sy[a+1]
- for k=1,n+1 do
- w[k] = (w[k] + 1) % 4
- if w[k] ~= 0 then
- a = (a + sh[w[k]]) % 6
- break
- end
- end
- return x, y
- end
- end
-end
-
-function demo3()
- local p = gsl.cplot()
- local ln = gsl.line('blue')
- ln:move_to(0, 0)
- for x, y in vonkoch(4) do
- ln:line_to(x, y)
- end
- p:add(ln)
- return p
-end
diff --git a/module/igsl.lua b/module/igsl.lua
deleted file mode 100644
index d6b94b87..00000000
--- a/module/igsl.lua
+++ /dev/null
@@ -1,277 +0,0 @@
-
- -- igsl.lua
- --
- -- Copyright (C) 2009 Francesco Abbate
- --
- -- This program is free software; you can redistribute it and/or modify
- -- it under the terms of the GNU General Public License as published by
- -- the Free Software Foundation; either version 3 of the License, or (at
- -- your option) any later version.
- --
- -- This program is distributed in the hope that it will be useful, but
- -- WITHOUT ANY WARRANTY; without even the implied warranty of
- -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- -- General Public License for more details.
- --
- -- You should have received a copy of the GNU General Public License
- -- along with this program; if not, write to the Free Software
- -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- --
-
-require 'gsl'
-
-gsl.real_env = _G
-setfenv(1, gsl)
-
-local table = real_env.table
-local math = real_env.math
-local string = real_env.string
-local type = real_env.type
-local ipairs = real_env.ipairs
-
-real_env = nil
-
-if not have_complex then
- math.conj = function(x) return x end
- math.real = math.conj
- math.imag = function(x) return 0 end
-end
-
-local cat = table.concat
-local fmt = string.format
-local function push(ls, e)
- ls[#ls+1] = e
- return ls
-end
-
-local function tos(t, maxdepth)
- if type(t) == 'table' then
- if maxdepth <= 0 then return '<table>' end
- local ls = {}
- for k, v in pairs(t) do
- if k ~= 'tag' then
- if type(k) ~= 'number' then
- push(ls, k .. '= ' .. tos(v, maxdepth-1))
- else
- push(ls, tos(v, maxdepth-1))
- end
- end
- end
- return '{' .. cat(ls, ', ') .. '}'
- elseif type(t) == 'function' then
- return '<function>'
- else
- return tostring(t)
- end
-end
-
-local function myprint(...)
- for i, v in ipairs(arg) do
- if i > 1 then io.write(', ') end
- io.write(tos(v, 2))
- end
- io.write('\n')
-end
-
-print = myprint
-
-function matrix_f_set(m, f)
- local r, c = m:dims()
- for i = 1, r do
- for j = 1, c do
- local z = f(i, j)
- m:set(i, j, z)
- end
- end
- return m
-end
-
-function matrix_reduce(m, f, accu)
- local r, c = m:dims()
- for i = 1, r do
- for j = 1, c do
- accu = f(accu, m:get(i, j))
- end
- end
- return accu
-end
-
-local function tostring_eps(z, eps)
- local a, b = math.real(z), math.imag(z)
- local f = function(x) return fmt('%g', x) end
- local s = math.abs(a) > eps and f(a) or ''
- if b > eps then
- local sign = (s == '' and '' or '+')
- s = s .. fmt('%s%si', sign, f(b))
- elseif b < -eps then
- s = s .. fmt('-%si', f(-b))
- end
- return s == '' and '0' or s
-end
-
-local function matrix_from_table(ctor, t)
- return matrix_f_set(ctor(#t, #t[1]), function(i,j) return t[i][j] end)
-end
-
-local function vector_from_table(ctor, t)
- local v = ctor (#t, 1)
- for i, x in ipairs(t) do v:set(i,1, x) end
- return v
-end
-
-function vector(t)
- return vector_from_table(new, t)
-end
-
-function cvector(t)
- return vector_from_table(cnew, t)
-end
-
-function matrix(t)
- return matrix_from_table(new, t)
-end
-
-function cmatrix(t)
- return matrix_from_table(cnew, t)
-end
-
-function matrix_print(m)
- local eps = m:norm() * 1e-8
- local fwidth = function(w, val)
- local ln = # tostring_eps(val, eps)
- return (ln > w and ln or w)
- end
- local width = matrix_reduce(m, fwidth, 0)
- local pad = function(s) return string.rep(' ', width - #s) .. s end
- local r, c = m:dims()
- local lines = {}
- for i=1,r do
- local ln = {}
- for j=1,c do
- push(ln, pad(tostring_eps(m:get(i,j), eps)))
- end
- push(lines, '[ ' .. cat(ln, ' ') .. ' ]')
- end
- return cat(lines, '\n')
-end
-
-function t(m)
- local r, c = m:dims()
- return new(c, r, function(i,j) return m:get(j,i) end)
-end
-
-function h(m)
- local r, c = m:dims()
- return cnew(c, r, function(i,j) return math.conj(m:get(j,i)) end)
-end
-
-function diag(v)
- local n = v:dims()
- return new(n, n, function(i,j) return i == j and v:get(i,1) or 0 end)
-end
-
-function unit(n)
- return new(n, n, function(i,j) return i == j and 1 or 0 end)
-end
-
-function matrix_norm(m)
- local sq = matrix_reduce(m, function(p, z) return p + z*math.conj(z) end, 0)
- return math.sqrt(sq)
-end
-
-function matrix_columns (m, cstart, cnb)
- local r = m:dims()
- return m:slice(1, cstart, r, cnb)
-end
-
-function matrix_row_print(m)
- local eps = m:norm() * 1e-8
- local f = function(p, z) return push(p, tostring_eps(z, eps)) end
- return cat(matrix_reduce(m, f, {}), ', ')
-end
-
-function set(d, s)
- matrix_f_set(d, function(i,j) return s:get(i,j) end)
-end
-
-function null(m)
- matrix_f_set(m, function(i,j) return 0 end)
-end
-
-local function add_matrix_method(s, m)
- Matrix[s] = m
- if have_complex then
- cMatrix[s] = m
- end
-end
-
-function ode_iter(s, t0, y0, t1, tstep)
- s:set(t0, y0)
- return function()
- local t, y = s.t, s.y
- if t < t1 then
- s:evolve(t1, tstep)
- return t, y
- end
- end
-end
-
-function sample(f, xi, xs, n)
- local k = 0
- local cf = (xs-xi)/n
- return function()
- if k <= n then
- local x = xi + k*cf
- k = k+1
- return x, f(x)
- end
- end
-end
-
-function irow(m, f)
- local r, c = m:dims()
- local i = 0
- return function()
- i = i+1
- if i <= r then return f(m, i) end
- end
-end
-
-function iter(f, i1, i2)
- local i = i1
- return function()
- if i <= i2 then
- i = i+1
- return f(i-1)
- end
- end
-end
-
-local function hc_reduce(hc, f, accu)
- local n = hc.length
- for i=0, n do accu = f(accu, hc:get(i)) end
- return accu
-end
-
-local function hc_print(hc)
- local ccadd = function(p,z) return p + z*math.conj(z) end
- local eps = 1e-8 * hc_reduce(hc, ccadd, 0)
- local function f(p,z)
- return push(p, fmt('%6i: %s', #p, tostring_eps(z, eps)))
- end
- return cat(hc_reduce(hc, f, {}), '\n')
-end
-
-if have_complex then
- FFT_hc_mixed_radix.__tostring = hc_print
- FFT_hc_radix2.__tostring = hc_print
-end
-
-ODE.iter = ode_iter
-if have_complex then cODE.iter = ode_iter end
-
-add_matrix_method('rowiter', matrix_rowiter)
-add_matrix_method('__tostring', matrix_print)
-add_matrix_method('norm', matrix_norm)
-add_matrix_method('columns', matrix_columns)
-add_matrix_method('row_print', matrix_row_print)
diff --git a/sf_gener.c b/sf_gener.c
index 57c9a173..3438c5b3 100644
--- a/sf_gener.c
+++ b/sf_gener.c
@@ -22,9 +22,7 @@ GSH_SF_CUSTOM(debye)
GSH_SF_CUSTOM(fermi_dirac)
GSH_SF(D, dilog)
-#ifdef LNUM_COMPLEX
GSH_SF_CUSTOM(cdilog)
-#endif
GSH_SF(D, erf)
@@ -58,8 +56,6 @@ GSH_SF_COMP(DD, hyperg, 0F1)
GSH_SF_CUSTOM(hyperg1F1)
GSH_SF_CUSTOM(hypergU)
GSH_SF_COMP(DDDD, hyperg, 2F1)
-#ifdef LNUM_COMPLEX
GSH_SF_CUSTOM(hyperg2F1conj)
-#endif
GSH_SF_CUSTOM(zeta)
diff --git a/sf_implement.h b/sf_implement.h
index b40fcf9a..65030f06 100644
--- a/sf_implement.h
+++ b/sf_implement.h
@@ -518,7 +518,6 @@ int GSH_LUA_NAME(legendreQ) (lua_State *L)
return push_gsl_result (L, &res);
}
-#ifdef LNUM_COMPLEX
int GSH_LUA_NAME(cdilog) (lua_State *L)
{
Complex z = luaL_checkcomplex (L, 1);
@@ -535,4 +534,3 @@ int GSH_LUA_NAME(cdilog) (lua_State *L)
lua_pushcomplex (L, rr.val + I * ri.val);
return 1;
}
-#endif
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月16日 09:54:20 +0000

AltStyle によって変換されたページ (->オリジナル) /