On 24.03.2012 20:19, [email protected] wrote:
> How about making MatExpr evaluate by default as it is the thing most
> frequently requested at the moment and leaving the rest until the need
> for it arises?
>
As I understand the main target to evaluate ImmutableMatrix by default
is to show the result of expression.
I agreed that it is better to see the result with in more convinient
form and key details.
Meanwhile at [1] was formulated arguments contra, and pro unevaluation
variant. I am warry why they are ignored.
Nevertheless, may be it is possible to join advantages of both variants
(non-evaluated by default and evaluated by default).
When I learn the sequences ans series I meet the similar problem, and
here are my suggestions:
For this we can just separate the task of showing of and the task
manipulation with expressions.
When I construct the expression (mul or add), I keep them in unevualeted
form as an expression, but every expression has `__getitem__` index,
which runs the calculation of desirable element (and, cache it).
If we work with such expressions in interactive mode, then printer
method form matrix used and it calls `__getitem__`, so we obtain the
readable answer.
Consider example (on example of ImmutableMatrix):
>>> a = ImmutableMatrix(3*eye(3))
# a <-- 3*ImmutableMatrix(...)
# here automatic simplification on the
# fly, which carring out common coeff.
# The "..." is written, because I don't know internal structure of the
# created object .
>>> b = 2*ImmutableMatrix(diag(1, 5, 6))
# b <-- 2*ImmutableMatrix(...)
>>> c = a*b
# c <-- 6*MatMul(ImmutableMatrix(...), ImmutableMatrix(...)
Note, so far we have not done any calculations with matrices.
No reasons for it.
We just construct the expression, simplify trivial things, if needed.
But if what to know (to show, or use in further calculations) then
result in readable form then we'll see:
>>> c[1:2]
30
>>> c
[6, 0, 0]
[0, 30, 0]
[0, 0, 36]
When we input "c[1:2]" then the
* `__getitem__ calls`
* the process of calculation of this element runs
(it is well-defined), which use only necessary calculations,
* then the result is cached,
* then it is returned and printed by printing system.
When we run "c", then (ordinary) printer for matrices is runs, which
also use __getitem__.
So, we can tune the printer system, and the expression behavior
independently during manipulation.
[1] http://code.google.com/p/sympy/issues/detail?id=3180
--
Alexey Gudchenko
--
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.