There *is* this in NumPy (which is the main use-case for this PEP):
numpy.matrix. But it causes headaches for everyone who uses it.

Aaron Meurer

On Thu, Feb 27, 2014 at 3:42 PM, Alexey U. Gudchenko <pr...@goodok.ru> wrote:
>
>
> On 25.02.2014 20:31, Aaron Meurer wrote:
>>
>> Some people on this list might be interested in this. Some folks are
>> giving another shot at writing a PEP to add a new operator to Python
>> for matrix multiplication. The discussion is at
>> https://github.com/numpy/numpy/pull/4351.
>>
>> Those of you who work with tensors may want to have a look as well.
>> There is talk to extending the operator to higher dimensional arrays,
>> but I feel that the discussion would be easier if it were formalized
>> into the language of tensor contractions.
>>
>> Aaron Meurer
>>
>
> Usually (in the one expression) we use only one type of the binary operator
> for the multiplication.
>
> And the example in the PEP also use only one operator '@' in some context
> without mixing with '*' operator in this expression (for the same class):
>
>       S = (H @ beta - r).T @ inv(H @ V @ H.T) @ (H @ beta - r)
>
> Moreover, I can't imagine easy the example when two types of the binary
> operators can be used simultaneously for the same class in one expression
> (or even in one block of expressions).
>
> If it is so, then it is possible maintain code and expressions to be
> readable  with the help of the switching of the context for this "*"
> operator. Just use the python's dynamical polymorphism.
>
> Example:
>
> Suppose we have a class of the array (class M). See attachment for details.
>
> And we want to use sometimes the elemente-wise product, or sometimes Cauchy
> product.
>
>
> And we want to write down expressions more readable for both cases
>
>     a = M([1, 2, 3])
>     b = M([5, 7, 11])
>     c = M([1, 2, 4])
>
>     Element wise product:
>
>     >>> a * b * c
>     [5, 28, 132]
>
>     Cauchy product:
>
>     # switch to cauchy_product
>     >>> M.mul_current = M.mul_cauchy_product
>
>     >>> a * b * c
>     [5, 27, 94]
>
>
> We can do it by switching: M.mul_current = M.mul_cauchy_product
>
> (It is possible to use class method if it have a few methods to be switched:
> __rmul__, for example)
>
> Disadvantage of this:
>
>    We can forget to switch '*' operator to the default behavior after usage,
> or this situation may occur as the result of some exception.
>
>    But may be it is possible to combine switching with the "with .. as"
> statement. (Some __enter__, __exit__ methods?)
>
>
>     Element wise product:
>     >>> a * b * c
>     [5, 28, 132]
>
>     Cauchy product:
>
>
>     >>> with M.use_cauhcy_product() as dummy:
>     >>>     a * b * c
>     [5, 27, 94]
>
>
>
> The last example is not implemented in the attachment. But I don't see the
> big problems, expect that "with...as" statement usually uses for the
> object's context, not classes.
>
> As my opinion (conclusion) I don't think that PEP for '@' operator is timely
> and not even convenient.
>
> --
> Alexey Gudchenko
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/530FB132.8030506%40goodok.ru.
>
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6Ka5qQAyz5v8E61ZcHwudXiyrcWcqU0cq3t3ofTqgB2iA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to