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

ruby-changes:60956

From: Marc-Andre <ko1@a...>
Date: Fri, 1 May 2020 16:31:20 +0900 (JST)
Subject: [ruby-changes:60956] 9b5675b325 (master): [ruby/matrix] Add Matrix#adjoint [#14]

https://git.ruby-lang.org/ruby.git/commit/?id=9b5675b325

From 9b5675b325c9d4533e4f3db080cd2aa019068aad Mon Sep 17 00:00:00 2001
From: Marc-Andre Lafortune <github@m...>
Date: Thu, 30 Apr 2020 18:04:30 -0400
Subject: [ruby/matrix] Add Matrix#adjoint [#14]

Patch adapted from Alessandro Minali

diff --git a/lib/matrix.rb b/lib/matrix.rb
index 75b5da2..336a928 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -1533,6 +1533,17 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L1533
   alias_method :conj, :conjugate
 
   #
+  # Returns the adjoint of the matrix.
+  #
+  #   Matrix[ [i,1],[2,-i] ].adjoint
+  #   #  => -i 2
+  #   #      1 i
+  #
+  def adjoint
+    conjugate.transpose
+  end
+
+  #
   # Returns the imaginary part of the matrix.
   #   Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]
   #   #  => 1+2i  i  0
diff --git a/test/matrix/test_matrix.rb b/test/matrix/test_matrix.rb
index f963b2d..b134bfb 100644
--- a/test/matrix/test_matrix.rb
+++ b/test/matrix/test_matrix.rb
@@ -807,4 +807,9 @@ class TestMatrix < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/matrix/test_matrix.rb#L807
     assert_equal false, @a3.orthogonal?
     assert_raise(Matrix::ErrDimensionMismatch) { @m1.orthogonal? }
   end
+
+  def test_adjoint
+    assert_equal(Matrix[[(1-2i), 1], [(0-1i), 2], [0, 3]], @c1.adjoint)
+    assert_equal(Matrix.empty(0,2), @e1.adjoint)
+  end
 end
-- 
cgit v0.10.2


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

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