[前][次][番号順一覧][スレッド一覧]

ruby-changes:33445

From: marcandre <ko1@a...>
Date: Mon, 7 Apr 2014 02:45:11 +0900 (JST)
Subject: [ruby-changes:33445] marcandRe: r45524 (trunk): * lib/matrix: Handle empty diagonal matrix case [fix GH-576]

marcandre	2014-04-07 02:45:07 +0900 (Mon, 07 Apr 2014)

  New Revision: 45524

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45524

  Log:
    * lib/matrix: Handle empty diagonal matrix case [fix GH-576]
      Patch by gogotanaka

  Modified files:
    trunk/lib/matrix.rb
    trunk/test/matrix/test_matrix.rb
Index: lib/matrix.rb
===================================================================
--- lib/matrix.rb	(revision 45523)
+++ lib/matrix.rb	(revision 45524)
@@ -204,6 +204,7 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L204
   #
   def Matrix.diagonal(*values)
     size = values.size
+    return Matrix.empty if size == 0
     rows = Array.new(size) {|j|
       row = Array.new(size, 0)
       row[j] = values[j]
Index: test/matrix/test_matrix.rb
===================================================================
--- test/matrix/test_matrix.rb	(revision 45523)
+++ test/matrix/test_matrix.rb	(revision 45524)
@@ -179,6 +179,7 @@ class TestMatrix < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/matrix/test_matrix.rb#L179
   end
 
   def test_diagonal
+    assert_equal(Matrix.empty(0, 0), Matrix.diagonal( ))
     assert_equal(Matrix[[3,0,0],[0,2,0],[0,0,1]], Matrix.diagonal(3, 2, 1))
     assert_equal(Matrix[[4,0,0,0],[0,3,0,0],[0,0,2,0],[0,0,0,1]], Matrix.diagonal(4, 3, 2, 1))
   end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]