T
Thomas J. Gritzan
Am 10.06.2010 07:37, schrieb orz:
Agreed. And it wouldn't be done in a performance critical loop, would it?
Well... you would have to bring both instances to the same state, so
that both either store x(i)...x(i+n-1) or x(i-n)...x(i-1). If you don't
want to change the original objects (they are const in the op==), you
have to make a copy of both for the check.
How? Comparing the original seeds and number of calls?
A simple save/restore might invalidate the naive approach, depending on
how you do it. I think an equality check should be robust, if it is
provided. So it must normalize the internal state before comparing.
Interestingly, the TR1 implementation of Dinkumware (Visual Studio 2010)
also uses the double amount of memory.
It is true that that makes efficient full equality checks a bit
easier. But...
1. Equality check is not a common operation on MT.
Agreed. And it wouldn't be done in a performance critical loop, would it?
2. Even without the state double, full equality checks on MT instances
are not inefficient.
Well... you would have to bring both instances to the same state, so
that both either store x(i)...x(i+n-1) or x(i-n)...x(i-1). If you don't
want to change the original objects (they are const in the op==), you
have to make a copy of both for the check.
3. You could do mostly the same thing for equality checks with just a
single extra integer instead of 624 extras.
How? Comparing the original seeds and number of calls?
4. The naive approach to MT equality checks mostly works okay anyway.
Not perfectly, but I think the only ways to trip it up require either
running an instance of MT through an entire period (functionally
impossible to do without a skip-ahead type method, which is not
provided), or comparing two instances of MT originally seeded with
different seeds but then moved to the exact same position (on average
requires going through half of a full cycle, though it is possible to
do so with slightly less by way of bad luck, or a lot less if you pick
your seeds with great care).
A simple save/restore might invalidate the naive approach, depending on
how you do it. I think an equality check should be robust, if it is
provided. So it must normalize the internal state before comparing.
5. The Boost random docs list MT as taking up the normal amount of
memory, not the doubled amount of memory.
Interestingly, the TR1 implementation of Dinkumware (Visual Studio 2010)
also uses the double amount of memory.