octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #51333] Reductions on an empty matrix is incon


From: Joel Dahne
Subject: [Octave-bug-tracker] [bug #51333] Reductions on an empty matrix is inconsistent
Date: Wed, 28 Jun 2017 09:21:13 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0

URL:
  <http://savannah.gnu.org/bugs/?51333>

                 Summary: Reductions on an empty matrix is inconsistent
                 Project: GNU Octave
            Submitted by: urathai
            Submitted on: Wed 28 Jun 2017 01:21:12 PM UTC
                Category: Octave Function
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Matlab Compatibility
                  Status: None
             Assigned to: None
         Originator Name: 
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 4.2.1
        Operating System: GNU/Linux

    _______________________________________________________

Details:

Some of the reduction functions have inconsistent handling of empty matrices.
They also differ slightly to how Matlab handles it. The function I have looked
at are sum, sumsq, prod and dot but it might hold true for other reduction
functions as well.

Both sum and prod have the convention that the empty matrix returns the unit,
i.e.


> sum ([])
ans = 0
> sumsq ([])
ans = 0
> prod ([])
ans = 1


But this does not hold true for dot


> dot ([], [])
ans = [](1x0)


I think it would be more natural for dot to also return 0 here. This is also
how Matlab does it


## In Matlab
> dot ([], [])
ans = 0


Further I noticed that Matlab and Octave handles the empty matrix differently
when a dimension is specified. In Octave we have

> sum ([])
ans = 0
> sum ([], 1)
ans = 0
> sum ([], 2)
ans = [](0x1)


Looking at the code for Octaves reduction function we in fact have a explicit
conversion from [] to a matrix of size 1x0 (commented as an inconsistency). In
Matlab we instead have


## In Matlab
> sum ([])
ans = 0
> sum ([], 1)
ans = [](1x0)
> sum ([], 2)
ans = [](0x1)


When no dimension is specified it handles the empty matrix in a special way.
But when a dimension is specified it handles it like any other matrix.




    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?51333>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]