diff options
author | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-14 20:09:30 +0000 |
---|---|---|
committer | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-03-14 20:09:30 +0000 |
commit | 666df1459406ad03d95105e228841d5bbfbe6e15 (patch) | |
tree | f3a1652c9333ce4c42e9c00b3e17e17c414826e2 /lib/matrix.rb | |
parent | 31e74d51fbb0d6662e6618b0ae06e3cede68adf0 (diff) | |
download | bundler-666df1459406ad03d95105e228841d5bbfbe6e15.tar.gz |
* lib/matrix.rb: Add Vector.zero and Vector#zero?
Patch by Chia-sheng Chen [#13208]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/matrix.rb')
-rw-r--r-- | lib/matrix.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/matrix.rb b/lib/matrix.rb index eaa4bfc6e1..77c35b3475 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -1685,6 +1685,7 @@ end # * Vector.[](*array) # * Vector.elements(array, copy = true) # * Vector.basis(size: n, index: k) +# * Vector.zero(n) # # To access elements: # * #[](i) @@ -1697,6 +1698,7 @@ end # * #angle_with(v) # * Vector.independent?(*vs) # * #independent?(*vs) +# * #zero? # # Vector arithmetic: # * #*(x) "is matrix or number" @@ -1769,6 +1771,17 @@ class Vector end # + # Return a zero vector. + # + # Vector.zero(3) => Vector[0, 0, 0] + # + def Vector.zero(size) + raise ArgumentError, "invalid size (#{size} for 0..)" if size < 0 + array = Array.new(size, 0) + new convert_to_array(array, false) + end + + # # Vector.new is private; use Vector[] or Vector.elements to create. # def initialize(array) @@ -1882,6 +1895,13 @@ class Vector self.class.independent?(self, *vs) end + # + # Returns +true+ iff all elements are zero. + # + def zero? + all?(&:zero?) + end + #-- # COMPARING -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #++ |