Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove non-STL random and added randDiscrete #9

Merged
merged 6 commits into from
Jul 31, 2015

Conversation

williampma
Copy link
Member

There's this bit of comment that says

-/** @todo Once C++11 is fully supported by GCC feel free to remove anything
- * wrapped by #ifndef USE_STL_RANDOM  
- * The situation is confusing... According to gnu.org, this has been
- * supported since gcc-4.3 (but possibly in the tr1 namespace ??)
- * In Ubuntu oneiric, with gcc-4.6.2, the build failed.
- *  With gcc-4.6.3, things work.  I'm confused. This
- * needs more user reports.
- */

so I assume removing all the old non-STL random is always wanted.

@williampma
Copy link
Member Author

Weird... how come my randomUTest pass on my machine and not on Travis... I thought random on the same seed should be fine...

Or am I using the std::distribution wrong?

@ngeiswei
Copy link
Member

Woohoo, very cool Travis check!!! :-)

@amebel
Copy link
Contributor

amebel commented Jul 30, 2015

travis builds are run on ubuntu 12.04, with some ppa for recent versions. perhaps it is a dependency issue?

@williampma
Copy link
Member Author

Oh, that might be it. The old comment I quoted said it failed on gcc 4.6.2. Perhaps ubuntu 12.04 uses that...

@williampma
Copy link
Member Author

Hummm.... C++11 requires GCC 4.8.1...

@amebel
Copy link
Contributor

amebel commented Jul 30, 2015

after some change on travis so as to use 4.9 and rebasing your pr on it, i am getting https://travis-ci.org/AmeBel/cogutils/builds/73349281

@williampma
Copy link
Member Author

Hummm... I really don't know what's going on...


TS_ASSERT(p[2] > p[1]);
TS_ASSERT(p[1] > p[3]);
TS_ASSERT(p[3] > p[0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use TS_ASSERT_LESS_THAN http://cxxtest.com/guide.html#ts_assert_less_than that way it returns more meaningful message when it fails.

@ngeiswei
Copy link
Member

Very very strange, this passes on my system (gcc 4.8.4) if I don't output p[0] to p[3]. If I do, by adding the following code

        for (size_t i = 0; i < 4; ++i)
            std::cout << "p[" << i << "] = " << p[i]
                      << ", p[" << i << "]/" << size << " = "
                      << (double)p[i]/(double)size << std::endl;

I get the following

p[0] = 7400799, p[0]/10000000 = 0.74008
p[1] = 3000512, p[1]/10000000 = 0.300051
p[2] = 3997427, p[2]/10000000 = 0.399743
p[3] = 2001454, p[3]/10000000 = 0.200145

In randomUTest::test_discrete:
/home/nilg/OpenCog/AmeBel/cogutils/tests/util/randomUTest.cxxtest:76: Error: Assertion failed: p[3] > p[0]
Failed 1 and Skipped 0 of 3 tests
Success rate: 66%

and it fails...

Looks like std::mt19937 relies on quantum mechanics, if you observe it, it behaves differently.

@amebel
Copy link
Contributor

amebel commented Jul 30, 2015

just checked in container and travis https://travis-ci.org/AmeBel/cogutils#L726, success using gcc 4.8 but not on gcc 4.9

@amebel amebel mentioned this pull request Jul 30, 2015
@ngeiswei
Copy link
Member

I think I know the problem! The array p is not initialized with zeros!

@ngeiswei
Copy link
Member

Yep, works, just add

        for (size_t i = 0; i < 4; ++i)
            p[i] = 0;

after defining p, or use a std::vector.

@williampma
Copy link
Member Author

Haha, oops, it happens. Thanks!

I will fix it tomorrow.

@amebel
Copy link
Contributor

amebel commented Jul 30, 2015

forgive my ignorance, but what just happened with that line? and why would the compiler miss that?

@ngeiswei
Copy link
Member

Well, it's another complicated C++ thing http://stackoverflow.com/questions/11812687/why-is-int-array-not-initialized-to-zeros-in-c

BTW, according to http://stackoverflow.com/questions/201101/how-to-initialize-an-array-in-c one can just write

        int p[4] = {};

@williampma
Copy link
Member Author

Unit test passes now, but how come Travis is testing twice, once with CXX=g++4.9 and once with CC="gcc4.9 (what's with the single "?)?

@amebel
Copy link
Contributor

amebel commented Jul 31, 2015

#11 fixes that. 'env' key is used to set mutliple builds, which I unkowling thought was a means of setting environment variables, which in a sense is, with each list entry a single separate environment identifier.

@williampma
Copy link
Member Author

Oh I see. That might to useful in the future I guess to test different setup.

Anyway, since Nil seems to be OK with the changes (he didn't comment on the old random code removal), I treat this as reviewed and will merge.

williampma added a commit that referenced this pull request Jul 31, 2015
Remove non-STL random and added randDiscrete
@williampma williampma merged commit 40e8a9d into opencog:master Jul 31, 2015
@williampma williampma deleted the RemoveOldRand branch July 31, 2015 03:42
@@ -20,53 +20,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef USE_STL_RANDOM
/* Original:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, is it appropriate to remove the copyright notice?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer using the copyrighted code right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants