From ec46ebcfdeb42b34d01709f31f6f0b4326a0169d Mon Sep 17 00:00:00 2001 From: Pablo Mortari Schiavini <32298088+pabloschiavini@users.noreply.github.com> Date: Fri, 9 Nov 2018 16:58:59 +0100 Subject: [PATCH] Variable vector initialization If `matrix:new` detects a vector, then it converts to a Nx1 matrix, instead of a 3x1 matrix. --- lua/matrix.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lua/matrix.lua b/lua/matrix.lua index 83f7d57..ef34fd6 100644 --- a/lua/matrix.lua +++ b/lua/matrix.lua @@ -134,7 +134,11 @@ function matrix:new( rows, columns, value ) if type( rows ) == "table" then -- check for vector if type(rows[1]) ~= "table" then -- expect a vector - return setmetatable( {{rows[1]},{rows[2]},{rows[3]}},matrix_meta ) + local vector = {} + for i=1,#rows do + vector[i] = { rows[i] } + end + return setmetatable( vector,matrix_meta ) end return setmetatable( rows,matrix_meta ) end