[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] IdentityDictionary possible bug: does not behave correctly after a readArchive WAS Re: [sc-users] Parameter space - saving to disk




On 17 May 2009, at 01:34, nescivi wrote:

On Saturday 16 May 2009 17:22:38 Miguel Negrao wrote:
> Thanks for the heads up James. Where can you I check which types are
> atomic types ?

Test using ===

Equivalent Symbols and numbers for instance test true for identity. Strings only if it's the exact same object.


>
> Nescivi, do you think it would be possible to have the ParameterSpace
> class use dictionaries instead of IdentityDictionaries ?

The downside of this is a performance hit. 

a = IdentityDictionary[\foo->\bar]

IdentityDictionary[ (foo -> bar) ]
b = Dictionary[\foo->\bar]

Dictionary[ (foo -> bar) ]

{
1000.do { a[\foo] }
}.bench
time to run: 0.0003569420077838 seconds.

{
1000.do { b[\foo] }
}.bench
time to run: 0.002664454994374 seconds.

Your example will work if you simply reverse the argument order and use Symbols instead of Strings. Sorry, coming late on this thread, but is that not what you want? Or you do want the Points as keys?

The other alternative is to convert to a Dictionary if needed using as.

S.



Sure.
Just send me a diff, and I'll commit it.

(go to the quarks/SenseWorld dir in the command line, type:
svn diff > parspace_dict.diff
and send me the resulting file offlist.

sincerely,
Marije

>
> James Harkins escreveu:
> > Not a bug. IdentityDictionaries should use only atomic types as keys.
> > Point is not an atomic type. Therefore you should be using Dictionary
> > instead.
> > hjh
> >
> > On Thu, May 14, 2009 at 1:50 PM, Miguel Negrao
> >
> > <miguel.negrao@xxxxxxxxxxxxxxxxx> wrote:
> >> With some investigations I concluded that IdentityDictionary's
> >> cannot be loaded with a readArchive.
> >>
> >> z = Point(0.5,0.5)
> >> y = Point(0.2,0.5)
> >> a = IdentityDictionary.new;
> >> a.put(z,"the point");
> >> a.put(y,"another point")
> >> a.writeArchive("/test")
> >> b = Object.readArchive("/test")
> >> b[b.keys.asArray[0]]
> >>
> >> this gives nil. This seems to me to be a bug, and I wonder if it could
> >> be fixed (devs ?). MultiLevelIdentityDictionary suffers from the same
> >> problem and that's what is keeping ParameterSpace from being saved
> >> correctly.