Skip to content

Commit 9dd0eee

Browse files
committed
2 parents 6e3b527 + b482f4c commit 9dd0eee

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/crystaledge/matrix.cr

+30-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ module CrystalEdge
172172
h.times do |c|
173173
cell = T.new 0
174174
width.times do |o|
175-
cell += self[o,c] * other[r, o]
175+
cell += self[o, c] * other[r, o]
176176
end
177177
result[r, c] = cell
178178
end
@@ -299,6 +299,35 @@ module CrystalEdge
299299
def {{key}}!(*values)
300300
copy_from {{key}}(*values)
301301
end
302+
303+
# Return string representation of the matrix
304+
def to_s
305+
# Format matrix by taking longest number
306+
longer = 0
307+
W.times do |row|
308+
H.times do |col|
309+
if longer < "#{@matrix[index(row, col)]} ".size
310+
longer = "#{@matrix[index(row, col)]} ".size
311+
end
312+
end
313+
end
314+
# Printing matrix
315+
W.times do |row|
316+
str = "| "
317+
H.times do |col|
318+
if col != H-1
319+
str += "#{@matrix[index(row, col)]} "
320+
else
321+
str += "#{@matrix[index(row, col)]}"
322+
end
323+
(longer - "#{@matrix[index(row, col)]} ".size).times do
324+
str += " "
325+
end
326+
end
327+
str += " |"
328+
return str
329+
end
330+
end
302331
{% end %}
303332
end
304333

0 commit comments

Comments
 (0)