Skip to content

Commit

Permalink
fixed pretty print format for matrices (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aelphy authored and translunar committed Aug 5, 2016
1 parent e3e5d12 commit 7f3fa5d
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions lib/nmatrix/nmatrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,14 @@ def pretty_print(q) #:nodoc:
end
end
else # dim 2
q.group(0, "\n[\n", "]") do
self.each_row.with_index do |row,i|
q.group(1, " [", "]") do
q.seplist(self.dim > 2 ? row.to_a[0] : row.to_a, lambda { q.text ", " }, :each_with_index) { |v,j| q.text v.inspect.rjust(longest[j]) }
q.group(0, "\n[\n ", "]") do
self.each_row.with_index do |row, i|
q.group(1, " [", "]\n") do
q.seplist(row.to_a, -> { q.text ", " }, :each_with_index) do |v,j|
q.text v.inspect.rjust(longest[j])
end
end
q.breakable
q.breakable unless i + 1 == self.shape[0]
end
end
end
Expand Down Expand Up @@ -269,14 +271,14 @@ def cols
end

# Return the main diagonal or antidiagonal a matrix. Only works with 2D matrices.
#
#
# == Arguments
#
# * +main_diagonal+ - Defaults to true. If passed 'false', then will return the
#
# * +main_diagonal+ - Defaults to true. If passed 'false', then will return the
# antidiagonal of the matrix.
#
#
# == References
#
#
# * http://en.wikipedia.org/wiki/Main_diagonal
def diagonal main_diagonal=true
diag_size = [cols, rows].min
Expand Down Expand Up @@ -367,9 +369,9 @@ def complex_dtype?

##
# call-seq:
#
#
# object_dtype?() -> Boolean
#
#
# Checks if dtype is a ruby object
def object_dtype?
dtype == :object
Expand Down Expand Up @@ -976,9 +978,9 @@ def inject(sym)
return self.map_stored.inject(sym)
end

# Returns the index of the first occurence of the specified value. Returns
# Returns the index of the first occurence of the specified value. Returns
# an array containing the position of the value, nil in case the value is not found.
#
#
def index(value)
index = nil

Expand All @@ -988,7 +990,7 @@ def index(value)
index = yields
break
end
end
end

index
end
Expand All @@ -1011,7 +1013,7 @@ def clone_structure(capacity = nil)
#
# call-seq:
# repeat(count, axis) -> NMatrix
#
#
# * *Arguments* :
# - +count+ -> how many times NMatrix should be repeated
# - +axis+ -> index of axis along which NMatrix should be repeated
Expand Down

0 comments on commit 7f3fa5d

Please sign in to comment.