summaryrefslogtreecommitdiff
path: root/lib/matrix.rb
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-11-20 02:18:12 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-11-20 02:18:12 +0000
commitaa95a42190fbe9f9990a60d722366a5e4d89920b (patch)
tree2f874207010641795868ae654ccfb1058b0025a1 /lib/matrix.rb
parente33b1690d06f867e45750bd8e3e8b06d78b5bc26 (diff)
downloadruby-aa95a42190fbe9f9990a60d722366a5e4d89920b.tar.gz
lib/matrix: Add explicit coercion #to_matrix
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60857 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/matrix.rb')
-rw-r--r--lib/matrix.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/matrix.rb b/lib/matrix.rb
index c6efa5d91a..8c22d2b208 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -1381,6 +1381,13 @@ class Matrix
end
#
+ # Explicit conversion to a Matrix. Returns self
+ #
+ def to_matrix
+ self
+ end
+
+ #
# Returns an array of arrays that describe the rows of the matrix.
#
def to_a
@@ -1494,6 +1501,10 @@ class Matrix
def self.coerce_to_int(obj)
coerce_to(obj, Integer, :to_int)
end
+
+ def self.coerce_to_matrix(obj)
+ coerce_to(obj, Matrix, :to_matrix)
+ end
end
include CoercionHelper
@@ -2039,6 +2050,13 @@ class Vector
@elements.dup
end
+ #
+ # Return a single-column matrix from this vector
+ #
+ def to_matrix
+ Matrix.column_vector(self)
+ end
+
def elements_to_f
warn "#{caller(1, 1)[0]}: warning: Vector#elements_to_f is deprecated"
map(&:to_f)