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

ruby-changes:60955

From: zverok <ko1@a...>
Date: Fri, 1 May 2020 16:31:20 +0900 (JST)
Subject: [ruby-changes:60955] c925cc01c5 (master): [ruby-matrix] Update docs (nicer rendering, undocumented method)

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

From c925cc01c5e8d595449156556416f067b914f6ca Mon Sep 17 00:00:00 2001
From: zverok <zverok.offline@g...>
Date: Sat, 26 Oct 2019 12:52:08 +0300
Subject: [ruby-matrix] Update docs (nicer rendering, undocumented method)


diff --git a/lib/matrix.rb b/lib/matrix.rb
index 81e3f59..a0f1160 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -72,8 +72,8 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L72
   #
   # Creates a matrix where each argument is a row.
   #   Matrix[ [25, 93], [-1, 66] ]
-  #      =>  25 93
-  #          -1 66
+  #   #   =>  25 93
+  #   #       -1 66
   #
   def Matrix.[](*rows)
     rows(rows, false)
@@ -84,8 +84,8 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L84
   # of the matrix.  If the optional argument +copy+ is false, use the given
   # arrays as the internal structure of the matrix without copying.
   #   Matrix.rows([[25, 93], [-1, 66]])
-  #      =>  25 93
-  #          -1 66
+  #   #   =>  25 93
+  #   #       -1 66
   #
   def Matrix.rows(rows, copy = true)
     rows = convert_to_array(rows, copy)
@@ -102,8 +102,8 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L102
   #
   # Creates a matrix using +columns+ as an array of column vectors.
   #   Matrix.columns([[25, 93], [-1, 66]])
-  #      =>  25 -1
-  #          93 66
+  #   #   =>  25 -1
+  #   #       93 66
   #
   def Matrix.columns(columns)
     rows(columns, false).transpose
@@ -116,9 +116,9 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L116
   # Returns an enumerator if no block is given.
   #
   #   m = Matrix.build(2, 4) {|row, col| col - row }
-  #     => Matrix[[0, 1, 2, 3], [-1, 0, 1, 2]]
+  #   #  => Matrix[[0, 1, 2, 3], [-1, 0, 1, 2]]
   #   m = Matrix.build(3) { rand }
-  #     => a 3x3 matrix with random elements
+  #   #  => a 3x3 matrix with random elements
   #
   def Matrix.build(row_count, column_count = row_count)
     row_count = CoercionHelper.coerce_to_int(row_count)
@@ -136,9 +136,9 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L136
   #
   # Creates a matrix where the diagonal elements are composed of +values+.
   #   Matrix.diagonal(9, 5, -3)
-  #     =>  9  0  0
-  #         0  5  0
-  #         0  0 -3
+  #   #  =>  9  0  0
+  #   #      0  5  0
+  #   #      0  0 -3
   #
   def Matrix.diagonal(*values)
     size = values.size
@@ -155,8 +155,8 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L155
   # Creates an +n+ by +n+ diagonal matrix where each diagonal element is
   # +value+.
   #   Matrix.scalar(2, 5)
-  #     => 5 0
-  #        0 5
+  #   #  => 5 0
+  #   #     0 5
   #
   def Matrix.scalar(n, value)
     diagonal(*Array.new(n, value))
@@ -165,8 +165,8 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L165
   #
   # Creates an +n+ by +n+ identity matrix.
   #   Matrix.identity(2)
-  #     => 1 0
-  #        0 1
+  #   #  => 1 0
+  #   #     0 1
   #
   def Matrix.identity(n)
     scalar(n, 1)
@@ -179,8 +179,8 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L179
   #
   # Creates a zero matrix.
   #   Matrix.zero(2)
-  #     => 0 0
-  #        0 0
+  #   #  => 0 0
+  #   #     0 0
   #
   def Matrix.zero(row_count, column_count = row_count)
     rows = Array.new(row_count){Array.new(column_count, 0)}
@@ -191,7 +191,7 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L191
   # Creates a single-row matrix where the values of that row are as given in
   # +row+.
   #   Matrix.row_vector([4,5,6])
-  #     => 4 5 6
+  #   #  => 4 5 6
   #
   def Matrix.row_vector(row)
     row = convert_to_array(row)
@@ -202,9 +202,9 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L202
   # Creates a single-column matrix where the values of that column are as given
   # in +column+.
   #   Matrix.column_vector([4,5,6])
-  #     => 4
-  #        5
-  #        6
+  #   #  => 4
+  #   #     5
+  #   #     6
   #
   def Matrix.column_vector(column)
     column = convert_to_array(column)
@@ -217,12 +217,12 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L217
   #
   #   m = Matrix.empty(2, 0)
   #   m == Matrix[ [], [] ]
-  #     => true
+  #   #  => true
   #   n = Matrix.empty(0, 3)
   #   n == Matrix.columns([ [], [], [] ])
-  #     => true
+  #   #  => true
   #   m * n
-  #     => Matrix[[0, 0, 0], [0, 0, 0]]
+  #   #  => Matrix[[0, 0, 0], [0, 0, 0]]
   #
   def Matrix.empty(row_count = 0, column_count = 0)
     raise ArgumentError, "One size must be 0" if column_count != 0 && row_count != 0
@@ -276,6 +276,8 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L276
     new result, total_column_count
   end
 
+  # :call-seq:
+  #   Matrix.combine(*matrices) { |*elements| ... }
   #
   # Create a matrix by combining matrices entrywise, using the given block
   #
@@ -301,12 +303,21 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L303
     new rows, x.column_count
   end
 
+  # :call-seq:
+  #   combine(*other_matrices) { |*elements| ... }
+  #
+  # Creates new matrix by combining with <i>other_matrices</i> entrywise,
+  # using the given block.
+  #
+  #   x = Matrix[[6, 6], [4, 4]]
+  #   y = Matrix[[1, 2], [3, 4]]
+  #   x.combine(y) {|a, b| a - b} # => Matrix[[5, 4], [1, 0]]
   def combine(*matrices, &block)
     Matrix.combine(self, *matrices, &block)
   end
 
   #
-  # Matrix.new is private; use Matrix.rows, columns, [], etc... to create.
+  # Matrix.new is private; use ::rows, ::columns, ::[], etc... to create.
   #
   def initialize(rows, column_count = rows[0].size)
     # No checking is done at this point. rows must be an Array of Arrays.
@@ -491,8 +502,8 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L502
   # * :strict_upper: yields only elements above the diagonal
   # * :upper: yields only elements on or above the diagonal
   #   Matrix[ [1,2], [3,4] ].collect { |e| e**2 }
-  #     => 1  4
-  #        9 16
+  #   #  => 1  4
+  #   #     9 16
   #
   def collect(which = :all, &block) # :yield: e
     return to_enum(:collect, which) unless block_given?
@@ -537,9 +548,9 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L548
   # * :strict_upper: yields only elements above the diagonal
   # * :upper: yields only elements on or above the diagonal
   #
-  #   Matrix[ [1,2], [3,4] ].each { |e| puts e }
-  #     # => prints the numbers 1 to 4
-  #   Matrix[ [1,2], [3,4] ].each(:strict_lower).to_a # => [3]
+  #     Matrix[ [1,2], [3,4] ].each { |e| puts e }
+  #       # => prints the numbers 1 to 4
+  #     Matrix[ [1,2], [3,4] ].each(:strict_lower).to_a # => [3]
   #
   def each(which = :all, &block) # :yield: e
     return to_enum :each, which unless block_given?
@@ -688,8 +699,8 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L699
   # *  row_range, col_range
   #
   #   Matrix.diagonal(9, 5, -3).minor(0..1, 0..2)
-  #     => 9 0 0
-  #        0 5 0
+  #   #  => 9 0 0
+  #   #     0 5 0
   #
   # Like Array#[], negative indices count backward from the end of the
   # row or column (-1 is the last element). Returns nil if the starting
@@ -732,9 +743,9 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L743
   # Returns the submatrix obtained by deleting the specified row and column.
   #
   #   Matrix.diagonal(9, 5, -3, 4).first_minor(1, 2)
-  #     => 9 0 0
-  #        0 0 0
-  #        0 0 4
+  #   #  => 9 0 0
+  #   #     0 0 0
+  #   #     0 0 4
   #
   def first_minor(row, column)
     raise RuntimeError, "first_minor of empty matrix is not defined" if empty?
@@ -761,7 +772,7 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L772
   # the first minor by (-1)**(row + column).
   #
   #   Matrix.diagonal(9, 5, -3, 4).cofactor(1, 1)
-  #     => -108
+  #   #  => -108
   #
   def cofactor(row, column)
     raise RuntimeError, "cofactor of empty matrix is not defined" if empty?
@@ -775,8 +786,8 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L786
   # Returns the adjugate of the matrix.
   #
   #   Matrix[ [7,6],[3,9] ].adjugate
-  #     => 9 -6
-  #        -3 7
+  #   #  => 9 -6
+  #   #     -3 7
   #
   def adjugate
     raise ErrDimensionMismatch unless square?
@@ -789,10 +800,10 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L800
   # Returns the Laplace expansion along given row or column.
   #
   #    Matrix[[7,6], [3,9]].laplace_expansion(column: 1)
-  #     => 45
+  #    # => 45
   #
   #    Matrix[[Vector[1, 0], Vector[0, 1]], [2, 3]].laplace_expansion(row: 0)
-  #     => Vector[3, -2]
+  #    # => Vector[3, -2]
   #
   #
   def laplace_expansion(row: nil, column: nil)
@@ -1039,8 +1050,8 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L1050
   #
   # Matrix multiplication.
   #   Matrix[[2,4], [6,8]] * Matrix.identity(2)
-  #     => 2 4
-  #        6 8
+  #   #  => 2 4
+  #   #     6 8
   #
   def *(m) # m is matrix or vector or number
     case(m)
@@ -1072,8 +1083,8 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L1083
   #
   # Matrix addition.
   #   Matrix.scalar(2,5) + Matrix[[1,0], [-4,7]]
-  #     =>  6  0
-  #        -4 12
+  #   #  =>  6  0
+  #   #     -4 12
   #
   def +(m)
     case m
@@ -1099,8 +1110,8 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L1110
   #
   # Matrix subtraction.
   #   Matrix[[1,5], [4,2]] - Matrix[[9,3], [-4,1]]
-  #     => -8  2
-  #         8  1
+  #   #  => -8  2
+  #   #      8  1
   #
   def -(m)
     case m
@@ -1126,8 +1137,8 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L1137
   #
   # Matrix division (multiplication by the inverse).
   #   Matrix[[7,6], [3,9]] / Matrix[[2,9], [3,1]]
-  #     => -7  1
-  #        -3 -6
+  #   #  => -7  1
+  #   #     -3 -6
   #
   def /(other)
     case other
@@ -1146,8 +1157,8 @@ class Matrix https://git (... truncated)

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

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