Method: CooCoo::NMatrix::Vector#each_slice

Defined in:
lib/coo-coo/math.rb

#each_slice(n, &block) ⇒ Object



443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# File 'lib/coo-coo/math.rb', line 443

def each_slice(n, &block)
  if block
    last_slice = (size / n.to_f).ceil.to_i
    
    @elements.each_slice(n).with_index do |slice, i|
      if i == last_slice - 1
        slice = slice + Array.new(n - slice.size)
      end
      
      block.call(self.class[slice])
    end
  else
    to_enum(__method__, n)
  end
end