mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
914efd0b60
commit
ef83d7a928
1 changed files with 2 additions and 2 deletions
|
@ -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] \
|
||||
|
|
Loading…
Reference in a new issue