Issue #13208 has been updated by stomar (Marcus Stollsteimer).


Granted, in the case of #zero? returning true might suggest itself, but is "nothing" really the same as "zero"...? If there was a method Vector.one with Vector.one(3) => Vector[1, 1, 1], should Vector.one(0).one? be true? (All the values in the vector are 1, even if there aren't that many values there...). In that case, for Vector[] both #one? and #zero? would be true at the same time...

Generally speaking: I'm a bit sceptical about allowing zero size for these creator methods and about allowing these properties for zero size vectors/matrices, and I'm not sure what mathematics says about it.

It's easier to demonstrate the possible problems using the Matrix class (which has more methods to play around). The current behavior is a bit strange and contradictory:

``` ruby
size = 0

z = Matrix.zero(size)
z.zero? && z.orthogonal? && z.unitary?  # => true  (a zero matrix that's also orthogonal!)
z.det    # => 1  (should be 0 for *any* `size')

i = Matrix.identity(size)
i.zero?  # => true  (should be false for *any* `size')

# and of course:
i == z  # true  (!)
```

The question is whether the methods that generate those special matrices/vectors should allow size 0 (since the generated objects do not have all the expected properties), and/or whether the methods that query these properties should return a value or not (since the property might not be very meaningful).


----------------------------------------
Feature #13208: Vector.zero(n) and vector.zero?
https://bugs.ruby-lang.org/issues/13208#change-63619

* Author: qitar888 (Chia-sheng Chen)
* Status: Closed
* Priority: Normal
* Assignee: marcandre (Marc-Andre Lafortune)
* Target version: 
----------------------------------------
Found that I need this recently, and class `Matrix` has these two function while `Vector` not.
So I add two function based on `Matrix` counterpart and also add test.

Usage

``` ruby
require 'matrix'
v = Vector.zero(3)  # => Vector[0, 0, 0]
v.zero?  # => true
w = Vector[1, 0, 0]
w.zero?  # => false
```

---Files--------------------------------
0001-Add-Vector.zero-n-and-vector.zero.patch (2.06 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>