mirror of
https://github.com/ruby/ruby.git
synced 2025-08-26 06:25:31 +02:00
[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]
This commit is contained in:
parent
3b5b309b7b
commit
a83a51932d
Notes:
git
2020-12-05 14:57:22 +09:00
2 changed files with 44 additions and 15 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue