gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/matrix.lua
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2012年11月12日 23:51:18 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2012年11月12日 23:51:18 +0100
commit70ee4afa111c6f7456f102b75b314f0f83fd010e (patch)
tree8dea547262fd7e264052ca858a00ac6fadf334c4 /matrix.lua
parentca4b11a05451867f6ec2df647c61044df3b69b50 (diff)
downloadgsl-shell-70ee4afa111c6f7456f102b75b314f0f83fd010e.tar.gz
Change matrix.diag to accept a table instead of a vector
Diffstat (limited to 'matrix.lua')
-rw-r--r--matrix.lua 24
1 files changed, 8 insertions, 16 deletions
diff --git a/matrix.lua b/matrix.lua
index cbf24590..4e60391b 100644
--- a/matrix.lua
+++ b/matrix.lua
@@ -580,12 +580,9 @@ local complex_mt = {
ffi.metatype(gsl_complex, complex_mt)
local function matrix_new_unit(n)
- local m = matrix_alloc(n, n)
- for i=0, n-1 do
- for j=0, n-1 do
- m.data[i*n+j] = (i == j and 1 or 0)
- end
- end
+ local m = matrix.alloc(n, n)
+ for k = 0, n*n - 1 do m.data[k] = 0 end
+ for k = 0, n-1 do m.data[k*(n+1)] = 1 end
return m
end
@@ -940,16 +937,11 @@ function matrix.svd(a)
return u, s, v
end
-matrix.diag = function(d)
- local n = #d
- local m = d.alloc(n, n)
- local mset, dget = m.set, d.get
- for i=1, n do
- for j= 1, n do
- local x = (i ~= j and 0 or dget(d, i, 1))
- mset(m, i, j, x)
- end
- end
+matrix.diag = function(t)
+ local n = #t
+ local m = matrix.alloc(n, n)
+ for k = 0, n*n - 1 do m.data[k] = 0 end
+ for k = 0, n-1 do m.data[k*(n+1)] = t[k+1] end
return m
end
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月15日 08:38:53 +0000

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