summaryrefslogtreecommitdiff
path: root/lib/matrix
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-10 16:53:57 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-10 16:53:57 +0000
commit8aac5f48fc96c4aa76d4758d8c873f3e2cb6de90 (patch)
treed59af5220c58cfff6c90900451c8e3f0cb09290f /lib/matrix
parent4c02cff191df87992a1c18d39f85693ec0de6597 (diff)
* lib/matrix: alias {row|column}_size to {row|column}_count and use the latter.
[Bug #7369] [ruby-core:49409] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38300 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/matrix')
-rw-r--r--lib/matrix/eigenvalue_decomposition.rb2
-rw-r--r--lib/matrix/lup_decomposition.rb56
2 files changed, 29 insertions, 29 deletions
diff --git a/lib/matrix/eigenvalue_decomposition.rb b/lib/matrix/eigenvalue_decomposition.rb
index 55e41aaf7cd..ab5888ff371 100644
--- a/lib/matrix/eigenvalue_decomposition.rb
+++ b/lib/matrix/eigenvalue_decomposition.rb
@@ -20,7 +20,7 @@ class Matrix
# @v: Array for internal storage of eigenvectors.
# @h: Array for internal storage of nonsymmetric Hessenberg form.
raise TypeError, "Expected Matrix but got #{a.class}" unless a.is_a?(Matrix)
- @size = a.row_size
+ @size = a.row_count
@d = Array.new(@size, 0)
@e = Array.new(@size, 0)
diff --git a/lib/matrix/lup_decomposition.rb b/lib/matrix/lup_decomposition.rb
index 8f5aac2e5a1..cf3897e9225 100644
--- a/lib/matrix/lup_decomposition.rb
+++ b/lib/matrix/lup_decomposition.rb
@@ -19,7 +19,7 @@ class Matrix
include Matrix::ConversionHelper
def l
- Matrix.build(@row_size, @col_size) do |i, j|
+ Matrix.build(@row_count, @column_count) do |i, j|
if (i > j)
@lu[i][j]
elsif (i == j)
@@ -33,7 +33,7 @@ class Matrix
# Returns the upper triangular factor +U+
def u
- Matrix.build(@col_size, @col_size) do |i, j|
+ Matrix.build(@column_count, @column_count) do |i, j|
if (i <= j)
@lu[i][j]
else
@@ -45,9 +45,9 @@ class Matrix
# Returns the permutation matrix +P+
def p
- rows = Array.new(@row_size){Array.new(@col_size, 0)}
+ rows = Array.new(@row_count){Array.new(@column_count, 0)}
@pivots.each_with_index{|p, i| rows[i][p] = 1}
- Matrix.send :new, rows, @col_size
+ Matrix.send :new, rows, @column_count
end
# Returns +L+, +U+, +P+ in an array
@@ -64,7 +64,7 @@ class Matrix
# Returns +true+ if +U+, and hence +A+, is singular.
def singular? ()
- @col_size.times do |j|
+ @column_count.times do |j|
if (@lu[j][j] == 0)
return true
end
@@ -76,11 +76,11 @@ class Matrix
# from the factorization.
def det
- if (@row_size != @col_size)
+ if (@row_count != @column_count)
Matrix.Raise Matrix::ErrDimensionMismatch unless square?
end
d = @pivot_sign
- @col_size.times do |j|
+ @column_count.times do |j|
d *= @lu[j][j]
end
d
@@ -96,24 +96,24 @@ class Matrix
Matrix.Raise Matrix::ErrNotRegular, "Matrix is singular."
end
if b.is_a? Matrix
- if (b.row_size != @row_size)
+ if (b.row_count != @row_count)
Matrix.Raise Matrix::ErrDimensionMismatch
end
# Copy right hand side with pivoting
- nx = b.column_size
+ nx = b.column_count
m = @pivots.map{|row| b.row(row).to_a}
# Solve L*Y = P*b
- @col_size.times do |k|
- (k+1).upto(@col_size-1) do |i|
+ @column_count.times do |k|
+ (k+1).upto(@column_count-1) do |i|
nx.times do |j|
m[i][j] -= m[k][j]*@lu[i][k]
end
end
end
# Solve U*m = Y
- (@col_size-1).downto(0) do |k|
+ (@column_count-1).downto(0) do |k|
nx.times do |j|
m[k][j] = m[k][j].quo(@lu[k][k])
end
@@ -126,7 +126,7 @@ class Matrix
Matrix.send :new, m, nx
else # same algorithm, specialized for simpler case of a vector
b = convert_to_array(b)
- if (b.size != @row_size)
+ if (b.size != @row_count)
Matrix.Raise Matrix::ErrDimensionMismatch
end
@@ -134,13 +134,13 @@ class Matrix
m = b.values_at(*@pivots)
# Solve L*Y = P*b
- @col_size.times do |k|
- (k+1).upto(@col_size-1) do |i|
+ @column_count.times do |k|
+ (k+1).upto(@column_count-1) do |i|
m[i] -= m[k]*@lu[i][k]
end
end
# Solve U*m = Y
- (@col_size-1).downto(0) do |k|
+ (@column_count-1).downto(0) do |k|
m[k] = m[k].quo(@lu[k][k])
k.times do |i|
m[i] -= m[k]*@lu[i][k]
@@ -154,28 +154,28 @@ class Matrix
raise TypeError, "Expected Matrix but got #{a.class}" unless a.is_a?(Matrix)
# Use a "left-looking", dot-product, Crout/Doolittle algorithm.
@lu = a.to_a
- @row_size = a.row_size
- @col_size = a.column_size
- @pivots = Array.new(@row_size)
- @row_size.times do |i|
+ @row_count = a.row_count
+ @column_count = a.column_count
+ @pivots = Array.new(@row_count)
+ @row_count.times do |i|
@pivots[i] = i
end
@pivot_sign = 1
- lu_col_j = Array.new(@row_size)
+ lu_col_j = Array.new(@row_count)
# Outer loop.
- @col_size.times do |j|
+ @column_count.times do |j|
# Make a copy of the j-th column to localize references.
- @row_size.times do |i|
+ @row_count.times do |i|
lu_col_j[i] = @lu[i][j]
end
# Apply previous transformations.
- @row_size.times do |i|
+ @row_count.times do |i|
lu_row_i = @lu[i]
# Most of the time is spent in the following dot product.
@@ -192,13 +192,13 @@ class Matrix
# Find pivot and exchange if necessary.
p = j
- (j+1).upto(@row_size-1) do |i|
+ (j+1).upto(@row_count-1) do |i|
if (lu_col_j[i].abs > lu_col_j[p].abs)
p = i
end
end
if (p != j)
- @col_size.times do |k|
+ @column_count.times do |k|
t = @lu[p][k]; @lu[p][k] = @lu[j][k]; @lu[j][k] = t
end
k = @pivots[p]; @pivots[p] = @pivots[j]; @pivots[j] = k
@@ -207,8 +207,8 @@ class Matrix
# Compute multipliers.
- if (j < @row_size && @lu[j][j] != 0)
- (j+1).upto(@row_size-1) do |i|
+ if (j < @row_count && @lu[j][j] != 0)
+ (j+1).upto(@row_count-1) do |i|
@lu[i][j] = @lu[i][j].quo(@lu[j][j])
end
end