Skip to content

Commit 16af7d1

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

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

lib/nmatrix/nmatrix.rb

+14-14
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ def pretty_print(q) #:nodoc:
189189
end
190190
end
191191
else # dim 2
192-
q.group(0, "\n[\n", "]") do
192+
q.group(0, "\n[\n ", "]") do
193193
self.each_row.with_index do |row,i|
194-
q.group(1, " [", "]") do
194+
q.group(1, " [", "]\n") do
195195
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]) }
196196
end
197-
q.breakable
197+
q.breakable unless i == self.shape[0] - 1
198198
end
199199
end
200200
end
@@ -269,14 +269,14 @@ def cols
269269
end
270270

271271
# Return the main diagonal or antidiagonal a matrix. Only works with 2D matrices.
272-
#
272+
#
273273
# == Arguments
274-
#
275-
# * +main_diagonal+ - Defaults to true. If passed 'false', then will return the
274+
#
275+
# * +main_diagonal+ - Defaults to true. If passed 'false', then will return the
276276
# antidiagonal of the matrix.
277-
#
277+
#
278278
# == References
279-
#
279+
#
280280
# * http://en.wikipedia.org/wiki/Main_diagonal
281281
def diagonal main_diagonal=true
282282
diag_size = [cols, rows].min
@@ -367,9 +367,9 @@ def complex_dtype?
367367

368368
##
369369
# call-seq:
370-
#
370+
#
371371
# object_dtype?() -> Boolean
372-
#
372+
#
373373
# Checks if dtype is a ruby object
374374
def object_dtype?
375375
dtype == :object
@@ -960,9 +960,9 @@ def inject(sym)
960960
return self.map_stored.inject(sym)
961961
end
962962

963-
# Returns the index of the first occurence of the specified value. Returns
963+
# Returns the index of the first occurence of the specified value. Returns
964964
# an array containing the position of the value, nil in case the value is not found.
965-
#
965+
#
966966
def index(value)
967967
index = nil
968968

@@ -972,7 +972,7 @@ def index(value)
972972
index = yields
973973
break
974974
end
975-
end
975+
end
976976

977977
index
978978
end
@@ -995,7 +995,7 @@ def clone_structure(capacity = nil)
995995
#
996996
# call-seq:
997997
# repeat(count, axis) -> NMatrix
998-
#
998+
#
999999
# * *Arguments* :
10001000
# - +count+ -> how many times NMatrix should be repeated
10011001
# - +axis+ -> index of axis along which NMatrix should be repeated

0 commit comments

Comments
 (0)