[cfe-commits] [libcxx] r103788 - in /libcxx/trunk: include/ test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/

Howard Hinnant hhinnant at apple.com
Fri May 14 11:43:10 PDT 2010


Author: hhinnant
Date: Fri May 14 13:43:10 2010
New Revision: 103788

URL: http://llvm.org/viewvc/llvm-project?rev=103788&view=rev
Log:
[rand.dist.pois.gamma]

Added:
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/assign.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/copy.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/ctor_double_double.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/ctor_param.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eq.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eval.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eval_param.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/get_param.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/io.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/max.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/min.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_assign.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_copy.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_ctor.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_eq.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_types.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/set_param.pass.cpp
    libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/types.pass.cpp
Modified:
    libcxx/trunk/include/random

Modified: libcxx/trunk/include/random
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/random?rev=103788&r1=103787&r2=103788&view=diff
==============================================================================
--- libcxx/trunk/include/random (original)
+++ libcxx/trunk/include/random Fri May 14 13:43:10 2010
@@ -3348,21 +3348,22 @@
 _RealType
 gamma_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p)
 {
-    result_type __a = __p_.alpha();
+    result_type __a = __p.alpha();
+    uniform_real_distribution<result_type> __gen(0, 1);
+    exponential_distribution<result_type> __egen;
+    result_type __x;
     if (__a == 1)
-        return exponential_distribution<result_type>(1/__p_.beta())(__g);
+        __x = __egen(__g);
     else if (__a > 1)
     {
         const result_type __b = __a - 1;
         const result_type __c = 3 * __a - result_type(0.75);
-        uniform_real_distribution<result_type> __gen(0, 1);
-        result_type __x;
         while (true)
         {
             const result_type __u = __gen(__g);
             const result_type __v = __gen(__g);
             const result_type __w = __u * (1 - __u);
-            if (__w =! 0)
+            if (__w != 0)
             {
                 const result_type __y = _STD::sqrt(__c / __w) *
                                         (__u - result_type(0.5));
@@ -3377,10 +3378,29 @@
                 }
             }
         }
-        return __x * __p_.beta();
     }
