On Sun, Mar 9, 2014 at 12:40 PM,  <n...@vorpus.org> wrote:
> On Sunday, March 9, 2014 7:20:50 PM UTC, Jeroen Demeyer wrote:
>>
>> I think the following piece should be made more clear, I don't
>> understand what you're trying to say here:
>>
>> The problem is that the presence of two different duck-types for numeric
>> data -- one where * means matrix multiply, and one where * means
>> elementwise multiplication -- make it impossible to write generic
>> functions that can operate on arbitrary data.
>
>
> Indeed, it's clear from everyone's responses here that I at least need to
> add a new section talking about these things explicitly, and also about why
> elementwise-* is actually used so often in practice in numeric computation
> (as opposed dto symbolic comptuation), and why np.matrix is so loathed. (It
> really is though, I didn't just make that up :-) I doubt you can find a
> single developer of any numpy-using package who has anything good to say
> about it.) I'll try to get to write such a section over the next few hours;
> at least it might make a better basis for discussion.
>
> In brief, the issue is that elementwise-* is a fine convention and you can
> use it to write useful code, and matrix-multiply-* is a fine convention and

I'm not convinced * is a fine convention for element-wise
multiplication of  matrices, since there is no software I know of that
does that.    Even Matlab uses * to mean matrix multiplication:
     http://www.math.utah.edu/~eyre/computing/matlab-intro/math.html

But * is set in stone for numpy.  The motivation for your proposal is
to make your example code involving matrix multiplication of numpy
arrays easier to read/write.   I wonder if there is any way to do this
using a with statement, e.g.,


   c = a*b   # element-wise multiplication

   with numpy.mul_as_dot():
            c = a*b        # matrix multiplication


Then the exact part of the code that involves some expressions with
matrix multiplies of numpy arrays can be cleanly written with *
instead of of numpy.dot, and without having to introduce another
operator.   Is this at least technically possible?  If so, it is worth
addressing in the PEP.   It would solve the problem of coding up
certain algorithms cleanly, and it is extremely clear and explicit
what is going on when you just jump into the code.

Another issue -- imagine jumping into code and seeing @'s everywhere
-- you would have to google and figure out what is going on, which
could be hard for "@ operator".   For example, I use the @ operator
all the time in CoffeeScript, so it's a useful thing, but googling "@
operator" yields basically nothing useful about anything.

 -- William




> you can use it to write useful code, but if you then try to glue those two
> pieces of code together into a larger system you will quickly find yourself
> in hell as you have to cast objects back and forth at every function call.
> Or similarly, if you try to write a function that works regardless of
> whether it receives an elementwise-*-object or a matrix-multiply-*-object,
> then this is also very painful (suddenly you need lots of type-checking and
> if statements scattered around every single function you write, it's
> horrible and no-one is willing to do it).
>
> This doesn't get into the reasons why numpy goes with the elementwise-*
> convention, but it's why it seems important to have *some* convention.
>
> (Some of the reasons for why numpy goes with elementwise-* are here:
> https://github.com/njsmith/numpy/blob/matmul-pep/doc/neps/return-of-revenge-of-matmul-pep.rst#choice-of-operation
> ; the other important reason that that section doesn't talk about as much as
> it could is that numpy has n-dimensional arrays, while matrix multiplication
> is only really natural for 2d arrays.)
>
> -n
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-devel+unsubscr...@googlegroups.com.
> To post to this group, send email to sage-devel@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-devel.
> For more options, visit https://groups.google.com/d/optout.



-- 
William Stein
Professor of Mathematics
University of Washington
http://wstein.org

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to