summaryrefslogtreecommitdiff
path: root/lib/matrix.rb
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-17 21:09:31 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-17 21:09:31 +0000
commitef83d7a928ef9d998dc9cf9cb86649cdd9ffceea (patch)
tree79a47d7e01762965559abf0348ada0b65efe636a /lib/matrix.rb
parent914efd0b60acc061b161faa4ebb8bce528793384 (diff)
* lib/matrix.rb (determinant): Trivial optimization (thanks to Benoit Daloze)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27868 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/matrix.rb')
-rw-r--r--lib/matrix.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/matrix.rb b/lib/matrix.rb
index ee26cb9..b98fc85 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -747,12 +747,12 @@ class Matrix
when 2
+ m[0][0] * m[1][1] - m[0][1] * m[1][0]
when 3
- m0 = m[0]; m1 = m[1]; m2 = m[2]
+ m0, m1, m2 = m
+ m0[0] * m1[1] * m2[2] - m0[0] * m1[2] * m2[1] \
- m0[1] * m1[0] * m2[2] + m0[1] * m1[2] * m2[0] \
+ m0[2] * m1[0] * m2[1] - m0[2] * m1[1] * m2[0]
when 4
- m0 = m[0]; m1 = m[1]; m2 = m[2]; m3 = m[3]
+ m0, m1, m2, m3 = m
+ m0[0] * m1[1] * m2[2] * m3[3] - m0[0] * m1[1] * m2[3] * m3[2] \
- m0[0] * m1[2] * m2[1] * m3[3] + m0[0] * m1[2] * m2[3] * m3[1] \
+ m0[0] * m1[3] * m2[1] * m3[2] - m0[0] * m1[3] * m2[2] * m3[1] \