skip Cholesky decomposition in is>>n_mv_dist

Jonathan Wakely jwakely@redhat.com
Fri Aug 9 10:26:00 GMT 2019


On 09/08/19 10:20 +0200, Ulrich Drepper wrote:
>On Fri, Aug 9, 2019 at 9:50 AM Alexandre Oliva <oliva@adacore.com> wrote:
>
>> normal_mv_distribution maintains the variance-covariance matrix param
>> in Cholesky-decomposed form.  Existing param_type constructors, when
>> taking a full or lower-triangle varcov matrix, perform Cholesky
>> decomposition to convert it to the internal representation.  This
>> internal representation is visible both in the varcov() result, and in
>> the streamed-out representation of a normal_mv_distribution object.
>>
>> […]
>>
>
>
>> Tested on x86_64-linux-gnu.  Ok to install?
>>
>
>Yes.  Thanks.

If the operator>> is a friend it can just write straight to the array
members of the param_type object:

diff --git a/libstdc++-v3/include/ext/random.tcc b/libstdc++-v3/include/ext/random.tcc
index 31dc33a2555..77abdd9a1de 100644
--- a/libstdc++-v3/include/ext/random.tcc
+++ b/libstdc++-v3/include/ext/random.tcc
@@ -700,18 +700,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       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)
+      typename normal_mv_distribution<_Dimen, _RealType>::param_type __param;
+      for (auto& __it : __param._M_mean)
        __is >> __it;
-      std::array<_RealType, _Dimen * (_Dimen + 1) / 2> __varcov;
-      for (auto& __it : __varcov)
+      for (auto& __it : __param._M_t)
        __is >> __it;

       __is >> __x._M_nd;

-      __x.param(typename normal_mv_distribution<_Dimen, _RealType>::
-               param_type(__mean.begin(), __mean.end(),
-                          __varcov.begin(), __varcov.end()));
+      __x.param(__param);

       __is.flags(__flags);
       return __is;


The default constructor for param_type() will pointlessly fill the
arrays that are about to be overwritten though, so maybe this isn't an
improvement.



More information about the Libstdc++ mailing list