Skip to content

Commit

Permalink
[ruby/matrix] Make frozen matrices Ractor shareable
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Dec 9, 2020
1 parent 6b264e8 commit a7dccd0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/matrix.rb
Expand Up @@ -532,7 +532,8 @@ def collect!(which = :all)
alias map! collect!

def freeze
@rows.freeze
@rows.each(&:freeze).freeze

super
end

Expand Down Expand Up @@ -2141,6 +2142,9 @@ def zero?
all?(&:zero?)
end

#
# Makes the matrix frozen and Ractor-shareable
#
def freeze
@elements.freeze
super
Expand Down
9 changes: 9 additions & 0 deletions test/matrix/test_matrix.rb
Expand Up @@ -818,4 +818,13 @@ def test_adjoint
assert_equal(Matrix[[(1-2i), 1], [(0-1i), 2], [0, 3]], @c1.adjoint)
assert_equal(Matrix.empty(0,2), @e1.adjoint)
end

def test_ractor
obj1 = @m1.freeze

obj2 = Ractor.new obj1 do |obj|
obj
end.take
assert_same obj1, obj2
end if defined?(Ractor)
end

0 comments on commit a7dccd0

Please sign in to comment.