diff options
| author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-01-09 20:39:28 +0000 |
|---|---|---|
| committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-01-09 20:39:28 +0000 |
| commit | 71ecd899986ed10a549d32762331ea9632343b1b (patch) | |
| tree | 206a940ee97f0ec27849a6addcac9d9e9d37f95e | |
| parent | 2ae2d9dd4dae4089bc1c0a813cd520734ad33d28 (diff) | |
reverted r26263.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@26264 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 10 | ||||
| -rw-r--r-- | lib/matrix.rb | 16 | ||||
| -rw-r--r-- | test/matrix/test_matrix.rb | 4 |
3 files changed, 10 insertions, 20 deletions
@@ -1,13 +1,3 @@ -Sun Jan 10 05:35:26 2010 Nobuyoshi Nakada <nobu@ruby-lang.org> - - * lib/matrix.rb (Matrix#inverse_from): use #quo. backported r9490. - - * lib/matrix.rb (Matrix#determinant): ditto. [ruby-core:27507] - - * lib/matrix.rb (Matrix#rank): ditto. - - * lib/matrix.rb (Matrix::Scalar#initialize): ditto. - Sun Jan 10 04:54:36 2010 Nobuyoshi Nakada <nobu@ruby-lang.org> * class.c (rb_define_class): raise TypeError same as class diff --git a/lib/matrix.rb b/lib/matrix.rb index 35ccb62625..93ae3a9909 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -549,7 +549,7 @@ class Matrix # # Returns the inverse of the matrix. - # Matrix[[-1, -1], [0, -1]].inverse + # Matrix[[1, 2], [2, 1]].inverse # => -1 1 # 0 -1 # @@ -585,7 +585,7 @@ class Matrix size.times do |i| next if i == k - q = a[i][k].quo(akk) + q = a[i][k] / akk a[i][k] = 0 (k + 1 ... size).each do |j| @@ -597,10 +597,10 @@ class Matrix end (k + 1 ... size).each do |j| - a[k][j] = a[k][j].quo(akk) + a[k][j] /= akk end size.times do |j| - @rows[k][j] = @rows[k][j].quo(akk) + @rows[k][j] /= akk end end self @@ -649,7 +649,7 @@ class Matrix # Returns the determinant of the matrix. If the matrix is not square, the # result is 0. # Matrix[[7,6], [3,9]].determinant - # => 45 + # => 63 # def determinant return 0 unless square? @@ -670,7 +670,7 @@ class Matrix end (k + 1 ... size).each do |i| - q = a[i][k].quo(akk) + q = a[i][k] / akk (k + 1 ... size).each do |j| a[i][j] -= a[k][j] * q end @@ -720,7 +720,7 @@ class Matrix end (k + 1 ... a_row_size).each do |i| - q = a[i][k].quo(akk) + q = a[i][k] / akk (k + 1... a_column_size).each do |j| a[i][j] -= a[k][j] * q end @@ -879,7 +879,7 @@ class Matrix self * other.inverse else x, y = other.coerce(self) - x.quo(y) + x / y end end diff --git a/test/matrix/test_matrix.rb b/test/matrix/test_matrix.rb index 6b9b587c6d..90e52b1295 100644 --- a/test/matrix/test_matrix.rb +++ b/test/matrix/test_matrix.rb @@ -150,7 +150,7 @@ class TestMatrix < Test::Unit::TestCase end def test_determinant - assert_equal(45, Matrix[[7,6], [3,9]].determinant) - assert_equal(-18, Matrix[[2,0,1],[0,-2,2],[1,2,3]].determinant) + assert_equal(45, Matrix[[7.0,6.0], [3.0,9.0]].determinant) + assert_equal(-18, Matrix[[2.0,0.0,1.0],[0.0,-2.0,2.0],[1.0,2.0,3.0]].determinant) end end |
