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

ruby-changes:60954

From: Marc-Andre <ko1@a...>
Date: Fri, 1 May 2020 16:31:20 +0900 (JST)
Subject: [ruby-changes:60954] 3cb038cc7a (master): [ruby/matrix] Fix Matrix#orthogonal?

https://git.ruby-lang.org/ruby.git/commit/?id=3cb038cc7a

From 3cb038cc7a9b1e01685a7e8a513e7ac7fb56b112 Mon Sep 17 00:00:00 2001
From: Marc-Andre Lafortune <github@m...>
Date: Thu, 30 Apr 2020 18:00:47 -0400
Subject: [ruby/matrix] Fix Matrix#orthogonal?


diff --git a/lib/matrix.rb b/lib/matrix.rb
index 9d66503..7d35b61 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -890,11 +890,12 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L890
   #
   def orthogonal?
     raise ErrDimensionMismatch unless square?
-    rows.each_with_index do |row, i|
-      column_count.times do |j|
+
+    rows.each_with_index do |row_i, i|
+      rows.each_with_index do |row_j, j|
         s = 0
         row_count.times do |k|
-          s += row[k] * rows[k][j]
+          s += row_i[k] * row_j[k]
         end
         return false unless s == (i == j ? 1 : 0)
       end
diff --git a/test/matrix/test_matrix.rb b/test/matrix/test_matrix.rb
index 9206678..f963b2d 100644
--- a/test/matrix/test_matrix.rb
+++ b/test/matrix/test_matrix.rb
@@ -800,4 +800,11 @@ class TestMatrix < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/matrix/test_matrix.rb#L800
     assert_equal false, @a3.unitary?
     assert_raise(Matrix::ErrDimensionMismatch) { @m1.unitary? }
   end
+
+  def test_orthogonal
+    assert_equal true, @rot.orthogonal?
+    assert_equal false, ((0+1i) * @rot).orthogonal?
+    assert_equal false, @a3.orthogonal?
+    assert_raise(Matrix::ErrDimensionMismatch) { @m1.orthogonal? }
+  end
 end
-- 
cgit v0.10.2


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

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