Closed GoogleCodeExporter closed 9 years ago
The attached file implements MetaToClassMethod decorator to replace Method
in previous file.
Original comment by pearu.peterson
on 21 Dec 2007 at 9:59
Attachments:
Moved the test script to svn under research directory.
Renamed decorator to InstanceClassMethod to reflect its
true nature. See
http://sympycore.googlecode.com/svn/trunk/research/InstanceClassMethod_decorator.py
for examples and docs.
Original comment by pearu.peterson
on 22 Dec 2007 at 12:51
(02:46:12 PM) ondrej: I was looking at the InstanceClassMethod(object):
(02:46:40 PM) ondrej: I don't want to mess up issues with my question - why is
it
needed to call the same method from classes and instances and metaclasses?
(03:58:29 PM) pearu: when a function class is a Basic object at the same time as
classobject then methods in a function class must have two different types of
implementations: one for the case where functions is treated as a Basic object
and
one for the case where functions is treated as class object
(04:00:33 PM) ondrej: but why do you need to call the same function both in the
object and the class?
(04:01:58 PM) pearu: there are many methods that require that, for example,
Sin.tostr() should result in `Sin` and Sin(x).tostr() results in `Sin(x)`.
(04:02:58 PM) ondrej: right, that's true
(04:03:29 PM) pearu: Recall that Sin is a Basic object, hence it should support
__add__ as a class method as well as __add__ as an instance method
(04:03:56 PM) pearu: so that both `Sin+1` and `Sin(x)+1` can work
(04:03:59 PM) ondrej: yes. I am not sure though I like to have classes in
expressions
(04:04:07 PM) ondrej: why not to wrap them maybe?
(04:04:18 PM) pearu: this was the result of making function classes
(04:04:35 PM) ondrej: I know
(04:05:00 PM) ondrej: definitely, there should be just one class for Sin
(04:05:10 PM) ondrej: but the question is how to get Sin + 1 working
(04:05:27 PM) pearu: it is already working in sympycore
(04:05:47 PM) ondrej: yes
(04:05:59 PM) pearu: the trick was to use DualMethod but the InstanceClassMethod
makes it cleaner
(04:06:47 PM) ondrej: ok then. :)
(04:07:33 PM) ondrej: make sense
Original comment by pearu.peterson
on 22 Dec 2007 at 3:11
The InstanceClassMethod_decorator.py now contains sample implementations
for operators and parametric functions. It is a proof of concept.
For example,
D(1) - derivative operator with respect to 1-st argument
D(1)(Sin) - D(1) applied to Sin without evaluating it results a function
D(1)(Sin)
D(1)(Sin)(x) - function D(1)(Sin) applied to argument x
Hermite(1) - 1-st Hermite polynomial operator
Hermite(1)(x) - Hermite(1) applied to argument x
Original comment by pearu.peterson
on 23 Dec 2007 at 2:01
The D operator is derived from BasicOperator.
The Hermite operator is derived from BasicParametricFunction
The Sin function is derived from BasicFunction.
So, the BasicOperator, BasicParametricFunction, BasicFunction form
a complete set of classes for supporting functions and operators
definitions.
Original comment by pearu.peterson
on 23 Dec 2007 at 2:04
The issue is irrelevant now.
Original comment by pearu.peterson
on 12 Feb 2008 at 10:00
Original issue reported on code.google.com by
pearu.peterson
on 20 Dec 2007 at 7:16Attachments: