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

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

[Octave-bug-tracker] [bug #53675] Warning/documentation of mtimes with n


From: Michael Leitner
Subject: [Octave-bug-tracker] [bug #53675] Warning/documentation of mtimes with non-matrix arguments
Date: Tue, 17 Apr 2018 07:31:30 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0

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

                 Summary: Warning/documentation of mtimes with non-matrix
arguments
                 Project: GNU Octave
            Submitted by: mleitner
            Submitted on: Tue 17 Apr 2018 11:31:28 AM UTC
                Category: Documentation
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Documentation
                  Status: None
             Assigned to: None
         Originator Name: 
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 4.2.1
        Operating System: Any

    _______________________________________________________

Details:

I do not know whether I am searching incorrectly, but it seems to me that all
that the documentation has to say about mtimes is "Return the matrix
multiplication product of inputs." But what if the arguments are not matrices,
that is, have more than two dimensions? By testing it seems to me that 


a*b


is exactly equivalent (in terms of results, but also under which conditions it
errors out) to


a(:,:)*b(:,:)


(I do not know whether or where this syntax is documented), which in turn is
equivalent to 


reshape(a,size(a,1),[])*reshape(b,size(b,1),[])


Even the error message is the same: for 


a=rand(1,3,2);
b=rand(3,3,3);


all three give "error: operator *: nonconformant arguments (op1 is 1x6, op2 is
3x9)". 

I have been using Octave now eight years nearly daily and did not know about
that feature, so this should be documented at least in section "8.3 Arithmetic
operators", but perhaps one could add a subsection under "8 Expressions"
called something like "Advanced trickery", where such things (also including
indexing by two or more colons) is presented. Further, perhaps the error
checking should be done a bit earlier, so that in the above-mentioned example
the actual dimensions of the input arguments are reported. And finally,
perhaps it would be good to emit a warning whenever
(length(size(a))>2)||(length(size(b))>2), because this is probably often
unintended.

However, I do not want to argue that under the above-mentioned condition this
should raise an error, as the behaviour is actually useful: for instance, it
allows me to have vectors organized in more dimensions, and to transform them
all by a simple matrix multiplication from the left with a subsequent reshape,
as opposed to have to reshape each argument and introduce singleton
dimensions, do an element-wise multiplication with broadcasting, sum over the
relevant dimension, and do a final reshape.




    _______________________________________________________

Reply to this item at:

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

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




reply via email to

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