Live data from Hacker News

PEP 465 – Dedicated infix operators for matrix multiplication and matrix power

python.org

11–20 of 42 posts

Re: PEP 465 – Dedicated infix operators for matrix multiplication and matrix power

#11
post #4

Great! Minor quibble: the underlying method names should not mention `mat` (e.g. `__matmul__`); instead mentioning the shape of the operator (e.g. `__atmul__`).

This. It allows for the general meaning to be conveyed (it's numeric, kind of multiplicative, uses @ symbol) without restricting it to a particular use case. This allows other users to define their own meanings for @ in a variety of contexts.

We could even have a reverse mnemonic: AlTernate Multiplication

Re: PEP 465 – Dedicated infix operators for matrix multiplication and matrix power

#13
post #4

Great! Minor quibble: the underlying method names should not mention `mat` (e.g. `__matmul__`); instead mentioning the shape of the operator (e.g. `__atmul__`).

that might be a good idea, or a little strange.

many existing python infix boolean operators resolve to method names based on the meaning, rather than the symbol. e.g. `a + b` resolves to `a.__add__(b)` rather than `a.__plus__(b)`, `x * * y` resolves to `x.__pow__(y)` rather than `x.__asteriskasterisk__(y)`, say. so arguably it would be consistent to name @ after the common meaning also.

http://docs.python.org/2/reference/datamodel.html#emulating-...

on the other hand, "consistency is not necessarily a virtue: one can be consistently obnoxious" - C.A.B. Smith

that said, i like the idea that @ should be more general than just for matrices. an arbitrary infix boolean operation, neither necessarily commutative nor invertible.

even when talking about matrix multiplication, generalising slightly from arrays to abstract elements of vector spaces, and from matrices to linear transformations between vector spaces leaves you writing the same kinds of expressions that compose linear transformations without anything necessarily being represented as a matrix.

Re: PEP 465 – Dedicated infix operators for matrix multiplication and matrix power

#14

That's funny. If there is one thing that Python users do more after than diss R - it's steal from R.

Matlab is a horror but one thing they do do well is .* and * for the two multiplies.

Julia also adopted this syntax, and I'm not sure if I like it. In numpy at least, I find myself doing element-wise multiplication much more frequently than matrix multiplication, so '.*' always feels clumsy. I'd rather have special syntax for the matrix multiply (and I was a long time matlab user before moving to numpy).

Re: PEP 465 – Dedicated infix operators for matrix multiplication and matrix power

#15
post #8

If you're really determined, you can use `.` as an operator via __getattr__ and inspect :p

ugh.

very loosely related, this reminds me of calling R functions from python that take keyword arguments with dots in their names.

    >>> f(hello.world=123)
      File "", line 1
    SyntaxError: keyword can't be an expression
so instead:

    >>> f(**{'hello.world':123})

Re: PEP 465 – Dedicated infix operators for matrix multiplication and matrix power

#16
post #5

Earlier quoted context omitted.

I have not witnessed this behavior, but it would be perfectly logical to dismiss R while absorbing its features – R is a domain-specific language (statistics) while Python is a general purpose programming language. A GP language will always have a larger useful scope than a DSL.

Calling R a DSL is like insisting that Python is just a scripting language.

R is “for statistical computing and graphics”¹.

1) http://www.r-project.org/

Re: PEP 465 – Dedicated infix operators for matrix multiplication and matrix power

#17
post #16

Earlier quoted context omitted.

Calling R a DSL is like insisting that Python is just a scripting language.

R is “ for statistical computing and graphics ”¹. 1) http://www.r-project.org/

Sure, the facilities for statistics and plotting are well exposed. But all the features you need for 'general purpose' are in there too, and they aren't awkward to access (at least, relative to anything else).

Re: PEP 465 – Dedicated infix operators for matrix multiplication and matrix power

#20
I'm kind of baffled by this. Python has operator overloading, so what's wrong with using * for matrix multiplication? I know there's a bit in the PEP that claims to answer this, but I can't understand their argument. Can someone explain?
Post reply on HN