[ruby/matrix] Make frozen matrices Ractor shareable

This commit is contained in:
Marc-Andre Lafortune 2020-09-26 15:49:43 -04:00 committed by Marc-André Lafortune
parent 6b264e833f
commit a7dccd08e7
Notes: git 2020-12-09 16:16:06 +09:00
2 changed files with 14 additions and 1 deletions

View File

@ -532,7 +532,8 @@ class Matrix
alias map! collect! alias map! collect!
def freeze def freeze
@rows.freeze @rows.each(&:freeze).freeze
super super
end end
@ -2141,6 +2142,9 @@ class Vector
all?(&:zero?) all?(&:zero?)
end end
#
# Makes the matrix frozen and Ractor-shareable
#
def freeze def freeze
@elements.freeze @elements.freeze
super super

View File

@ -818,4 +818,13 @@ class TestMatrix < Test::Unit::TestCase
assert_equal(Matrix[[(1-2i), 1], [(0-1i), 2], [0, 3]], @c1.adjoint) assert_equal(Matrix[[(1-2i), 1], [(0-1i), 2], [0, 3]], @c1.adjoint)
assert_equal(Matrix.empty(0,2), @e1.adjoint) assert_equal(Matrix.empty(0,2), @e1.adjoint)
end 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 end