Class: Matrix
- Inherits:
-
Object
- Object
- Matrix
- Defined in:
- lib/quantum_ruby.rb
Overview
Overrides for base ruby base classes
Direct Known Subclasses
Instance Method Summary collapse
-
#kronecker(m) ⇒ Object
Takes two arbitrary sized resulting in a block matrix according to the Kronecker Product Details: en.wikipedia.org/wiki/Kronecker_product.
Instance Method Details
#kronecker(m) ⇒ Object
Takes two arbitrary sized resulting in a block matrix according to the Kronecker Product Details: en.wikipedia.org/wiki/Kronecker_product
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/quantum_ruby.rb', line 11 def kronecker(m) raise ErrOperationNotDefined, [__method__, self.class, m.class] unless m.is_a?(Matrix) a = Array.new(row_count * m.row_count) { Array.new(column_count * m.column_count) } count_ver = 0 row_count.times do |i| count_hor = 0 column_count.times do |j| m.row_count.times do |p| m.column_count.times do |q| a[i + p + count_ver][j + q + count_hor] = self[i, j] * m[p, q] end end count_hor += m.column_count - 1 end count_ver += m.row_count - 1 end self.class[*a] end |