This really should be a class method:
@classmethod
def is_collinear(cls, *points)
points = [cls(a) for a in points]
Note that this breaks backwards compatibility with the method being
called on an instance. Previously it would work, because the instance
would be the first element of points (what is usually the argument
self).
I think to maintain this behavior, or even raise a deprecation
warning, you'd need a custom descriptor. Or override it in __init__.
See http://stackoverflow.com/a/861109/161801.
Aaron Meurer
On Sat, Dec 6, 2014 at 5:40 PM, Duane Nykamp <[email protected]> wrote:
> Well, upon closer examination, I find many uses of Point in point.py that I
> don't know how to fix. I think my Python knowledge isn't quite there yet.
>
> It appears many of the functions are intended be called off the class rather
> than an instance, such as Point.is_collinear(p1, p2, p3, p4)
>
> def is_collinear(*points):
> .....
> points = [Point(a) for a in points]
>
> and, I'm not sure what to replace Point with in these cases.
>
> Duane
>
>
>
> On Saturday, December 6, 2014 4:17:15 PM UTC-6, Duane Nykamp wrote:
>>
>> The Point class, for numerous functions, such as .evalf, returns a hard
>> coded Point class. This means that for a derived class, these functions end
>> up returning the original Point class not the derived class. I assume there
>> must be a way to code it differently so these functions return the derived
>> class. For now, I'm just overriding the functions, like .evalf, that I need
>> to use so that they return my derived class.
>>
>> Should the calls to Point be changed to self.__class__ or is there a
>> different way one is supposed to accomplish this in Python? If it is as
>> simple as that, I could make the change and submit a pull request.
>>
>> (I'm creating a derived class to get rid of the call to nsimplify, as
>> functions like doit() and bottom up get rid of the evaluate=False flag.
>> nsimplify is quite slow. Each call to nsimplify for something like
>> Point(3.23423545235,6.345436534630) takes on the order of 100 ms. My
>> webserver slowed to a crawl with 140 students repeatedly hitting "Submit"
>> multiple times to check answers with a problem that had less than 10 Points
>> in it. Even with no load, the server takes over a second to grade the
>> question and spit back the results.)
>>
>> Thanks,
>> Duane
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> 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/d1a69ef6-a64a-415c-a4c2-ae262491c621%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.
--
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 [email protected].
To post to this group, send email to [email protected].
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%3D6%2Bi9KzRo454crTAiX1_iLZyh5_b4EWYt36-a-TV1amw4Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.