mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parent
8187228de0
commit
d8c8b79d24
Notes:
git
2021-01-11 06:21:37 +09:00
Merged-By: marcandre <github@marc-andre.ca>
2 changed files with 17 additions and 4 deletions
|
@ -1239,7 +1239,7 @@ class Matrix
|
||||||
when Integer
|
when Integer
|
||||||
case
|
case
|
||||||
when exp == 0
|
when exp == 0
|
||||||
_make_sure_it_is_invertible = inverse
|
raise ErrDimensionMismatch unless square?
|
||||||
self.class.identity(column_count)
|
self.class.identity(column_count)
|
||||||
when exp < 0
|
when exp < 0
|
||||||
inverse.power_int(-exp)
|
inverse.power_int(-exp)
|
||||||
|
|
|
@ -21,17 +21,30 @@ describe "Matrix#**" do
|
||||||
-> { m ** 0 }.should raise_error(Matrix::ErrDimensionMismatch)
|
-> { m ** 0 }.should raise_error(Matrix::ErrDimensionMismatch)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "that is <= 0" do
|
describe "that is < 0" do
|
||||||
it "returns the inverse of **(-n)" do
|
it "returns the inverse of **(-n)" do
|
||||||
m = Matrix[ [1, 1], [1, 2] ]
|
m = Matrix[ [1, 1], [1, 2] ]
|
||||||
(m ** -2).should == Matrix[ [5, -3], [-3, 2]]
|
(m ** -2).should == Matrix[ [5, -3], [-3, 2]]
|
||||||
(m ** -4).should == (m.inverse ** 4)
|
(m ** -4).should == (m.inverse ** 4)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises a ErrDimensionMismatch for irregular matrices" do
|
it "raises a ErrNotRegular for irregular matrices" do
|
||||||
m = Matrix[ [1, 1], [1, 1] ]
|
m = Matrix[ [1, 1], [1, 1] ]
|
||||||
-> { m ** -2 }.should raise_error(Matrix::ErrNotRegular)
|
-> { m ** -2 }.should raise_error(Matrix::ErrNotRegular)
|
||||||
-> { m ** 0 }.should raise_error(Matrix::ErrNotRegular)
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ruby_bug '#17521', ''..'3.0.0' do
|
||||||
|
describe "that is 0" do
|
||||||
|
it "returns the identity for square matrices" do
|
||||||
|
m = Matrix[ [1, 1], [1, 1] ]
|
||||||
|
(m ** 0).should == Matrix.identity(2)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "raises an ErrDimensionMismatch for non-square matrices" do
|
||||||
|
m = Matrix[ [1, 1] ]
|
||||||
|
-> { m ** 0 }.should raise_error(Matrix::ErrDimensionMismatch)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue