Skip to content

Commit

Permalink
Add abs to Matrix (#2199)
Browse files Browse the repository at this point in the history
  • Loading branch information
bonafernando authored and marcandre committed Aug 21, 2019
1 parent 48fdc37 commit 8d804e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/matrix.rb
Expand Up @@ -1225,6 +1225,13 @@ def -@
collect {|e| -e }
end

#
# Returns the absolute value elementwise
#
def abs
collect(&:abs)
end

#--
# MATRIX FUNCTIONS -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#++
Expand Down
5 changes: 5 additions & 0 deletions test/matrix/test_matrix.rb
Expand Up @@ -583,6 +583,11 @@ def o.coerce(x)
assert_equal(1, s1 ** o)
end

def test_abs
s1 = @a3.abs
assert_equal(s1, Matrix[[4, 1, 3], [0, 3, 7], [11, 4, 2]])
end

def test_hstack
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)
Expand Down

0 comments on commit 8d804e4

Please sign in to comment.