Project

General

Profile

Feature #13208 ยป 0001-Add-Vector.zero-n-and-vector.zero.patch

qitar888 (Chia-sheng Chen), 02/11/2017 07:54 PM

View differences:

lib/matrix.rb
# * Vector.[](*array)
# * Vector.elements(array, copy = true)
# * Vector.basis(size: n, index: k)
# * Vector.zero(n)
#
# To access elements:
# * #[](i)
......
# * #angle_with(v)
# * Vector.independent?(*vs)
# * #independent?(*vs)
# * #zero?
#
# Vector arithmetic:
# * #*(x) "is matrix or number"
......
end
#
# Return a zero vector.
#
# Vector.zero(3) => Vector[0, 0, 0]
#
def Vector.zero(size)
raise ArgumentError, "invalid size (#{size} for 1..)" if size < 1
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)
......
self.class.independent?(self, *vs)
end
#
# Returns +true+ iff all elements are zero.
#
def zero?
all?(&:zero?)
end
#--
# COMPARING -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#++
test/matrix/test_vector.rb
@w1 = Vector[2,3,4]
end
def test_zero
assert_equal Vector[0, 0, 0, 0], Vector.zero(4)
assert_raise(ArgumentError) { Vector.zero(-1) }
assert Vector[0, 0, 0, 0].zero?
end
def test_basis
assert_equal(Vector[1, 0, 0], Vector.basis(size: 3, index: 0))
assert_raise(ArgumentError) { Vector.basis(size: -1, index: 2) }
    (1-1/1)