Add abs to Matrix (#2199)
This commit is contained in:
parent
48fdc37ad5
commit
8d804e41a0
@ -1225,6 +1225,13 @@ class Matrix
|
|||||||
collect {|e| -e }
|
collect {|e| -e }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#
|
||||||
|
# Returns the absolute value elementwise
|
||||||
|
#
|
||||||
|
def abs
|
||||||
|
collect(&:abs)
|
||||||
|
end
|
||||||
|
|
||||||
#--
|
#--
|
||||||
# MATRIX FUNCTIONS -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
# MATRIX FUNCTIONS -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
||||||
#++
|
#++
|
||||||
|
@ -583,6 +583,11 @@ class TestMatrix < Test::Unit::TestCase
|
|||||||
assert_equal(1, s1 ** o)
|
assert_equal(1, s1 ** o)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_abs
|
||||||
|
s1 = @a3.abs
|
||||||
|
assert_equal(s1, Matrix[[4, 1, 3], [0, 3, 7], [11, 4, 2]])
|
||||||
|
end
|
||||||
|
|
||||||
def test_hstack
|
def test_hstack
|
||||||
assert_equal Matrix[[1,2,3,2,3,4,1,2,3], [4,5,6,5,6,7,4,5,6]],
|
assert_equal Matrix[[1,2,3,2,3,4,1,2,3], [4,5,6,5,6,7,4,5,6]],
|
||||||
@m1.hstack(@n1, @m1)
|
@m1.hstack(@n1, @m1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user