Christian Heimes writes:
> You are right as long as you don't try to rebind the variable.
And then only if you assign through an instance, which doesn't make
sense for a class-level cache. Assignment like Example2._cache = {}
would work.
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, Dec 29, 2010 at 00:45, Christian Heimes wrote:
> Am 28.12.2010 21:16, schrieb Hrvoje Niksic:
>> Christian Heimes writes:
>>
>>> Also this code is going to use much more memory than an ordinary tuple
>>> since every instance of InternedTuple has a __dict__ attribute. This
>>> code works bu
Am 28.12.2010 21:16, schrieb Hrvoje Niksic:
> Christian Heimes writes:
>
>> Also this code is going to use much more memory than an ordinary tuple
>> since every instance of InternedTuple has a __dict__ attribute. This
>> code works but I had to move the cache outside the class because of
>> __sl
Christian Heimes writes:
> Also this code is going to use much more memory than an ordinary tuple
> since every instance of InternedTuple has a __dict__ attribute. This
> code works but I had to move the cache outside the class because of
> __slots__.
Wouldn't it work inside the class as well?
On 12/27/2010 3:05 AM, Ulrich Eckhardt wrote:
Hi!
I'm trying to solve a computational problem and of course speed and size is
important there.
Then you probably shouldn't be using CPython.
Apart from picking the right algorithm, I came across an
idea that could help speed up things and k
Am 28.12.2010 15:11, schrieb Steven D'Aprano:
> # Untested
> class InternedTuple(tuple):
> _cache = {}
> def __new__(cls, *args):
> t = super().__new__(cls, *args)
> return cls._cache.setdefault(args, t)
> def __eq__(self, other):
> return self is other
> de
Steven D'Aprano, 28.12.2010 15:11:
On Tue, 28 Dec 2010 13:42:39 +0100, Ulrich Eckhardt wrote:
Steven D'Aprano wrote:
class InternedTuple(tuple):
... _cache = {}
... def __new__(cls, *args):
... t = super().__new__(cls, *args)
... return cls._cache.setdefault(t,
On Tue, 28 Dec 2010 13:42:39 +0100, Ulrich Eckhardt wrote:
> Steven D'Aprano wrote:
> class InternedTuple(tuple):
>> ... _cache = {}
>> ... def __new__(cls, *args):
>> ... t = super().__new__(cls, *args)
>> ... return cls._cache.setdefault(t, t)
>
> That looks
Steven D'Aprano wrote:
class InternedTuple(tuple):
> ... _cache = {}
> ... def __new__(cls, *args):
> ... t = super().__new__(cls, *args)
> ... return cls._cache.setdefault(t, t)
That looks good. The only thing that first bothered me is that it creates an
obje
On Mon, 27 Dec 2010 12:05:10 +0100, Ulrich Eckhardt wrote:
> What I'm now considering is to only allow a single instance of these
> objects for each set of values, similar to interned strings. What I
> would gain is that I could safely compare objects for identity instead
> of equality. What I'm n
On 27 December 2010 22:05, Ulrich Eckhardt wrote:
> What I'm now considering is to only allow a single instance of these
> objects
> for each set of values, similar to interned strings. What I would gain is
> that I could safely compare objects for identity instead of equality. What
> I'm not ye
Terry Reedy wrote:
> What sort of numbers are the coordinates? If integers in a finite range,
> your problem is a lot simpler than if float of indefinite precision.
Yes, indeed, I could optimize the amount of data required to store the data
itself, but that would require application-specific hand
On 12/27/2010 6:05 AM, Ulrich Eckhardt wrote:
Hi!
I'm trying to solve a computational problem and of course speed and size is
important there. Apart from picking the right algorithm, I came across an
idea that could help speed up things and keep memory requirements down. What
I have is regions d
>> I believe what you are looking for is (some variant of) the singleton
>> pattern:
>>
>> http://en.wikipedia.org/wiki/Singleton_pattern
>
> Actually, no. What I want is the flyweight pattern instead:
>
> http://en.wikipedia.org/wiki/Flyweight_pattern
Oh I see. I did not know about this pattern,
Daniel Fetchinson wrote:
> I believe what you are looking for is (some variant of) the singleton
> pattern:
>
> http://en.wikipedia.org/wiki/Singleton_pattern
Actually, no. What I want is the flyweight pattern instead:
http://en.wikipedia.org/wiki/Flyweight_pattern
...but thank you for the appr
> I'm trying to solve a computational problem and of course speed and size is
> important there. Apart from picking the right algorithm, I came across an
> idea that could help speed up things and keep memory requirements down. What
> I have is regions described by min and max coordinates. At first
Hi!
I'm trying to solve a computational problem and of course speed and size is
important there. Apart from picking the right algorithm, I came across an
idea that could help speed up things and keep memory requirements down. What
I have is regions described by min and max coordinates. At first
17 matches
Mail list logo