Skip to content

Commit

Permalink
Fixes #602, missing Array#sum in NMatrix#block_diagonal (MRI only, no…
Browse files Browse the repository at this point in the history
…t JRuby)
  • Loading branch information
translunar committed Dec 14, 2017
1 parent e63cd52 commit 056dfb0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/nmatrix/shortcuts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -494,11 +494,11 @@ def block_diagonal(*params)
block_sizes << b.shape[0]
end

block_diag_mat = NMatrix.zeros(block_sizes.sum, options)
block_diag_mat = NMatrix.zeros(block_sizes.inject(0,:+), options)
(0...params.length).each do |n|
# First determine the size and position of the n'th block in the block-diagonal matrix
block_size = block_sizes[n]
block_pos = block_sizes[0...n].sum
block_pos = block_sizes[0...n].inject(0,:+)
# populate the n'th block in the block-diagonal matrix
(0...block_size).each do |i|
(0...block_size).each do |j|
Expand Down

0 comments on commit 056dfb0

Please sign in to comment.