author | Francesco Abbate <francesco.bbt@gmail.com> | 2012年04月09日 21:39:22 +0200 |
---|---|---|
committer | Francesco Abbate <francesco.bbt@gmail.com> | 2012年04月09日 21:39:22 +0200 |
commit | 0d681c0fe2aa68b05e1a0266c86a82c1055a5f5c (patch) | |
tree | 624f4ab8cdc7a23b109c807dd434bbb516f05934 | |
parent | 062a149787504d97ab756521dedad16a28035080 (diff) | |
download | gsl-shell-0d681c0fe2aa68b05e1a0266c86a82c1055a5f5c.tar.gz |
-rw-r--r-- | matrix.lua | 18 |
diff --git a/matrix.lua b/matrix.lua index 956a8a50..ac570eba 100644 --- a/matrix.lua +++ b/matrix.lua @@ -1,4 +1,5 @@ + local ffi = require 'ffi' local gsl = require 'gsl' @@ -13,6 +14,7 @@ local gsl_matrix_complex = ffi.typeof('gsl_matrix_complex') local gsl_complex = ffi.typeof('complex') local gsl_check = require 'gsl-check' +local tonumber = tonumber local function check_real(x) if type(x) ~= 'number' then error('expected real number', 3) end @@ -34,7 +36,7 @@ end local function cartesian(x) if is_real(x) then - return x, 0 + return x, 0 else return x[0], x[1] end @@ -99,14 +101,14 @@ local function matrix_cnew(n1, n2, f) end local function matrix_free(m) - if m.owner then + if m.owner then local b = m.block b.ref_count = b.ref_count - 1 if b.ref_count == 0 then ffi.C.free(b.data) ffi.C.free(b) end - end + end end local function matrix_dim(m) @@ -213,13 +215,13 @@ local function recttostr(x, y, eps) if x_sub and y_sub then fmt, x_sub, y_sub = '%.0f', x==0, y==0 end - + if not x_sub then local sign = x+eps < 0 and '-' or '' local ax = abs(x) if y_sub then return format('%s'..fmt, sign, ax) - else + else return format('%s'..fmt..'%s', sign, ax, itostr(y, eps, fmt, true)) end else @@ -395,7 +397,7 @@ local function real_get(x) return x, 0 end local function complex_get(z) return z[0], z[1] end local function mat_real_get(m,i,j) return m.data[i*m.tda+j], 0 end -local function mat_complex_get(m,i,j) +local function mat_complex_get(m,i,j) local idx = 2*i*m.tda+2*j return m.data[idx], m.data[idx+1] end @@ -568,7 +570,7 @@ local complex_mt = { return (ar == br) and (ai == bi) end, - __pow = function(z,n) + __pow = function(z,n) if is_real(n) then return gsl.gsl_complex_pow_real (z, n) else @@ -705,7 +707,7 @@ end local matrix_mt = { __gc = matrix_free, - + __add = generic_add, __sub = generic_sub, __mul = generic_mul, |