diff options
author | Marc-Andre Lafortune <github@marc-andre.ca> | 2020-12-04 01:57:40 -0500 |
---|---|---|
committer | Marc-André Lafortune <github@marc-andre.ca> | 2020-12-05 00:56:58 -0500 |
commit | a83a51932dbc31b549e11b9da8967f2f52a8b07c (patch) | |
tree | 272eea99e5f40150af2a52114d7f8c9d8f325264 /test/matrix | |
parent | 3b5b309b7b3724849c27dc1c836b5348a8a82e23 (diff) | |
download | ruby-a83a51932dbc31b549e11b9da8967f2f52a8b07c.tar.gz |
[ruby/matrix] Optimize **
Avoiding recursive call would imply iterating bits starting from
most significant, which is not easy to do efficiently.
Any saving would be dwarfed by the multiplications anyways.
[Feature #15233]
Diffstat (limited to 'test/matrix')
-rw-r--r-- | test/matrix/test_matrix.rb | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/test/matrix/test_matrix.rb b/test/matrix/test_matrix.rb index b134bfb3a1..8125fb2bcb 100644 --- a/test/matrix/test_matrix.rb +++ b/test/matrix/test_matrix.rb @@ -448,6 +448,12 @@ class TestMatrix < Test::Unit::TestCase assert_equal(Matrix[[67,96],[48,99]], Matrix[[7,6],[3,9]] ** 2) assert_equal(Matrix.I(5), Matrix.I(5) ** -1) assert_raise(Matrix::ErrOperationNotDefined) { Matrix.I(5) ** Object.new } + + m = Matrix[[0,2],[1,0]] + exp = 0b11101000 + assert_equal(Matrix.scalar(2, 1 << (exp/2)), m ** exp) + exp = 0b11101001 + assert_equal(Matrix[[0, 2 << (exp/2)], [1 << (exp/2), 0]], m ** exp) end def test_det |