Skip to content

Commit deb5648

Browse files
committed
fixed pretty print format for matrices
1 parent 5a1fd1f commit deb5648

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

lib/nmatrix/nmatrix.rb

+18-16
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,14 @@ def pretty_print(q) #:nodoc:
189189
end
190190
end
191191
else # dim 2
192-
q.group(0, "\n[\n", "]") do
193-
self.each_row.with_index do |row,i|
194-
q.group(1, " [", "]") do
195-
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]) }
192+
q.group(0, "\n[\n ", "]") do
193+
self.each_row.with_index do |row, i|
194+
q.group(1, " [", "]\n") do
195+
q.seplist(row.to_a, -> { q.text ", " }, :each_with_index) do |v,j|
196+
q.text v.inspect.rjust(longest[j])
197+
end
196198
end
197-
q.breakable
199+
q.breakable unless i + 1 == self.shape[0]
198200
end
199201
end
200202
end
@@ -269,14 +271,14 @@ def cols
269271
end
270272

271273
# Return the main diagonal or antidiagonal a matrix. Only works with 2D matrices.
272-
#
274+
#
273275
# == Arguments
274-
#
275-
# * +main_diagonal+ - Defaults to true. If passed 'false', then will return the
276+
#
277+
# * +main_diagonal+ - Defaults to true. If passed 'false', then will return the
276278
# antidiagonal of the matrix.
277-
#
279+
#
278280
# == References
279-
#
281+
#
280282
# * http://en.wikipedia.org/wiki/Main_diagonal
281283
def diagonal main_diagonal=true
282284
diag_size = [cols, rows].min
@@ -367,9 +369,9 @@ def complex_dtype?
367369

368370
##
369371
# call-seq:
370-
#
372+
#
371373
# object_dtype?() -> Boolean
372-
#
374+
#
373375
# Checks if dtype is a ruby object
374376
def object_dtype?
375377
dtype == :object
@@ -960,9 +962,9 @@ def inject(sym)
960962
return self.map_stored.inject(sym)
961963
end
962964

963-
# Returns the index of the first occurence of the specified value. Returns
965+
# Returns the index of the first occurence of the specified value. Returns
964966
# an array containing the position of the value, nil in case the value is not found.
965-
#
967+
#
966968
def index(value)
967969
index = nil
968970

@@ -972,7 +974,7 @@ def index(value)
972974
index = yields
973975
break
974976
end
975-
end
977+
end
976978

977979
index
978980
end
@@ -995,7 +997,7 @@ def clone_structure(capacity = nil)
995997
#
996998
# call-seq:
997999
# repeat(count, axis) -> NMatrix
998-
#
1000+
#
9991001
# * *Arguments* :
10001002
# - +count+ -> how many times NMatrix should be repeated
10011003
# - +axis+ -> index of axis along which NMatrix should be repeated

0 commit comments

Comments
 (0)