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

ruby-changes:15275

From: marcandre <ko1@a...>
Date: Fri, 2 Apr 2010 03:05:58 +0900 (JST)
Subject: [ruby-changes:15275] Ruby:r27159 (trunk): * lib/matrix.rb: New Complex instance methods:

marcandre	2010-04-02 03:05:11 +0900 (Fri, 02 Apr 2010)

  New Revision: 27159

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

  Log:
    * lib/matrix.rb: New Complex instance methods:
        conjugate, conj, imaginary, imag, real, real?, rectangular, rect
        [ruby-core:26285]

  Modified files:
    trunk/ChangeLog
    trunk/lib/matrix.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 27158)
+++ ChangeLog	(revision 27159)
@@ -1,3 +1,16 @@
+Fri Apr  2 02:56:56 2010  Marc-Andre Lafortune  <ruby-core@m...>
+
+	* lib/matrix.rb: : New instance methods:
+      empty? [ruby-core:26284], each, each_with_index [ruby-core:28400],
+      conjugate, conj, imaginary, imag, real, real?, rectangular, rect
+        [ruby-core:26285]
+
+    Removed compare_by*, inspect_org, cf [ruby-core:26268]
+
+    Matrix.empty: raise on negative sizes
+
+    Matrix.determinant: raise on rectangular matrices [ruby-core:28271]
+
 Thu Apr  1 17:17:00 2010  NARUSE, Yui  <naruse@r...>
 
 	* enc/trans/iso2022.trans: CP50221 supports 8bit JIS.
Index: lib/matrix.rb
===================================================================
--- lib/matrix.rb	(revision 27158)
+++ lib/matrix.rb	(revision 27159)
@@ -70,6 +70,7 @@
 # * <tt> #minor(*param)                 </tt>
 #
 # Properties of a matrix:
+# * <tt> #real?                         </tt>
 # * <tt> #regular?                      </tt>
 # * <tt> #singular?                     </tt>
 # * <tt> #square?                       </tt>
@@ -92,6 +93,15 @@
 # * <tt> #transpose                     </tt>
 # * <tt> #t                             </tt>
 #
+# Complex arithmetic:
+# * <tt> conj                           </tt>
+# * <tt> conjugate                      </tt>
+# * <tt> imag                           </tt>
+# * <tt> imaginary                      </tt>
+# * <tt> real                           </tt>
+# * <tt> rect                           </tt>
+# * <tt> rectangular                    </tt>
+#
 # Conversion to other data types:
 # * <tt> #coerce(other)                 </tt>
 # * <tt> #row_vectors                   </tt>
@@ -435,6 +445,13 @@
   end
 
   #
+  # Returns +true+ if all entries of the matrix are real.
+  #
+  def real?
+    all?(&:real?)
+  end
+
+  #
   # Returns +true+ if this is a regular matrix.
   #
   def regular?
@@ -898,6 +915,62 @@
   alias t transpose
 
   #--
+  # COMPLEX ARITHMETIC -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+  #++
+
+  #
+  # Returns the conjugate of the matrix.
+  #   Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]
+  #     => 1+2i   i  0
+  #           1   2  3
+  #   Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].conjugate
+  #     => 1-2i  -i  0
+  #           1   2  3
+  #
+  def conjugate
+    collect(&:conjugate)
+  end
+  alias conj conjugate
+
+  #
+  # Returns the imaginary part of the matrix.
+  #   Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]
+  #     => 1+2i  i  0
+  #           1  2  3
+  #   Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].imaginary
+  #     =>   2i  i  0
+  #           0  0  0
+  #
+  def imaginary
+    collect(&:imaginary)
+  end
+  alias imag imaginary
+
+  #
+  # Returns the real part of the matrix.
+  #   Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]
+  #     => 1+2i  i  0
+  #           1  2  3
+  #   Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].real
+  #     =>    1  0  0
+  #           1  2  3
+  #
+  def real
+    collect(&:real)
+  end
+
+  #
+  # Returns an array containing matrices corresponding to the real and imaginary
+  # parts of the matrix
+  #
+  # m.rect == [m.real, m.imag]  # ==> true for all matrices m
+  #
+  def rect
+    [real, imag]
+  end
+  alias rectangular rect
+
+  #--
   # CONVERTING -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
   #++
 

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

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