Project

General

Profile

Feature #10077 » Implement_Matrix#column_merge.patch

gogotanaka (Kazuki Tanaka), 07/21/2014 02:51 AM

View differences:

lib/matrix.rb
# * #minor(*param)
# * #first_minor(row, column)
# * #cofactor(row, column)
# * #column_merge(*matrices)
#
# Properties of a matrix:
# * #diagonal?
......
det_of_minor * (-1) ** (row + column)
end
#
# Merge matrices between columns.
#
# Matrix[[1, 2], [3, 4]].column_merge(Matrix[[5, 6]])
# => 1 2
# 3 4
# 5 6
#
def column_merge(*matrices)
if matrices.any?{|m| m.column_size != column_size }
raise ErrDimensionMismatch, "all matrices should have same column size"
end
new_matrix [self, *matrices].map(&:to_a).flatten(1)
end
#--
# TESTING -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#++
(1-1/6)