Commit bf30f229 by Ulrich Drepper Committed by Ulrich Drepper

random: Add __gnu_cxx:normal_mv_distribution<> class.


	* include/ext/random: Add __gnu_cxx:normal_mv_distribution<> class.
	* include/ext/random.tccAdd out-of-line functions for
	__gnu_cxx::normal_mv_distribution<>.
	* testsuite/26_numerics/random/normal_mv_distribution/
	operators/equal.cc: New file.
	* testsuite/26_numerics/random/normal_mv_distribution/
	operators/serialize.cc: New file.
	* testsuite/26_numerics/random/normal_mv_distribution/
	operators/inequal.cc: New file.
	* testsuite/26_numerics/random/normal_mv_distribution/
	cons/default.cc: New file.
	* testsuite/26_numerics/random/normal_mv_distribution/
	cons/parms.cc: New file.
	* testsuite/26_numerics/random/normal_mv_distribution/
	requirements/explicit_instantiation/1.cc: New file.
	* testsuite/26_numerics/random/normal_mv_distribution/
	requirements/typedefs.cc: New file.

From-SVN: r190960
parent 29ac1b66
2012-09-05 Ulrich Drepper <drepper@gmail.com>
* include/ext/random: Add __gnu_cxx:normal_mv_distribution<> class.
* include/ext/random.tccAdd out-of-line functions for
__gnu_cxx::normal_mv_distribution<>.
* testsuite/26_numerics/random/normal_mv_distribution/
operators/equal.cc: New file.
* testsuite/26_numerics/random/normal_mv_distribution/
operators/serialize.cc: New file.
* testsuite/26_numerics/random/normal_mv_distribution/
operators/inequal.cc: New file.
* testsuite/26_numerics/random/normal_mv_distribution/
cons/default.cc: New file.
* testsuite/26_numerics/random/normal_mv_distribution/
cons/parms.cc: New file.
* testsuite/26_numerics/random/normal_mv_distribution/
requirements/explicit_instantiation/1.cc: New file.
* testsuite/26_numerics/random/normal_mv_distribution/
requirements/typedefs.cc: New file.
2012-09-04 Ulrich Drepper <drepper@gmail.com>
* libstdc++-v3/include/ext/random: Add __gnu_cxx::beta_distribution<>
class.
* libstdc++-v3/include/ext/random.tcc: Add out-of-line functions for
* include/ext/random: Add __gnu_cxx::beta_distribution<> class.
* include/ext/random.tcc: Add out-of-line functions for
__gnu_cxx::beta_distribution<>.
* libstdc++-v3/testsuite/26_numerics/random/beta_distribution/
* testsuite/26_numerics/random/beta_distribution/
operators/equal.cc: New file.
* libstdc++-v3/testsuite/26_numerics/random/beta_distribution/
* testsuite/26_numerics/random/beta_distribution/
operators/serialize.cc: New file.
* libstdc++-v3/testsuite/26_numerics/random/beta_distribution/
* testsuite/26_numerics/random/beta_distribution/
operators/inequal.cc: New file.
* libstdc++-v3/testsuite/26_numerics/random/beta_distribution/
* testsuite/26_numerics/random/beta_distribution/
cons/parms.cc: New file.
* libstdc++-v3/testsuite/26_numerics/random/beta_distribution/
* testsuite/26_numerics/random/beta_distribution/
cons/default.cc: New file.
* libstdc++-v3/testsuite/26_numerics/random/beta_distribution/
* testsuite/26_numerics/random/beta_distribution/
requirements/typedefs.cc: New file.
* libstdc++-v3/testsuite/26_numerics/random/beta_distribution/
* testsuite/26_numerics/random/beta_distribution/
requirements/explicit_instantiation/1.cc: New file.
2012-09-04 Steven Bosscher <steven@gcc.gnu.org>
......
......@@ -538,6 +538,220 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __is;
}
template<std::size_t _Dimen, typename _RealType>
template<typename _InputIterator1, typename _InputIterator2>
void
normal_mv_distribution<_Dimen, _RealType>::param_type::
_M_init_full(_InputIterator1 __meanbegin, _InputIterator1 __meanend,
_InputIterator2 __varcovbegin, _InputIterator2 __varcovend)
{
__glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
__glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
std::fill(std::copy(__meanbegin, __meanend, _M_mean.begin()),
_M_mean.end(), _RealType(0));
// Perform the Cholesky decomposition
auto __w = _M_t.begin();
for (size_t __j = 0; __j < _Dimen; ++__j)
{
_RealType __sum = _RealType(0);
auto __slitbegin = __w;
auto __cit = _M_t.begin();
for (size_t __i = 0; __i < __j; ++__i)
{
auto __slit = __slitbegin;
_RealType __s = *__varcovbegin++;
for (size_t __k = 0; __k < __i; ++__k)
__s -= *__slit++ * *__cit++;
*__w++ = __s /= *__cit++;
__sum += __s * __s;
}
__sum = *__varcovbegin - __sum;
if (__builtin_expect(__sum <= _RealType(0), 0))
std::__throw_runtime_error(__N("normal_mv_distribution::"
"param_type::_M_init_full"));
*__w++ = std::sqrt(__sum);
std::advance(__varcovbegin, _Dimen - __j);
}
}
template<std::size_t _Dimen, typename _RealType>
template<typename _InputIterator1, typename _InputIterator2>
void
normal_mv_distribution<_Dimen, _RealType>::param_type::
_M_init_lower(_InputIterator1 __meanbegin, _InputIterator1 __meanend,
_InputIterator2 __varcovbegin, _InputIterator2 __varcovend)
{
__glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
__glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
std::fill(std::copy(__meanbegin, __meanend, _M_mean.begin()),
_M_mean.end(), _RealType(0));
// Perform the Cholesky decomposition
auto __w = _M_t.begin();
for (size_t __j = 0; __j < _Dimen; ++__j)
{
_RealType __sum = _RealType(0);
auto __slitbegin = __w;
auto __cit = _M_t.begin();
for (size_t __i = 0; __i < __j; ++__i)
{
auto __slit = __slitbegin;
_RealType __s = *__varcovbegin++;
for (size_t __k = 0; __k < __i; ++__k)
__s -= *__slit++ * *__cit++;
*__w++ = __s /= *__cit++;
__sum += __s * __s;
}
__sum = *__varcovbegin++ - __sum;
if (__builtin_expect(__sum <= _RealType(0), 0))
std::__throw_runtime_error(__N("normal_mv_distribution::"
"param_type::_M_init_full"));
*__w++ = std::sqrt(__sum);
}
}
template<std::size_t _Dimen, typename _RealType>
template<typename _InputIterator1, typename _InputIterator2>
void
normal_mv_distribution<_Dimen, _RealType>::param_type::
_M_init_diagonal(_InputIterator1 __meanbegin, _InputIterator1 __meanend,
_InputIterator2 __varbegin, _InputIterator2 __varend)
{
__glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
__glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
std::fill(std::copy(__meanbegin, __meanend, _M_mean.begin()),
_M_mean.end(), _RealType(0));
auto __w = _M_t.begin();
size_t __step = 0;
while (__varbegin != __varend)
{
std::fill_n(__w, __step, _RealType(0));
__w += __step++;
if (__builtin_expect(*__varbegin < _RealType(0), 0))
std::__throw_runtime_error(__N("normal_mv_distribution::"
"param_type::_M_init_diagonal"));
*__w++ = std::sqrt(*__varbegin++);
}
}
template<std::size_t _Dimen, typename _RealType>
template<typename _UniformRandomNumberGenerator>
typename normal_mv_distribution<_Dimen, _RealType>::result_type
normal_mv_distribution<_Dimen, _RealType>::
operator()(_UniformRandomNumberGenerator& __urng,
const param_type& __param)
{
result_type __ret;
for (size_t __i = 0; __i < _Dimen; ++__i)
__ret[__i] = _M_nd(__urng);
auto __t_it = __param._M_t.crbegin();
for (size_t __i = _Dimen; __i > 0; --__i)
{
_RealType __sum = _RealType(0);
for (size_t __j = __i; __j > 0; --__j)
__sum += __ret[__j - 1] * *__t_it++;
__ret[__i - 1] = __sum;
}
return __ret;
}
template<std::size_t _Dimen, typename _RealType>
template<typename _ForwardIterator, typename _UniformRandomNumberGenerator>
void
normal_mv_distribution<_Dimen, _RealType>::
__generate_impl(_ForwardIterator __f, _ForwardIterator __t,
_UniformRandomNumberGenerator& __urng,
const param_type& __param)
{
__glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
_ForwardIterator>)
while (__f != __t)
*__f++ = this->operator()(__urng, __param);
}
template<size_t _Dimen, typename _RealType>
bool
operator==(const __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>&
__d1,
const __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>&
__d2)
{
return __d1._M_param == __d2._M_param && __d1._M_nd == __d2._M_nd;
}
template<size_t _Dimen, typename _RealType, typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& __os,
const __gnu_cxx::normal_mv_distribution<_Dimen, _RealType>& __x)
{
typedef std::basic_ostream<_CharT, _Traits> __ostream_type;
typedef typename __ostream_type::ios_base __ios_base;
const typename __ios_base::fmtflags __flags = __os.flags();
const _CharT __fill = __os.fill();
const std::streamsize __precision = __os.precision();
const _CharT __space = __os.widen(' ');
__os.flags(__ios_base::scientific | __ios_base::left);
__os.fill(__space);
__os.precision(std::numeric_limits<_RealType>::max_digits10);
auto __mean = __x._M_param.mean();
for (auto __it : __mean)
__os << __it << __space;
auto __t = __x._M_param.varcov();
for (auto __it : __t)
__os << __it << __space;
__os << __x._M_nd;
__os.flags(__flags);
__os.fill(__fill);
__os.precision(__precision);
return __os;
}
template<size_t _Dimen, typename _RealType, typename _CharT, typename _Traits>
std::basic_istream<_CharT, _Traits>&
operator>>(std::basic_istream<_CharT, _Traits>& __is,
__gnu_cxx::normal_mv_distribution<_Dimen, _RealType>& __x)
{
typedef std::basic_istream<_CharT, _Traits> __istream_type;
typedef typename __istream_type::ios_base __ios_base;
const typename __ios_base::fmtflags __flags = __is.flags();
__is.flags(__ios_base::dec | __ios_base::skipws);
std::array<_RealType, _Dimen> __mean;
for (auto& __it : __mean)
__is >> __it;
std::array<_RealType, _Dimen * (_Dimen + 1) / 2> __varcov;
for (auto& __it : __varcov)
__is >> __it;
__is >> __x._M_nd;
__x.param(typename normal_mv_distribution<_Dimen, _RealType>::
param_type(__mean.begin(), __mean.end(),
__varcov.begin(), __varcov.end()));
__is.flags(__flags);
return __is;
}
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace
......
// { dg-options "-std=c++0x" }
// { dg-require-cstdint "" }
//
// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
// 2012-09-04 Ulrich Drepper <drepper@gmail.com>
//
// Copyright (C) 2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <ext/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
__gnu_cxx::normal_mv_distribution<2> u;
VERIFY( u.mean()[0] == 0.0 );
VERIFY( u.mean()[1] == 0.0 );
VERIFY( u.varcov()[0] == 1.0 );
VERIFY( u.varcov()[1] == 0.0 );
VERIFY( u.varcov()[2] == 1.0 );
typedef __gnu_cxx::normal_mv_distribution<2>::result_type result_type;
VERIFY( u.min()[0] == std::numeric_limits<result_type::value_type>::min() );
VERIFY( u.max()[0] == std::numeric_limits<result_type::value_type>::max() );
VERIFY( u.min()[1] == std::numeric_limits<result_type::value_type>::min() );
VERIFY( u.max()[1] == std::numeric_limits<result_type::value_type>::max() );
}
int main()
{
test01();
return 0;
}
// { dg-options "-std=c++0x" }
// { dg-require-cstdint "" }
//
// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
// 2012-09-04 Ulrich Drepper <drepper@gmail.com>
//
// Copyright (C) 2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <ext/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
__gnu_cxx::normal_mv_distribution<2> u({5.0, 4.0}, {4.0, 9.0});
VERIFY( u.mean()[0] == 5.0 );
VERIFY( u.mean()[1] == 4.0 );
VERIFY( u.varcov()[0] == 2.0 );
VERIFY( u.varcov()[1] == 0.0 );
VERIFY( u.varcov()[2] == 3.0 );
typedef __gnu_cxx::normal_mv_distribution<2>::result_type result_type;
VERIFY( u.min()[0] == std::numeric_limits<result_type::value_type>::min() );
VERIFY( u.max()[0] == std::numeric_limits<result_type::value_type>::max() );
VERIFY( u.min()[1] == std::numeric_limits<result_type::value_type>::min() );
VERIFY( u.max()[1] == std::numeric_limits<result_type::value_type>::max() );
}
int main()
{
test01();
return 0;
}
// { dg-options "-std=c++0x" }
// { dg-require-cstdint "" }
//
// 2010-03-16 Paolo Carlini <paolo.carlini@oracle.com>
// 2012-09-04 Ulrich Drepper <drepper@gmail.com>
//
// Copyright (C) 2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <ext/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
__gnu_cxx::normal_mv_distribution<2,double> u({5.0, 4.0}, {2.0, 1.5}), v, w;
VERIFY( v == w );
VERIFY( !(u == v) );
}
int main()
{
test01();
return 0;
}
// { dg-options "-std=c++0x" }
// { dg-require-cstdint "" }
//
// 2010-03-16 Paolo Carlini <paolo.carlini@oracle.com>
// 2012-09-04 Ulrich Drepper <drepper@gmail.com>
//
// Copyright (C) 2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <ext/random>
#include <testsuite_hooks.h>
void
test01()
{
bool test __attribute__((unused)) = true;
__gnu_cxx::normal_mv_distribution<2,double> u({3.0, 5.0}, {1.0, 2.0}), v, w;
VERIFY( u != v );
VERIFY( !(v != w) );
}
int main()
{
test01();
return 0;
}
// { dg-options "-std=c++0x" }
// { dg-require-cstdint "" }
//
// 2009-08-14 Edward M. Smith-Rowland <3dw4rd@verizon.net>
// 2012-09-04 Ulrich Drepper <drepper@gmail.com>
//
// Copyright (C) 2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <ext/random>
#include <sstream>
void
test01()
{
std::stringstream str;
__gnu_cxx::normal_mv_distribution<2,double> u({1.0, 5.0}, {2.0, 4.0}), v;
std::minstd_rand0 rng;
u(rng); // advance
str << u;
str >> v;
}
int main()
{
test01();
return 0;
}
// { dg-do compile }
// { dg-options "-std=c++11" }
// { dg-require-cstdint "" }
//
// Copyright (C) 2012 Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <ext/random>
template class __gnu_cxx::normal_mv_distribution<2,float>;
template class __gnu_cxx::normal_mv_distribution<2,double>;
template class __gnu_cxx::normal_mv_distribution<2,long double>;
// { dg-do compile }
// { dg-options "-std=c++0x" }
// { dg-require-cstdint "" }
//
// 2008-11-24 Edward M. Smith-Rowland <3dw4rd@verizon.net>
// 2012-09-04 Ulrich Drepper <drepper@gmail.com>
//
// Copyright (C) 2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <ext/random>
void
test01()
{
typedef __gnu_cxx::normal_mv_distribution<3,double> test_type;
typedef test_type::result_type result_type;
typedef test_type::param_type param_type;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment