Project

General

Profile

Feature #10069

[PATCH] Implement monadic operator for Matrix

Added by gogo tanaka over 2 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
[ruby-core:63850]

Description

Before

m = Matrix[[1,2,3], [4,5,6]]

+ m
NoMethodError: undefined method `+@' for Matrix[[1, 2, 3], [4, 5, 6]]:Matrix

- m
NoMethodError: undefined method `-@' for Matrix[[1, 2, 3], [4, 5, 6]]:Matrix

After

m = Matrix[[1,2,3], [4,5,6]]

+ m
=> Matrix[[1, 2, 3], [4, 5, 6]]

- m
=> Matrix[[-1, -2, -3], [-4, -5, -6]]

I think monadic operator for Matrix is important, when I use operator as block. like that

matrix_ary.inject(:+)

implement_uplus_for_matrix.patch View (762 Bytes) gogo tanaka, 07/19/2014 02:07 AM

implement_negate_for_matrix.patch View (1.21 KB) gogo tanaka, 07/19/2014 02:07 AM


Related issues

Related to Ruby trunk - Feature #10068: [PATCH] Implement monadic operator for Vector Closed 07/19/2014

Associated revisions

Revision 47840
Added by Marc-Andre Lafortune about 2 years ago

  • lib/matrix.rb: Add @- and @+ for Matrix and Vector. patch by gogo tanaka [#10068] [#10069]

Revision 47840
Added by Marc-Andre Lafortune about 2 years ago

  • lib/matrix.rb: Add @- and @+ for Matrix and Vector. patch by gogo tanaka [#10068] [#10069]

Revision 47840
Added by Marc-Andre Lafortune about 2 years ago

  • lib/matrix.rb: Add @- and @+ for Matrix and Vector. patch by gogo tanaka [#10068] [#10069]

History

#1 [ruby-core:63870] Updated by Yukihiro Matsumoto over 2 years ago

  • Related to Feature #10068: [PATCH] Implement monadic operator for Vector added

#2 [ruby-core:63871] Updated by Yukihiro Matsumoto over 2 years ago

As #10068, I like the idea, but unary operator has nothing related to inject though.

Matz.

#3 [ruby-core:63885] Updated by gogo tanaka over 2 years ago

Yukihiro Matsumoto wrote:

unary operator has nothing related to inject though.

It's kind of my mistake, sorry to confuse you.

I think it not seldom happens that we want do this(term monadic). And this is based on custom in math.

Compared with some other numerical analysis software(MATLAB, mathematica, GNU Octave, R, NumPy),

They have term monadic for matrix, vector. (But you can say "this is ruby issue! this is no business of how other softwares are" )

thank you.

gogo.

#4 [ruby-core:63902] Updated by Hiroshi SHIBATA over 2 years ago

  • Target version set to current: 2.2.0
  • Assignee set to Marc-Andre Lafortune
  • Category set to lib
  • Status changed from Open to Assigned

#5 [ruby-core:65495] Updated by Marc-Andre Lafortune about 2 years ago

  • Status changed from Assigned to Closed

Done.

Thanks for catching this omission, and for the patch.

Also available in: Atom PDF