ruby-changes:20232
From: marcandre <ko1@a...>
Date: Wed, 29 Jun 2011 10:13:33 +0900 (JST)
Subject: [ruby-changes:20232] marcandRe: r32280 (trunk): * lib/matrix.rb: Matrix.zero can build rectangular matrices.
marcandre 2011-06-29 10:13:22 +0900 (Wed, 29 Jun 2011) New Revision: 32280 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32280 Log: * lib/matrix.rb: Matrix.zero can build rectangular matrices. Vector#r should be called #magnitude Modified files: trunk/ChangeLog trunk/NEWS trunk/lib/matrix.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 32279) +++ ChangeLog (revision 32280) @@ -1,3 +1,8 @@ +Wed Jun 29 10:13:12 2011 Marc-Andre Lafortune <ruby-core@m...> + + * lib/matrix.rb: Matrix.zero can build rectangular matrices. + Vector#r should be called #magnitude + Wed Jun 29 10:11:08 2011 Marc-Andre Lafortune <ruby-core@m...> * lib/matrix.rb: Add Matrix#diagonal?, hermitian?, normal?, Index: lib/matrix.rb =================================================================== --- lib/matrix.rb (revision 32279) +++ lib/matrix.rb (revision 32280) @@ -229,13 +229,14 @@ end # - # Creates an +n+ by +n+ zero matrix. + # Creates a zero matrix. # Matrix.zero(2) # => 0 0 # 0 0 # - def Matrix.zero(n) - Matrix.scalar(n, 0) + def Matrix.zero(row_size, column_size = row_size) + rows = Array.new(row_size){Array.new(column_size, 0)} + new rows, column_size end # @@ -1723,9 +1724,10 @@ # Returns the modulus (Pythagorean distance) of the vector. # Vector[5,8,2].r => 9.643650761 # - def r + def magnitude Math.sqrt(@elements.inject(0) {|v, e| v + e*e}) end + alias r magnitude #-- # CONVERTING Index: NEWS =================================================================== --- NEWS (revision 32279) +++ NEWS (revision 32280) @@ -168,10 +168,12 @@ * Matrix#unitary? * Matrix#upper_triangular? * Matrix#zero? + * Vector#magnitude * extended methods: * Matrix#each and #each_with_index can iterate on a subset of the elements * Matrix#find_index returns [row, column] and can iterate on a subset of the elements + * Matrix.zero can build rectangular matrices * net/http * SNI (Server Name Indication) supported for HTTPS. -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/