-    // else __a < 1
-    return 0; // temp!!!
+    else  // __a < 1
+    {
+        while (true)
+        {
+            const result_type __u = __gen(__g);
+            const result_type __es = __egen(__g);
+            if (__u <= 1 - __a)
+            {
+                __x = _STD::pow(__u, 1 / __a);
+                if (__x <= __es)
+                    break;
+            }
+            else
+            {
+                const result_type __e = -_STD::log((1-__u)/__a);
+                __x = _STD::pow(1 - __a + __a * __e, 1 / __a);
+                if (__x <= __e + __es)
+                    break;
+            }
+        }
+    }
+    return __x * __p.beta();
 }
 
 template <class _CharT, class _Traits, class _RT>

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/assign.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/assign.pass.cpp?rev=103788&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/assign.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/assign.pass.cpp Fri May 14 13:43:10 2010
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class gamma_distribution
+
+// gamma_distribution& operator=(const gamma_distribution&);
+
+#include <random>
+#include <cassert>
+
+void
+test1()
+{
+    typedef std::gamma_distribution<> D;
+    D d1(20, 0.75);
+    D d2;
+    assert(d1 != d2);
+    d2 = d1;
+    assert(d1 == d2);
+}
+
+int main()
+{
+    test1();
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/copy.pass.cpp?rev=103788&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/copy.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/copy.pass.cpp Fri May 14 13:43:10 2010
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class gamma_distribution
+
+// gamma_distribution(const gamma_distribution&);
+
+#include <random>
+#include <cassert>
+
+void
+test1()
+{
+    typedef std::gamma_distribution<> D;
+    D d1(20, 1.75);
+    D d2 = d1;
+    assert(d1 == d2);
+}
+
+int main()
+{
+    test1();
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/ctor_double_double.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/ctor_double_double.pass.cpp?rev=103788&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/ctor_double_double.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/ctor_double_double.pass.cpp Fri May 14 13:43:10 2010
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class gamma_distribution
+
+// explicit gamma_distribution(result_type alpha = 0, result_type beta = 1);
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::gamma_distribution<> D;
+        D d;
+        assert(d.alpha() == 1);
+        assert(d.beta() == 1);
+    }
+    {
+        typedef std::gamma_distribution<> D;
+        D d(14.5);
+        assert(d.alpha() == 14.5);
+        assert(d.beta() == 1);
+    }
+    {
+        typedef std::gamma_distribution<> D;
+        D d(14.5, 5.25);
+        assert(d.alpha() == 14.5);
+        assert(d.beta() == 5.25);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/ctor_param.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/ctor_param.pass.cpp?rev=103788&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/ctor_param.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/ctor_param.pass.cpp Fri May 14 13:43:10 2010
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class gamma_distribution
+
+// explicit gamma_distribution(const param_type& parm);
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::gamma_distribution<> D;
+        typedef D::param_type P;
+        P p(0.25, 10);
+        D d(p);
+        assert(d.alpha() == 0.25);
+        assert(d.beta() == 10);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eq.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eq.pass.cpp?rev=103788&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eq.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eq.pass.cpp Fri May 14 13:43:10 2010
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class gamma_distribution
+
+// bool operator=(const gamma_distribution& x,
+//                const gamma_distribution& y);
+// bool operator!(const gamma_distribution& x,
+//                const gamma_distribution& y);
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::gamma_distribution<> D;
+        D d1(2.5, 4);
+        D d2(2.5, 4);
+        assert(d1 == d2);
+    }
+    {
+        typedef std::gamma_distribution<> D;
+        D d1(2.5, 4);
+        D d2(2.5, 4.5);
+        assert(d1 != d2);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eval.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eval.pass.cpp?rev=103788&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eval.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eval.pass.cpp Fri May 14 13:43:10 2010
@@ -0,0 +1,95 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class gamma_distribution
+
+// template<class _URNG> result_type operator()(_URNG& g);
+
+#include <random>
+#include <cassert>
+#include <vector>
+#include <numeric>
+
+template <class T>
+inline
+T
+sqr(T x)
+{
+    return x * x;
+}
+
+int main()
+{
+    {
+        typedef std::gamma_distribution<> D;
+        typedef D::param_type P;
+        typedef std::minstd_rand G;
+        G g;
+        D d(0.5, 2);
+        const int N = 100000;
+        std::vector<D::result_type> u;
+        for (int i = 0; i < N; ++i)
+            u.push_back(d(g));
+        D::result_type mean = std::accumulate(u.begin(), u.end(),
+                                              D::result_type(0)) / u.size();
+        D::result_type var = 0;
+        for (int i = 0; i < u.size(); ++i)
+            var += sqr(u[i] - mean);
+        var /= u.size();
+        D::result_type x_mean = d.alpha() * d.beta();
+        D::result_type x_var = d.alpha() * sqr(d.beta());
+        assert(std::abs(mean - x_mean) / x_mean < 0.02);
+        assert(std::abs(var - x_var) / x_var < 0.02);
+    }
+    {
+        typedef std::gamma_distribution<> D;
+        typedef D::param_type P;
+        typedef std::minstd_rand G;
+        G g;
+        D d(1, .5);
+        const int N = 100000;
+        std::vector<D::result_type> u;
+        for (int i = 0; i < N; ++i)
+            u.push_back(d(g));
+        D::result_type mean = std::accumulate(u.begin(), u.end(),
+                                              D::result_type(0)) / u.size();
+        D::result_type var = 0;
+        for (int i = 0; i < u.size(); ++i)
+            var += sqr(u[i] - mean);
+        var /= u.size();
+        D::result_type x_mean = d.alpha() * d.beta();
+        D::result_type x_var = d.alpha() * sqr(d.beta());
+        assert(std::abs(mean - x_mean) / x_mean < 0.02);
+        assert(std::abs(var - x_var) / x_var < 0.02);
+    }
+    {
+        typedef std::gamma_distribution<> D;
+        typedef D::param_type P;
+        typedef std::minstd_rand G;
+        G g;
+        D d(2, 3);
+        const int N = 100000;
+        std::vector<D::result_type> u;
+        for (int i = 0; i < N; ++i)
+            u.push_back(d(g));
+        D::result_type mean = std::accumulate(u.begin(), u.end(),
+                                              D::result_type(0)) / u.size();
+        D::result_type var = 0;
+        for (int i = 0; i < u.size(); ++i)
+            var += sqr(u[i] - mean);
+        var /= u.size();
+        D::result_type x_mean = d.alpha() * d.beta();
+        D::result_type x_var = d.alpha() * sqr(d.beta());
+        assert(std::abs(mean - x_mean) / x_mean < 0.02);
+        assert(std::abs(var - x_var) / x_var < 0.02);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eval_param.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eval_param.pass.cpp?rev=103788&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eval_param.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/eval_param.pass.cpp Fri May 14 13:43:10 2010
@@ -0,0 +1,98 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class gamma_distribution
+
+// template<class _URNG> result_type operator()(_URNG& g, const param_type& parm);
+
+#include <random>
+#include <cassert>
+#include <vector>
+#include <numeric>
+
+template <class T>
+inline
+T
+sqr(T x)
+{
+    return x * x;
+}
+
+int main()
+{
+    {
+        typedef std::gamma_distribution<> D;
+        typedef D::param_type P;
+        typedef std::minstd_rand G;
+        G g;
+        D d(0.5, 2);
+        P p(1, .5);
+        const int N = 100000;
+        std::vector<D::result_type> u;
+        for (int i = 0; i < N; ++i)
+            u.push_back(d(g, p));
+        D::result_type mean = std::accumulate(u.begin(), u.end(),
+                                              D::result_type(0)) / u.size();
+        D::result_type var = 0;
+        for (int i = 0; i < u.size(); ++i)
+            var += sqr(u[i] - mean);
+        var /= u.size();
+        D::result_type x_mean = p.alpha() * p.beta();
+        D::result_type x_var = p.alpha() * sqr(p.beta());
+        assert(std::abs(mean - x_mean) / x_mean < 0.02);
+        assert(std::abs(var - x_var) / x_var < 0.02);
+    }
+    {
+        typedef std::gamma_distribution<> D;
+        typedef D::param_type P;
+        typedef std::minstd_rand G;
+        G g;
+        D d(1, .5);
+        P p(2, 3);
+        const int N = 100000;
+        std::vector<D::result_type> u;
+        for (int i = 0; i < N; ++i)
+            u.push_back(d(g, p));
+        D::result_type mean = std::accumulate(u.begin(), u.end(),
+                                              D::result_type(0)) / u.size();
+        D::result_type var = 0;
+        for (int i = 0; i < u.size(); ++i)
+            var += sqr(u[i] - mean);
+        var /= u.size();
+        D::result_type x_mean = p.alpha() * p.beta();
+        D::result_type x_var = p.alpha() * sqr(p.beta());
+        assert(std::abs(mean - x_mean) / x_mean < 0.02);
+        assert(std::abs(var - x_var) / x_var < 0.02);
+    }
+    {
+        typedef std::gamma_distribution<> D;
+        typedef D::param_type P;
+        typedef std::minstd_rand G;
+        G g;
+        D d(2, 3);
+        P p(.5, 2);
+        const int N = 100000;
+        std::vector<D::result_type> u;
+        for (int i = 0; i < N; ++i)
+            u.push_back(d(g, p));
+        D::result_type mean = std::accumulate(u.begin(), u.end(),
+                                              D::result_type(0)) / u.size();
+        D::result_type var = 0;
+        for (int i = 0; i < u.size(); ++i)
+            var += sqr(u[i] - mean);
+        var /= u.size();
+        D::result_type x_mean = p.alpha() * p.beta();
+        D::result_type x_var = p.alpha() * sqr(p.beta());
+        assert(std::abs(mean - x_mean) / x_mean < 0.02);
+        assert(std::abs(var - x_var) / x_var < 0.02);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/get_param.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/get_param.pass.cpp?rev=103788&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/get_param.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/get_param.pass.cpp Fri May 14 13:43:10 2010
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class gamma_distribution
+
+// param_type param() const;
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::gamma_distribution<> D;
+        typedef D::param_type P;
+        P p(.125, .5);
+        D d(p);
+        assert(d.param() == p);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/io.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/io.pass.cpp?rev=103788&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/io.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/io.pass.cpp Fri May 14 13:43:10 2010
@@ -0,0 +1,41 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class gamma_distribution
+
+// template <class CharT, class Traits, class RealType>
+// basic_ostream<CharT, Traits>&
+// operator<<(basic_ostream<CharT, Traits>& os,
+//            const gamma_distribution<RealType>& x);
+
+// template <class CharT, class Traits, class RealType>
+// basic_istream<CharT, Traits>&
+// operator>>(basic_istream<CharT, Traits>& is,
+//            gamma_distribution<RealType>& x);
+
+#include <random>
+#include <sstream>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::gamma_distribution<> D;
+        D d1(7, 5);
+        std::ostringstream os;
+        os << d1;
+        std::istringstream is(os.str());
+        D d2;
+        is >> d2;
+        assert(d1 == d2);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/max.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/max.pass.cpp?rev=103788&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/max.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/max.pass.cpp Fri May 14 13:43:10 2010
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class gamma_distribution
+
+// result_type max() const;
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::gamma_distribution<> D;
+        D d(5, .25);
+        D::result_type m = d.max();
+        assert(m == INFINITY);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/min.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/min.pass.cpp?rev=103788&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/min.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/min.pass.cpp Fri May 14 13:43:10 2010
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class gamma_distribution
+
+// result_type min() const;
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::gamma_distribution<> D;
+        D d(.5, .5);
+        assert(d.min() == 0);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_assign.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_assign.pass.cpp?rev=103788&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_assign.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_assign.pass.cpp Fri May 14 13:43:10 2010
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class gamma_distribution
+// {
+//     class param_type;
+
+#include <random>
+#include <limits>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::gamma_distribution<> D;
+        typedef D::param_type param_type;
+        param_type p0(.75, 6);
+        param_type p;
+        p = p0;
+        assert(p.alpha() == .75);
+        assert(p.beta() == 6);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_copy.pass.cpp?rev=103788&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_copy.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_copy.pass.cpp Fri May 14 13:43:10 2010
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class gamma_distribution
+// {
+//     class param_type;
+
+#include <random>
+#include <limits>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::gamma_distribution<> D;
+        typedef D::param_type param_type;
+        param_type p0(10, .125);
+        param_type p = p0;
+        assert(p.alpha() == 10);
+        assert(p.beta() == .125);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_ctor.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_ctor.pass.cpp?rev=103788&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_ctor.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_ctor.pass.cpp Fri May 14 13:43:10 2010
@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class gamma_distribution
+// {
+//     class param_type;
+
+#include <random>
+#include <limits>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::gamma_distribution<> D;
+        typedef D::param_type param_type;
+        param_type p;
+        assert(p.alpha() == 1);
+        assert(p.beta() == 1);
+    }
+    {
+        typedef std::gamma_distribution<> D;
+        typedef D::param_type param_type;
+        param_type p(10);
+        assert(p.alpha() == 10);
+        assert(p.beta() == 1);
+    }
+    {
+        typedef std::gamma_distribution<> D;
+        typedef D::param_type param_type;
+        param_type p(10, 5);
+        assert(p.alpha() == 10);
+        assert(p.beta() == 5);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_eq.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_eq.pass.cpp?rev=103788&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_eq.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_eq.pass.cpp Fri May 14 13:43:10 2010
@@ -0,0 +1,37 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class gamma_distribution
+// {
+//     class param_type;
+
+#include <random>
+#include <limits>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::gamma_distribution<> D;
+        typedef D::param_type param_type;
+        param_type p1(0.75, .5);
+        param_type p2(0.75, .5);
+        assert(p1 == p2);
+    }
+    {
+        typedef std::gamma_distribution<> D;
+        typedef D::param_type param_type;
+        param_type p1(0.75, .5);
+        param_type p2(0.5, .5);
+        assert(p1 != p2);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_types.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_types.pass.cpp?rev=103788&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_types.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/param_types.pass.cpp Fri May 14 13:43:10 2010
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class gamma_distribution
+// {
+//     class param_type;
+
+#include <random>
+#include <type_traits>
+
+int main()
+{
+    {
+        typedef std::gamma_distribution<> D;
+        typedef D::param_type param_type;
+        typedef param_type::distribution_type distribution_type;
+        static_assert((std::is_same<D, distribution_type>::value), "");
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/set_param.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/set_param.pass.cpp?rev=103788&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/set_param.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/set_param.pass.cpp Fri May 14 13:43:10 2010
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class gamma_distribution;
+
+// void param(const param_type& parm);
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+    {
+        typedef std::gamma_distribution<> D;
+        typedef D::param_type P;
+        P p(0.25, 5.5);
+        D d(0.75, 4);
+        d.param(p);
+        assert(d.param() == p);
+    }
+}

Added: libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/types.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/types.pass.cpp?rev=103788&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/types.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.dis/rand.dist.pois/rand.dist.pois.gamma/types.pass.cpp Fri May 14 13:43:10 2010
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class RealType = double>
+// class gamma_distribution
+// {
+// public:
+//     // types
+//     typedef RealType result_type;
+
+#include <random>
+#include <type_traits>
+
+int main()
+{
+    {
+        typedef std::gamma_distribution<> D;
+        typedef D::result_type result_type;
+        static_assert((std::is_same<result_type, double>::value), "");
+    }
+    {
+        typedef std::gamma_distribution<float> D;
+        typedef D::result_type result_type;
+        static_assert((std::is_same<result_type, float>::value), "");
+    }
+}





More information about the cfe-commits mailing list