On Thu, Jun 5, 2008 at 4:20 PM, Ondrej Certik <[EMAIL PROTECTED]> wrote:
> On Thu, Jun 5, 2008 at 3:50 PM, Robert Cimrman <[EMAIL PROTECTED]> wrote:
>>
>> Hi,
>>
>> In [16]: sympy.__version__
>> Out[16]: '0.5.15-hg'
>> In [19]: K = sympy.Matrix(nm.array(1, ndmin = 2))
>> In [20]: sympy.sympify(K)
>> ...
>> NotImplementedError: matrix support
>>
>> Is there a reason for this? Why a Matrix instance is not just passed
>> along, since it is already a sympy object?
>
> The patch fixing this is trivial:
>
> $ hg di
> diff --git a/sympy/core/sympify.py b/sympy/core/sympify.py
> --- a/sympy/core/sympify.py
> +++ b/sympy/core/sympify.py
> @@ -107,7 +107,7 @@ def sympify(a, sympify_lists=False, loca
> if isinstance(a, Polynomial):
> return a
> if isinstance(a, Matrix):
> - raise NotImplementedError('matrix support')
> + return a
>
> if not isinstance(a, str):
> # At this point we were given an arbitrary expression
>
> Is anyone against committing it? All tests pass.
>
>>
>> Then, what is the preferred way of dealing with symbolic matrices w.r.t.
>> their usability in sympy functions:
>> - use regular lists (numpy arrays would do too?) and call sympify() with
>> sympify_lists=True at the beginning of a function accepting a
>> matrix-like argument
>> - use Matrix
>> Ideally, both should work the same way(?)
>
> It depends what you want to do.
>
> - for simple stuff I suggest to just use lists
> - if you need linear algebra (which I think you almost always need),
> I'd suggest Matrices
> - in some special (numerical) cases numpy arrays could be used too
>
> I just discovered we probably need to think about this:
>
> In [1]: a = Matrix((1, x), (2, y))
>
> In [2]: from numpy import array
>
> In [3]: a
> Out[3]:
> ⎡1 x⎤
> ⎣2 y⎦
>
> In [4]: Matrix(sin(array(a)))
> Out[4]:
> ⎡sin(1) sin(x)⎤
> ⎣sin(2) sin(y)⎦
>
> In [5]: sin(a)
> [...]
>
> AttributeError: 'Matrix' object has no attribute 'is_Number'
>
>
> What should [5] return? The same as [4] or the sin of a Matrix, which
> is defined as sin(A) = Q*sin(D)*Q^T if A = Q*D*Q^T and D is
> diagonal, so sin(D) is just the D with sin applied to the diagonal
> terms.
numpy must have exactly the same problem btw. So let's do the same as
numpy to be compatible, e.g. I am for returning [4]. And let's provide
some methods for returning [5] if needed.
Ondrej
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---