mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/matrix.rb: Add @- and @+ for Matrix and Vector.
patch by gogo tanaka [#10068] [#10069] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47840 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
49e9f4714e
commit
a2ae7bccf8
5 changed files with 45 additions and 1 deletions
|
@ -1,3 +1,8 @@
|
|||
Wed Oct 8 05:16:32 2014 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
||||
|
||||
* lib/matrix.rb: Add @- and @+ for Matrix and Vector.
|
||||
patch by gogo tanaka [#10068] [#10069]
|
||||
|
||||
Wed Oct 8 04:58:48 2014 John Bachir <j@jjb.cc>
|
||||
|
||||
* bootstraptest/test_io.rb (assert_finish):
|
||||
|
@ -55,7 +60,7 @@ Tue Oct 7 21:40:17 2014 Masaki Suketa <masaki.suketa@nifty.ne.jp>
|
|||
* ext/win32ole/win32ole_method.c: refactoring. add
|
||||
olemethod_data_get_struct to wrap Data_Get_Struct.
|
||||
* ext/win32ole/win32ole_method.h: ditto.
|
||||
|
||||
|
||||
* ext/win32ole/win32ole_param.c (oleparam_ole_param):
|
||||
call olemethod_data_get_struct instead of Data_Get_Struct.
|
||||
|
||||
|
|
1
NEWS
1
NEWS
|
@ -147,6 +147,7 @@ with all sufficient information, see the ChangeLog file.
|
|||
* Matrix#laplace_expansion(row_or_column: num) returns the laplace_expansion
|
||||
along the +num+ -th row or column.
|
||||
* Vector.basis(size:, index:) returns the specified basis vector
|
||||
* Unary - and + added for Vector and Matrix
|
||||
|
||||
* Pathname
|
||||
* Pathname#/ is aliased to Pathname#+.
|
||||
|
|
|
@ -90,6 +90,8 @@ end
|
|||
# * #inverse
|
||||
# * #inv
|
||||
# * #**
|
||||
# * #+@
|
||||
# * #-@
|
||||
#
|
||||
# Matrix functions:
|
||||
# * #determinant
|
||||
|
@ -1122,6 +1124,14 @@ class Matrix
|
|||
end
|
||||
end
|
||||
|
||||
def +@
|
||||
self
|
||||
end
|
||||
|
||||
def -@
|
||||
collect {|e| -e }
|
||||
end
|
||||
|
||||
#--
|
||||
# MATRIX FUNCTIONS -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
#++
|
||||
|
@ -1670,6 +1680,8 @@ end
|
|||
# * #*(x) "is matrix or number"
|
||||
# * #+(v)
|
||||
# * #-(v)
|
||||
# * #+@
|
||||
# * #-@
|
||||
#
|
||||
# Vector functions:
|
||||
# * #inner_product(v)
|
||||
|
@ -1907,6 +1919,14 @@ class Vector
|
|||
end
|
||||
end
|
||||
|
||||
def +@
|
||||
self
|
||||
end
|
||||
|
||||
def -@
|
||||
collect {|e| -e }
|
||||
end
|
||||
|
||||
#--
|
||||
# VECTOR FUNCTIONS -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||
#++
|
||||
|
|
|
@ -62,6 +62,15 @@ class TestMatrix < Test::Unit::TestCase
|
|||
assert_equal @m1.hash, @m3.hash
|
||||
end
|
||||
|
||||
def test_uplus
|
||||
assert_equal(@m1, +@m1)
|
||||
end
|
||||
|
||||
def test_negate
|
||||
assert_equal(Matrix[[-1, -2, -3], [-4, -5, -6]], -@m1)
|
||||
assert_equal(@m1, -(-@m1))
|
||||
end
|
||||
|
||||
def test_rank
|
||||
[
|
||||
[[0]],
|
||||
|
|
|
@ -120,6 +120,15 @@ class TestVector < Test::Unit::TestCase
|
|||
assert_equal(0, Vector[1, 2, 3] - o)
|
||||
end
|
||||
|
||||
def test_uplus
|
||||
assert_equal(@v1, +@v1)
|
||||
end
|
||||
|
||||
def test_negate
|
||||
assert_equal(Vector[-1, -2, -3], -@v1)
|
||||
assert_equal(@v1, -(-@v1))
|
||||
end
|
||||
|
||||
def test_inner_product
|
||||
assert_equal(1+4+9, @v1.inner_product(@v1))
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue