Hi David,
MatrixExprs represent matrices without explicit elements. I'm modifying the
first half of Chris' example above
>>> from sympy import MatrixSymbol
>>> n = Symbol('n')
>>> X = MatrixSymbol('X', n, n)
>>> Y = MatrixSymbol('Y', n, n)
>>> (X.T*X).I*Y
X^-1*X'^-1*Y
The result here is an expression tree from which you could generate code.
I'm actively working on this and would be interested in hearing more about
what you're working on.
MatrixExprs don't currently contain an elementwise product but it could be
added if there was a need. I've added an issue for this topic here
http://code.google.com/p/sympy/issues/detail?id=3447
I'm planning to take a bit of time to work on MatrixExprs this week. If you
have some easy-to-implement feature requests this would be a good time. I'd
be happy to see symbolic matrix expressions in wider use. I think that
they're a good idea.
Other options:
1. There is an old `Indexed` class in SymPy for representing and generating
code for indexed expressions. I'm sure that this would
support element-wise product. I hope that it would also support matrix
multiply but I'm not sure what the state of the module is. Andy Terrel
might have more information here.
2. There is the Theano project which actively thinks about code generation
for matrix and array expressions. They tend to target people who don't do
their own code generation but they certainly have a language that can
represent the sorts of operations for which you're asking.
Best,
-Matthew
On Sun, Oct 21, 2012 at 1:43 AM, David Ketcheson <[email protected]> wrote:
> Thanks. But I don't want to specify the size of the matrices, and I don't
> want the result to be in terms of matrix elements; I want it to still
> appear as A*(B.*C) or something similar, as the purpose is generation of
> MATLAB or numpy code that won't index into the matrices. I just need two
> different kinds of multiplication operators for non-commutative symbols.
>
> David
>
>
> On Sunday, October 21, 2012 11:31:12 AM UTC+3, smichr wrote:
>
>> On Sun, Oct 21, 2012 at 1:58 PM, David Ketcheson <[email protected]>
>> wrote:
>> > I would like to express formulas that involve both traditional
>> matrix-matrix
>> > multiplication and elementwise multiplication. To be clear, these are
>> the
>>
>> The following is from the docs on Matrix Expressions:
>>
>>
>> >>> from sympy import MatrixSymbol, Matrix
>> >>> X = MatrixSymbol('X', 3, 3)
>> >>> Y = MatrixSymbol('Y', 3, 3)
>> >>> (X.T*X).I*Y
>> X^-1*X'^-1*Y
>>
>> >>> Matrix(X)
>> [X_00, X_01, X_02]
>> [X_10, X_11, X_12]
>> [X_20, X_21, X_22]
>>
>> >>> (X*Y)[1, 2]
>> X_10*Y_02 + X_11*Y_12 + X_12*Y_22
>>
>> So yes, you can do abstract value-agnostic manipulations. Although
>> there is a matrix_multiply_elementwise function that operates on
>> regular matrices, I don't think that there is an implementation yet
>> for MatrixExpr.
>>
>> Chris
>>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sympy/-/mcrYhSuqpukJ.
>
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.