From 1f4c792072b0f53d084abe7601ef5e371b4a1019 Mon Sep 17 00:00:00 2001 From: marcandre Date: Sun, 13 Jan 2013 22:13:12 +0000 Subject: * lib/matrix/lup_decomposition: Fix bugs with LUP Decomposition of rectangular matrices. [rubyspec:ba849801a85] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38807 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ lib/matrix/lup_decomposition.rb | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 28699e7004..f3cf4d3c5e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Jan 14 07:12:52 2013 Marc-Andre Lafortune + + * lib/matrix/lup_decomposition: Fix bugs with LUP Decomposition of + rectangular matrices. [rubyspec:ba849801a85] + Mon Jan 14 06:46:53 2013 NARUSE, Yui * regparse.c (add_ctype_to_cc): don't check dup warn on adding diff --git a/lib/matrix/lup_decomposition.rb b/lib/matrix/lup_decomposition.rb index fa8a1448de..30f3276253 100644 --- a/lib/matrix/lup_decomposition.rb +++ b/lib/matrix/lup_decomposition.rb @@ -19,7 +19,7 @@ class Matrix include Matrix::ConversionHelper def l - Matrix.build(@row_count, @column_count) do |i, j| + Matrix.build(@row_count, [@column_count, @row_count].min) do |i, j| if (i > j) @lu[i][j] elsif (i == j) @@ -33,7 +33,7 @@ class Matrix # Returns the upper triangular factor +U+ def u - Matrix.build(@column_count, @column_count) do |i, j| + Matrix.build([@column_count, @row_count].min, @column_count) do |i, j| if (i <= j) @lu[i][j] else @@ -45,9 +45,9 @@ class Matrix # Returns the permutation matrix +P+ def p - rows = Array.new(@row_count){Array.new(@column_count, 0)} + rows = Array.new(@row_count){Array.new(@row_count, 0)} @pivots.each_with_index{|p, i| rows[i][p] = 1} - Matrix.send :new, rows, @column_count + Matrix.send :new, rows, @row_count end # Returns +L+, +U+, +P+ in an array -- cgit v1.2.3