Sha256: a15eb59b7216a3e8271abda9c09926b3e6432f30a668e8fd9371f5f2c9548d2d
Contents?: true
Size: 1.01 KB
Versions: 2
Compression:
Stored size: 1.01 KB
Contents
module Silicium module Sparse # addition for SparseMatrix class class SparseMatrix ## # @param [SparseMatrix] matrix - second matrix for adding # @raise [ArgumentError] If the size of the first matrix doesn't # match the size of the second matrix # @return [SparseMatrix] Matrix as the sum of the other two matrices # # Makes the sum of two matrix def adding(matrix) raise 'wrong argument' if @n != matrix.m res = SparseMatrix.new(@n, @m) (0..@n).each { |i| help_row1 = get_row(i) help_row2 = matrix.get_row(i) res_row = Array.new(@m, 0) j = 0 help_row1.each do |elem| res_row[j] = elem + help_row2[j] j = j + 1 end k = 0 res_row.each do |elem| if (elem != 0) res.add(i, k, elem) end k = k+1 end } res end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
silicium-0.0.22 | lib/silicium/adding.rb |
silicium-0.0.21 | lib/silicium/adding.rb |