Feature #10069

[PATCH] Implement monadic operator for Matrix

Added by gogo tanaka about 1 year ago. Updated 11 months ago.

[ruby-core:63850]
Status:Closed
Priority:Normal
Assignee:Marc-Andre Lafortune

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 Magnifier (762 Bytes) gogo tanaka, 07/19/2014 02:07 AM

implement_negate_for_matrix.patch Magnifier (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 11 months ago

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

Revision 47840
Added by Marc-Andre Lafortune 11 months ago

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

History

#1 Updated by Yukihiro Matsumoto about 1 year ago

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

#2 Updated by Yukihiro Matsumoto about 1 year ago

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

Matz.

#3 Updated by gogo tanaka about 1 year 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 Updated by Hiroshi SHIBATA about 1 year 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 Updated by Marc-Andre Lafortune 11 months ago

  • Status changed from Assigned to Closed

Done.

Thanks for catching this omission, and for the patch.

Also available in: Atom PDF