ruby-changes:64040
From: Marc-Andre <ko1@a...>
Date: Wed, 9 Dec 2020 16:15:59 +0900 (JST)
Subject: [ruby-changes:64040] a7dccd08e7 (master): [ruby/matrix] Make frozen matrices Ractor shareable
https://git.ruby-lang.org/ruby.git/commit/?id=a7dccd08e7 From a7dccd08e7c9cf0e5d0c0fdbe659ccc921624e6f Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune <github@m...> Date: Sat, 26 Sep 2020 15:49:43 -0400 Subject: [ruby/matrix] Make frozen matrices Ractor shareable diff --git a/lib/matrix.rb b/lib/matrix.rb index c6193eb..32f1e23 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -532,7 +532,8 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L532 alias map! collect! def freeze - @rows.freeze + @rows.each(&:freeze).freeze + super end @@ -2141,6 +2142,9 @@ class Vector https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L2142 all?(&:zero?) end + # + # Makes the matrix frozen and Ractor-shareable + # def freeze @elements.freeze super diff --git a/test/matrix/test_matrix.rb b/test/matrix/test_matrix.rb index 8125fb2..03e6bf1 100644 --- a/test/matrix/test_matrix.rb +++ b/test/matrix/test_matrix.rb @@ -818,4 +818,13 @@ class TestMatrix < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/matrix/test_matrix.rb#L818 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 -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/