RCR: Enhancing matrix.rb

Hi,

Following three methods would make Ruby’s Matrix class (matrix.rb) more
powerful (especially the []= method):

class Matrix

···

Same as +collect+ but in-place.

def collect! # :yield: e
@rows.each{|row| row.collect!{|e| yield e}}
self
end
alias map! collect!

Sets element (+i+,+j+) of the matrix to +value+. That is: row +i+,

column +j+.

def []=(i, j, value)
@rows[i][j] = value
end

Creates an empty +m+ by +n+ matrix.

def Matrix.m_by_n(m, n)
new(:init_rows, (0…m).map{Array.new(n)}, false)
end
end

Should we add them?

Regards,

Michael

Hi,

Following three methods would make Ruby’s Matrix class (matrix.rb) more
powerful (especially the = method):

Should we add them?

Keiju will make final decision. I will forward your proposal to him.

						matz.
···

In message “RCR: Enhancing matrix.rb” on 03/06/04, Michael Neumann mneumann@ntecs.de writes:

Hi,

···

In message “Re: RCR: Enhancing matrix.rb” on 03/06/04, Yukihiro Matsumoto matz@ruby-lang.org writes:

Following three methods would make Ruby’s Matrix class (matrix.rb) more
powerful (especially the = method):

Should we add them?

Keiju will make final decision. I will forward your proposal to him.

Keiju and others feel reluctant against making Matrix mutable. I
understand their feeling. What do you think to use these muting
methods for? There might be different ways.

						matz.

No problem, as I can still extend Matrix locally in my own applications.

Now, after having looked through my application for a further time, I
think I can live very well without mutable matrices.

Regards,

Michael

···

On Fri, Jun 06, 2003 at 02:15:19PM +0900, Yukihiro Matsumoto wrote:

Hi,

In message “Re: RCR: Enhancing matrix.rb” > on 03/06/04, Yukihiro Matsumoto matz@ruby-lang.org writes:

Following three methods would make Ruby’s Matrix class (matrix.rb) more
powerful (especially the = method):

Should we add them?

Keiju will make final decision. I will forward your proposal to him.

Keiju and others feel reluctant against making Matrix mutable. I
understand their feeling. What do you think to use these muting
methods for? There might be different ways.

I do not understand their reluctance. I see no good reason for Matrix
to be immutable.

As for where a mutable Matrix might be useful, consider:

  • Without =, how can a (very large) Matrix be created incrementally?
    (it can be done, but the solution isn’t pretty). With =,
    Matrix.diagonal() could be implemented in terms of = instead of
    having to create a temporary array then copy that array into the
    Matrix.
  • Suppose I want to perform a particular transformation on a large
    Matrix. Should it be necessary to make a copy of this large Matrix
    in order to perform the transformation? Bear in mind that I may not
    even want to keep the original Matrix around.

If I want an immutable Matrix, I can always freeze it.

Paul

···

On Fri, Jun 06, 2003 at 02:15:19PM +0900, Yukihiro Matsumoto wrote:

Keiju and others feel reluctant against making Matrix mutable. I
understand their feeling. What do you think to use these muting
methods for? There might be different ways.

How about adding it to rubygarden ?

···

On Fri, 06 Jun 2003 19:10:04 +0900, Michael Neumann wrote:

On Fri, Jun 06, 2003 at 02:15:19PM +0900, Yukihiro Matsumoto wrote:

Keiju and others feel reluctant against making Matrix mutable. I
understand their feeling. What do you think to use these muting
methods for? There might be different ways.

No problem, as I can still extend Matrix locally in my own applications.

Now, after having looked through my application for a further time, I
think I can live very well without mutable matrices.


Simon Strandgaard

Didn’t knew about this great link. I’ll add it there.

Regards,

Michael

···

On Fri, Jun 06, 2003 at 06:43:41PM +0900, Simon Strandgaard wrote:

On Fri, 06 Jun 2003 19:10:04 +0900, Michael Neumann wrote:

On Fri, Jun 06, 2003 at 02:15:19PM +0900, Yukihiro Matsumoto wrote:

Keiju and others feel reluctant against making Matrix mutable. I
understand their feeling. What do you think to use these muting
methods for? There might be different ways.

No problem, as I can still extend Matrix locally in my own applications.

Now, after having looked through my application for a further time, I
think I can live very well without mutable matrices.

How about adding it to rubygarden ?

http://www.rubygarden.org/ruby?StandardClassExtensions

Keiju and others feel reluctant against making Matrix mutable. I
understand their feeling. What do you think to use these muting
methods for? There might be different ways.

No problem, as I can still extend Matrix locally in my own
applications.

Now, after having looked through my application for a further time, I
think I can live very well without mutable matrices.

How about adding it to rubygarden ?

http://www.rubygarden.org/ruby?StandardClassExtensions

Didn’t knew about this great link. I’ll add it there.

If there is a new version of Matrix, of course it
should be called Matrix Reloaded.

Hal

···

----- Original Message -----
From: “Michael Neumann” mneumann@ntecs.de
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Friday, June 06, 2003 5:46 AM
Subject: Re: RCR: Enhancing matrix.rb

On Fri, Jun 06, 2003 at 06:43:41PM +0900, Simon Strandgaard wrote:

On Fri, 06 Jun 2003 19:10:04 +0900, Michael Neumann wrote:

On Fri, Jun 06, 2003 at 02:15:19PM +0900, Yukihiro Matsumoto wrote: