native_pq_tag.hpp: Remove.
2006-10-03 Benjamin Kosnik <bkoz@redhat.com> * testsuite/util/native_type/priority_queue/native_pq_tag.hpp: Remove. * testsuite/util/statistic/sample_var.hpp: Rename to... * testsuite/util/statistic/sample_variance.hpp: ... this. * testsuite/util/statistic/res_recorder.hpp: Rename to... * testsuite/util/statistic/result_recorder.hpp: ... this. * testsuite/util/statistic/sample_mean.hpp: Format. * testsuite/util/statistic/sample_mean_confidence_checker.hpp: Same. * testsuite/util/regression/trait/priority_queue/trait.hpp: Same. * testsuite/util/regression/trait/erase_if_fn.hpp: Same. * testsuite/util/regression/trait/assoc/trait.hpp: Same. * testsuite/util/native_type/priority_queue/ native_priority_queue.hpp: Same. * testsuite/util/native_type/assoc/native_tree_tag.hpp: Same. * testsuite/util/native_type/assoc/native_hash_tag.hpp: Same. * testsuite/util/native_type/assoc/native_hash_map.hpp: Same. * testsuite/util/performance/priority_queue/timing/join_test.hpp: Same. * testsuite/util/performance/priority_queue/timing/ modify_test.hpp: Same. * testsuite/util/performance/assoc/timing/ subscript_insert_test.hpp: Same. * testsuite/util/performance/time/timing_test_base.hpp: Same. From-SVN: r117397
This commit is contained in:
parent
c55cebdacd
commit
382a135134
17 changed files with 184 additions and 413 deletions
|
@ -1,3 +1,27 @@
|
|||
2006-10-03 Benjamin Kosnik <bkoz@redhat.com>
|
||||
|
||||
* testsuite/util/native_type/priority_queue/native_pq_tag.hpp: Remove.
|
||||
* testsuite/util/statistic/sample_var.hpp: Rename to...
|
||||
* testsuite/util/statistic/sample_variance.hpp: ... this.
|
||||
* testsuite/util/statistic/res_recorder.hpp: Rename to...
|
||||
* testsuite/util/statistic/result_recorder.hpp: ... this.
|
||||
* testsuite/util/statistic/sample_mean.hpp: Format.
|
||||
* testsuite/util/statistic/sample_mean_confidence_checker.hpp: Same.
|
||||
* testsuite/util/regression/trait/priority_queue/trait.hpp: Same.
|
||||
* testsuite/util/regression/trait/erase_if_fn.hpp: Same.
|
||||
* testsuite/util/regression/trait/assoc/trait.hpp: Same.
|
||||
* testsuite/util/native_type/priority_queue/
|
||||
native_priority_queue.hpp: Same.
|
||||
* testsuite/util/native_type/assoc/native_tree_tag.hpp: Same.
|
||||
* testsuite/util/native_type/assoc/native_hash_tag.hpp: Same.
|
||||
* testsuite/util/native_type/assoc/native_hash_map.hpp: Same.
|
||||
* testsuite/util/performance/priority_queue/timing/join_test.hpp: Same.
|
||||
* testsuite/util/performance/priority_queue/timing/
|
||||
modify_test.hpp: Same.
|
||||
* testsuite/util/performance/assoc/timing/
|
||||
subscript_insert_test.hpp: Same.
|
||||
* testsuite/util/performance/time/timing_test_base.hpp: Same.
|
||||
|
||||
2006-10-02 Paolo Carlini <pcarlini@suse.de>
|
||||
|
||||
* include/ext/rc_string_base.h (_M_compare<wchar_t>):
|
||||
|
|
|
@ -134,5 +134,5 @@ namespace pb_ds
|
|||
} // namespace test
|
||||
} // namespace pb_ds
|
||||
|
||||
#endif // #ifndef PB_DS_NATIVE_HASH_MAP_HPP
|
||||
#endif
|
||||
|
||||
|
|
|
@ -55,4 +55,4 @@ namespace pb_ds
|
|||
} // namespace test
|
||||
} // namespace pb_ds
|
||||
|
||||
#endif // #ifndef PB_DS_NATIVE_HASH_DS_TAG_HPP
|
||||
#endif
|
||||
|
|
|
@ -56,4 +56,4 @@ namespace pb_ds
|
|||
} // namespace test
|
||||
} // namespace pb_ds
|
||||
|
||||
#endif // #ifndef PB_DS_NATIVE_TREE_DS_TAG_HPP
|
||||
#endif
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
// -*- C++ -*-
|
||||
|
||||
// Copyright (C) 2005, 2006 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 2, 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 COPYING. If not, write to
|
||||
// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
|
||||
// MA 02111-1307, USA.
|
||||
|
||||
// As a special exception, you may use this file as part of a free
|
||||
// software library without restriction. Specifically, if other files
|
||||
// instantiate templates or use macros or inline functions from this
|
||||
// file, or you compile this file and link it with other files to
|
||||
// produce an executable, this file does not by itself cause the
|
||||
// resulting executable to be covered by the GNU General Public
|
||||
// License. This exception does not however invalidate any other
|
||||
// reasons why the executable file might be covered by the GNU General
|
||||
// Public License.
|
||||
|
||||
// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
|
||||
|
||||
// Permission to use, copy, modify, sell, and distribute this software
|
||||
// is hereby granted without fee, provided that the above copyright
|
||||
// notice appears in all copies, and that both that copyright notice
|
||||
// and this permission notice appear in supporting documentation. None
|
||||
// of the above authors, nor IBM Haifa Research Laboratories, make any
|
||||
// representation about the suitability of this software for any
|
||||
// purpose. It is provided "as is" without express or implied
|
||||
// warranty.
|
||||
|
||||
/**
|
||||
* @file native_tree_tag.hpp
|
||||
* Contains a tag for native tree-based containers
|
||||
*/
|
||||
|
||||
#ifndef PB_DS_NATIVE_PQ_DS_TAG_HPP
|
||||
#define PB_DS_NATIVE_PQ_DS_TAG_HPP
|
||||
|
||||
namespace pb_ds
|
||||
{
|
||||
|
||||
namespace test
|
||||
{
|
||||
|
||||
struct native_pq_tag
|
||||
{ };
|
||||
|
||||
} // namespace test
|
||||
|
||||
} // namespace pb_ds
|
||||
|
||||
#endif // #ifndef PB_DS_NATIVE_PQ_DS_TAG_HPP
|
|
@ -47,87 +47,66 @@
|
|||
#ifndef PB_DS_NATIVE_PRIORITY_QUEUE_HPP
|
||||
#define PB_DS_NATIVE_PRIORITY_QUEUE_HPP
|
||||
|
||||
#include <ext/pb_ds/detail/standard_policies.hpp>
|
||||
#include <ext/pb_ds/detail/type_utils.hpp>
|
||||
#include <native_type/priority_queue/native_pq_tag.hpp>
|
||||
#include <io/xml.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
#include <deque>
|
||||
#include <ext/pb_ds/detail/standard_policies.hpp>
|
||||
#include <ext/pb_ds/detail/type_utils.hpp>
|
||||
#include <io/xml.hpp>
|
||||
|
||||
namespace pb_ds
|
||||
{
|
||||
|
||||
namespace test
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<typename Value_Type, bool Vector, class Allocator>
|
||||
template<typename Value_Type, bool Vector, typename Allocator>
|
||||
struct base_seq
|
||||
{
|
||||
typedef
|
||||
std::vector<
|
||||
Value_Type,
|
||||
typename Allocator::template rebind<
|
||||
Value_Type>::other>
|
||||
type;
|
||||
private:
|
||||
typedef typename Allocator::template rebind<Value_Type> value_rebind;
|
||||
|
||||
public:
|
||||
typedef std::vector<Value_Type, typename value_rebind::other> type;
|
||||
};
|
||||
|
||||
template<typename Value_Type, class Allocator>
|
||||
struct base_seq<
|
||||
Value_Type,
|
||||
false,
|
||||
Allocator>
|
||||
template<typename Value_Type, typename Allocator>
|
||||
struct base_seq<Value_Type, false, Allocator>
|
||||
{
|
||||
typedef
|
||||
std::deque<
|
||||
Value_Type,
|
||||
typename Allocator::template rebind<
|
||||
Value_Type>::other>
|
||||
type;
|
||||
};
|
||||
private:
|
||||
typedef typename Allocator::template rebind<Value_Type> value_rebind;
|
||||
|
||||
public:
|
||||
typedef std::deque<Value_Type, typename value_rebind::other> type;
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
struct native_pq_tag
|
||||
{ };
|
||||
|
||||
#define PB_DS_CLASS_C_DEC \
|
||||
native_priority_queue< \
|
||||
Value_Type, \
|
||||
Vector, \
|
||||
Cmp_Fn, \
|
||||
Allocator>
|
||||
native_priority_queue<Value_Type, Vector, Cmp_Fn, Allocator>
|
||||
|
||||
#define PB_DS_BASE_C_DEC \
|
||||
std::priority_queue< \
|
||||
Value_Type, \
|
||||
typename detail::base_seq<Value_Type, Vector, Allocator>::type, \
|
||||
Cmp_Fn>
|
||||
std::priority_queue<Value_Type, typename detail::base_seq<Value_Type, Vector, Allocator>::type, Cmp_Fn>
|
||||
|
||||
template<typename Value_Type,
|
||||
bool Vector,
|
||||
class Cmp_Fn =
|
||||
std::less<Value_Type>,
|
||||
class Allocator = std::allocator<char> >
|
||||
typename Cmp_Fn = std::less<Value_Type>,
|
||||
typename Allocator = std::allocator<char> >
|
||||
class native_priority_queue : public PB_DS_BASE_C_DEC
|
||||
{
|
||||
private:
|
||||
typedef PB_DS_BASE_C_DEC base_type;
|
||||
typedef typename Allocator::template rebind<Value_Type> value_rebind;
|
||||
|
||||
public:
|
||||
typedef Value_Type value_type;
|
||||
|
||||
typedef
|
||||
typename Allocator::template rebind<
|
||||
value_type>::other::const_reference
|
||||
const_reference;
|
||||
|
||||
typedef typename value_rebind::other::const_reference const_reference;
|
||||
typedef native_pq_tag container_category;
|
||||
|
||||
typedef Cmp_Fn cmp_fn;
|
||||
|
||||
public:
|
||||
native_priority_queue() : base_type()
|
||||
{ }
|
||||
|
||||
|
@ -140,7 +119,6 @@ namespace pb_ds
|
|||
{
|
||||
if (Vector)
|
||||
return ("n_pq_vector");
|
||||
|
||||
return ("n_pq_deque");
|
||||
}
|
||||
|
||||
|
@ -148,44 +126,36 @@ namespace pb_ds
|
|||
desc()
|
||||
{
|
||||
if (Vector)
|
||||
return (make_xml_tag( "type", "value", "std::priority_queue_vector"));
|
||||
|
||||
return (make_xml_tag( "type", "value", "std::priority_queue_deque"));
|
||||
return make_xml_tag("type", "value", "std::priority_queue_vector");
|
||||
return make_xml_tag("type", "value", "std::priority_queue_deque");
|
||||
}
|
||||
|
||||
void
|
||||
clear()
|
||||
{
|
||||
* static_cast<base_type* >(this) = base_type();
|
||||
}
|
||||
{ *static_cast<base_type*>(this) = base_type(); }
|
||||
|
||||
void
|
||||
erase(const_reference r_val)
|
||||
{
|
||||
base_type tmp;
|
||||
|
||||
Cmp_Fn cmp;
|
||||
|
||||
while (cmp(base_type::top(), r_val) || cmp(r_val, base_type::top()))
|
||||
{
|
||||
tmp.push(base_type::top());
|
||||
|
||||
base_type::pop();
|
||||
}
|
||||
|
||||
if (!base_type::empty())
|
||||
{
|
||||
base_type::pop();
|
||||
|
||||
while (!base_type::empty())
|
||||
{
|
||||
tmp.push(base_type::top());
|
||||
|
||||
base_type::pop();
|
||||
}
|
||||
}
|
||||
|
||||
* static_cast<base_type* >(this) = tmp;
|
||||
*static_cast<base_type* >(this) = tmp;
|
||||
}
|
||||
|
||||
template<typename Pred>
|
||||
|
@ -193,21 +163,17 @@ namespace pb_ds
|
|||
erase_if(Pred pred)
|
||||
{
|
||||
base_type tmp;
|
||||
|
||||
std::size_t ersd = 0;
|
||||
|
||||
while (!base_type::empty())
|
||||
{
|
||||
if (!pred(base_type::top()))
|
||||
tmp.push(base_type::top());
|
||||
else
|
||||
++ersd;
|
||||
|
||||
base_type::pop();
|
||||
}
|
||||
|
||||
* static_cast<base_type* >(this) = tmp;
|
||||
|
||||
*static_cast<base_type*>(this) = tmp;
|
||||
return ersd;
|
||||
}
|
||||
|
||||
|
@ -216,27 +182,22 @@ namespace pb_ds
|
|||
split(Pred pred, PB_DS_CLASS_C_DEC& other)
|
||||
{
|
||||
base_type tmp;
|
||||
|
||||
other.clear();
|
||||
|
||||
while (!base_type::empty())
|
||||
{
|
||||
if (!pred(base_type::top()))
|
||||
tmp.push(base_type::top());
|
||||
else
|
||||
other.push(base_type::top());
|
||||
|
||||
base_type::pop();
|
||||
}
|
||||
|
||||
* static_cast<base_type* >(this) = tmp;
|
||||
*static_cast<base_type*>(this) = tmp;
|
||||
}
|
||||
|
||||
void
|
||||
modify(const_reference r_old, const_reference r_new)
|
||||
{
|
||||
erase(r_old);
|
||||
|
||||
push(r_new);
|
||||
}
|
||||
|
||||
|
@ -244,37 +205,30 @@ namespace pb_ds
|
|||
join(PB_DS_CLASS_C_DEC& other)
|
||||
{
|
||||
std::vector<value_type> a_tmp;
|
||||
|
||||
while (!base_type::empty())
|
||||
{
|
||||
a_tmp.push_back(base_type::top());
|
||||
|
||||
base_type::pop();
|
||||
}
|
||||
|
||||
while (!other.empty())
|
||||
{
|
||||
a_tmp.push_back(other.top());
|
||||
|
||||
other.pop();
|
||||
}
|
||||
|
||||
* static_cast<base_type* >(this) = base_type(a_tmp.begin(), a_tmp.end());
|
||||
*static_cast<base_type*>(this) = base_type(a_tmp.begin(), a_tmp.end());
|
||||
}
|
||||
|
||||
Cmp_Fn
|
||||
get_cmp_fn() const
|
||||
{
|
||||
return Cmp_Fn();
|
||||
}
|
||||
{ return Cmp_Fn(); }
|
||||
};
|
||||
|
||||
#undef PB_DS_BASE_C_DEC
|
||||
|
||||
#undef PB_DS_CLASS_C_DEC
|
||||
|
||||
} // namespace test
|
||||
|
||||
} // namespace pb_ds
|
||||
|
||||
#endif // #ifndef PB_DS_NATIVE_PRIORITY_QUEUE_HPP
|
||||
#endif
|
||||
|
|
|
@ -50,7 +50,6 @@
|
|||
#include <performance/time/timing_test_base.hpp>
|
||||
#include <performance/io/xml_formatter.hpp>
|
||||
#include <common_type/assoc/string_form.hpp>
|
||||
#include <statistic/res_recorder.hpp>
|
||||
#include <iterator>
|
||||
|
||||
namespace pb_ds
|
||||
|
|
|
@ -128,6 +128,9 @@ namespace pb_ds
|
|||
using pb_ds::test::detail::double_push_functor;
|
||||
using pb_ds::test::detail::double_push_join_functor;
|
||||
typedef pb_ds::test::detail::timing_test_base base_type;
|
||||
typedef double_push_functor<It, Cntnr> psh_fnct;
|
||||
typedef double_push_join_functor<It, Cntnr> psh_jn_fnct;
|
||||
|
||||
typedef xml_result_set_performance_formatter formatter_type;
|
||||
formatter_type res(string_form<Cntnr>::name(),
|
||||
string_form<Cntnr>::desc());
|
||||
|
@ -139,12 +142,12 @@ namespace pb_ds
|
|||
It e = m_ins_b;
|
||||
std::advance(e, v);
|
||||
|
||||
double_push_functor<It, Cntnr> double_push_fn(b, e);
|
||||
const double double_push_res = base_type::operator()(double_push_fn);
|
||||
double_push_join_functor<It, Cntnr> double_push_join_fn(b, e);
|
||||
const double double_push_join_res = base_type::operator()(double_push_join_fn);
|
||||
|
||||
const double effective_delta = std::max(double_push_join_res - double_push_res, base_type::min_time_res());
|
||||
psh_fnct double_push_fn(b, e);
|
||||
const double dbl_psh_res = base_type::operator()(double_push_fn);
|
||||
psh_jn_fnct dbl_psh_jn_fn(b, e);
|
||||
const double dbl_psh_jn_res = base_type::operator()(dbl_psh_jn_fn);
|
||||
const double min_res = double(timing_test_base::min_time_res());
|
||||
const double effective_delta = std::max(dbl_psh_jn_res - dbl_psh_res, min_res);
|
||||
res.add_res(v, effective_delta / v);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ namespace pb_ds
|
|||
{
|
||||
namespace detail
|
||||
{
|
||||
// Primary templates.
|
||||
template<typename It, class Cntnr, class Tag>
|
||||
class push_functor
|
||||
{
|
||||
|
@ -123,6 +124,7 @@ namespace pb_ds
|
|||
const value_type m_mod_val;
|
||||
};
|
||||
|
||||
// Specializations.
|
||||
template<typename It, class Cntnr>
|
||||
class push_functor<It, Cntnr, pb_ds::binary_heap_tag>
|
||||
{
|
||||
|
@ -148,6 +150,33 @@ namespace pb_ds
|
|||
const It m_ins_it_e;
|
||||
};
|
||||
|
||||
template<typename It, class Cntnr>
|
||||
class push_functor<It, Cntnr, pb_ds::test::native_pq_tag>
|
||||
{
|
||||
public:
|
||||
push_functor(It ins_it_b, It ins_it_e)
|
||||
: m_ins_it_b(ins_it_b), m_ins_it_e(ins_it_e)
|
||||
{ }
|
||||
|
||||
void
|
||||
operator()(std::size_t resolution)
|
||||
{
|
||||
typedef typename Cntnr::const_reference const_reference;
|
||||
for (std::size_t i = 0; i < resolution; ++i)
|
||||
{
|
||||
Cntnr c;
|
||||
|
||||
for (It ins_it = m_ins_it_b; ins_it != m_ins_it_e; ++ins_it)
|
||||
c.push(const_reference(ins_it->first));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const It m_ins_it_b;
|
||||
const It m_ins_it_e;
|
||||
};
|
||||
|
||||
|
||||
template<typename It, class Cntnr>
|
||||
class push_modify_functor<It, Cntnr, pb_ds::binary_heap_tag>
|
||||
{
|
||||
|
@ -190,32 +219,6 @@ namespace pb_ds
|
|||
const value_type m_mod_val;
|
||||
};
|
||||
|
||||
template<typename It, class Cntnr>
|
||||
class push_functor<It, Cntnr, pb_ds::test::native_pq_tag>
|
||||
{
|
||||
public:
|
||||
push_functor(It ins_it_b, It ins_it_e)
|
||||
: m_ins_it_b(ins_it_b), m_ins_it_e(ins_it_e)
|
||||
{ }
|
||||
|
||||
void
|
||||
operator()(std::size_t resolution)
|
||||
{
|
||||
typedef typename Cntnr::const_reference const_reference;
|
||||
for (std::size_t i = 0; i < resolution; ++i)
|
||||
{
|
||||
Cntnr c;
|
||||
|
||||
for (It ins_it = m_ins_it_b; ins_it != m_ins_it_e; ++ins_it)
|
||||
c.push(const_reference(ins_it->first));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const It m_ins_it_b;
|
||||
const It m_ins_it_e;
|
||||
};
|
||||
|
||||
template<typename It, class Cntnr>
|
||||
class push_modify_functor<It, Cntnr, pb_ds::test::native_pq_tag>
|
||||
{
|
||||
|
@ -291,8 +294,9 @@ namespace pb_ds
|
|||
typedef typename Cntnr::value_type value_type;
|
||||
typedef typename Cntnr::container_category container_category;
|
||||
typedef typename Cntnr::const_reference const_reference;
|
||||
typedef pb_ds::test::detail::timing_test_base timing_test_base;
|
||||
|
||||
typedef detail::timing_test_base timing_test_base;
|
||||
typedef detail::push_functor<It, Cntnr, container_category> psh_fnct;
|
||||
typedef detail::push_modify_functor<It, Cntnr, container_category> psh_mod_fnct;
|
||||
typedef xml_result_set_performance_formatter formatter_type;
|
||||
formatter_type res_set_fmt(string_form<Cntnr>::name(),
|
||||
string_form<Cntnr>::desc());
|
||||
|
@ -304,10 +308,8 @@ namespace pb_ds
|
|||
It e = m_ins_b;
|
||||
std::advance(e, v);
|
||||
|
||||
pb_ds::test::detail::push_functor<It, Cntnr, container_category>
|
||||
push_fn( b, e);
|
||||
|
||||
const double push_res = timing_test_base::operator()(push_fn);
|
||||
psh_fnct psh_fn(b, e);
|
||||
const double psh_res = timing_test_base::operator()(psh_fn);
|
||||
|
||||
value_type val = b->first;
|
||||
{
|
||||
|
@ -320,13 +322,12 @@ namespace pb_ds
|
|||
}
|
||||
}
|
||||
|
||||
pb_ds::test::detail::push_modify_functor<It, Cntnr, container_category>
|
||||
push_modify_fn(b, e, val);
|
||||
psh_mod_fnct psh_mod_fn(b, e, val);
|
||||
const double psh_mod_res = timing_test_base::operator()(psh_mod_fn);
|
||||
|
||||
const double push_modify_res = timing_test_base::operator()(push_modify_fn);
|
||||
|
||||
const double effective_delta = std::max(push_modify_res - push_res,
|
||||
timing_test_base::min_time_res());
|
||||
const double min_res = double(timing_test_base::min_time_res());
|
||||
const double effective_delta = std::max(psh_mod_res - psh_res,
|
||||
min_res);
|
||||
|
||||
res_set_fmt.add_res(v, effective_delta / v);
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
#define PB_DS_TIMING_TEST_BASE_HPP
|
||||
|
||||
#include <performance/time/elapsed_timer.hpp>
|
||||
#include <statistic/res_recorder.hpp>
|
||||
#include <statistic/result_recorder.hpp>
|
||||
|
||||
namespace pb_ds
|
||||
{
|
||||
|
@ -81,12 +81,12 @@ namespace pb_ds
|
|||
timing_test_base::operator()(Functor& fn)
|
||||
{
|
||||
const std::size_t resolution = get_min_resolution(fn);
|
||||
pb_ds::test::detail::res_recorder<double> rec;
|
||||
pb_ds::test::detail::result_recorder<double> rec;
|
||||
double res;
|
||||
do
|
||||
res = run_at_resolution(fn, resolution);
|
||||
while (rec.add_res(res) == false);
|
||||
res = rec.sample_mean() / resolution;
|
||||
while (rec.add_result(res) == false);
|
||||
res = rec.get_sample_mean() / resolution;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -101,22 +101,15 @@ namespace detail
|
|||
{
|
||||
private:
|
||||
typedef PB_DS_NATIVE_TYPE_TRAITS_C_DEC native_type_traits_base;
|
||||
|
||||
typedef PB_DS_TYPE_TRAITS_C_DEC type_traits_base;
|
||||
|
||||
public:
|
||||
typedef typename Cntnr::key_type key_type;
|
||||
|
||||
typedef typename Cntnr::const_key_reference const_key_reference;
|
||||
|
||||
typedef typename Cntnr::value_type value_type;
|
||||
|
||||
typedef typename Cntnr::const_reference const_reference;
|
||||
|
||||
typedef typename PB_DS_NATIVE_TYPE_TRAITS_C_DEC::type native_type;
|
||||
|
||||
typedef typename native_type::key_type native_key_type;
|
||||
|
||||
typedef typename native_type::value_type native_value_type;
|
||||
|
||||
enum
|
||||
|
@ -153,73 +146,49 @@ namespace detail
|
|||
|
||||
static void
|
||||
print_container(const Cntnr& r_c, std::ostream& r_os)
|
||||
{
|
||||
PB_DS_TYPE_TRAITS_C_DEC::print_container(r_c, r_os);
|
||||
}
|
||||
|
||||
public:
|
||||
{ PB_DS_TYPE_TRAITS_C_DEC::print_container(r_c, r_os); }
|
||||
|
||||
template<typename Gen>
|
||||
static key_type
|
||||
generate_key(Gen& r_gen, size_t max)
|
||||
{
|
||||
return PB_DS_TYPE_TRAITS_C_DEC::generate_key(r_gen, max);
|
||||
}
|
||||
{ return PB_DS_TYPE_TRAITS_C_DEC::generate_key(r_gen, max); }
|
||||
|
||||
template<typename Gen>
|
||||
static value_type
|
||||
generate_value(Gen& r_gen, size_t max)
|
||||
{
|
||||
return PB_DS_TYPE_TRAITS_C_DEC::generate_value(r_gen, max);
|
||||
}
|
||||
{ return PB_DS_TYPE_TRAITS_C_DEC::generate_value(r_gen, max); }
|
||||
|
||||
static const_key_reference
|
||||
extract_key(const_reference r_val)
|
||||
{
|
||||
return type_traits_base::extract_key(r_val);
|
||||
}
|
||||
{ return type_traits_base::extract_key(r_val); }
|
||||
|
||||
static native_key_type
|
||||
native_key(const_key_reference r_key)
|
||||
{
|
||||
return native_type_traits_base::native_key(r_key);
|
||||
}
|
||||
{ return native_type_traits_base::native_key(r_key); }
|
||||
|
||||
static native_value_type
|
||||
native_value(const_reference r_val)
|
||||
{
|
||||
return native_type_traits_base::native_value(r_val);
|
||||
}
|
||||
{ return native_type_traits_base::native_value(r_val); }
|
||||
|
||||
static const native_key_type&
|
||||
extract_native_key(const native_value_type& r_val)
|
||||
{
|
||||
return native_type_traits_base::extract_key(r_val);
|
||||
}
|
||||
{ return native_type_traits_base::extract_key(r_val); }
|
||||
|
||||
static bool
|
||||
cmp(const_reference r_val, const native_value_type& r_native_val)
|
||||
{
|
||||
return val_to_string(r_val) == native_val_to_string(r_native_val);
|
||||
}
|
||||
{ return val_to_string(r_val) == native_val_to_string(r_native_val); }
|
||||
|
||||
static std::string
|
||||
val_to_string(const_reference r_val)
|
||||
{
|
||||
return to_string(r_val);
|
||||
}
|
||||
{ return to_string(r_val); }
|
||||
|
||||
static std::string
|
||||
key_to_string(const_key_reference r_key)
|
||||
{
|
||||
return to_string(r_key);
|
||||
}
|
||||
{ return to_string(r_key); }
|
||||
|
||||
static std::string
|
||||
native_val_to_string(const native_value_type& r_native_val)
|
||||
{
|
||||
return to_string(r_native_val);
|
||||
}
|
||||
{ return to_string(r_native_val); }
|
||||
|
||||
static bool
|
||||
prefix_match(const_key_reference r_key, const std::string& r_native_key)
|
||||
|
@ -232,7 +201,6 @@ namespace detail
|
|||
|
||||
return native_substr == (const std::string&) r_key;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#undef PB_DS_TYPE_TRAITS_C_DEC
|
||||
|
|
|
@ -52,17 +52,13 @@
|
|||
|
||||
namespace pb_ds
|
||||
{
|
||||
|
||||
namespace test
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
struct regression_test_erase_if_fn : public std::unary_function<
|
||||
T,
|
||||
bool>
|
||||
struct regression_test_erase_if_fn
|
||||
: public std::unary_function<T, bool>
|
||||
{
|
||||
private:
|
||||
typedef const T& const_reference;
|
||||
|
@ -77,35 +73,23 @@ namespace pb_ds
|
|||
};
|
||||
|
||||
template<typename Hd, class Tl>
|
||||
struct regression_test_erase_if_fn<
|
||||
std::pair<
|
||||
Hd,
|
||||
Tl> > : public std::unary_function<
|
||||
std::pair<
|
||||
Hd,
|
||||
Tl>,
|
||||
bool>
|
||||
struct regression_test_erase_if_fn<std::pair<Hd, Tl> >
|
||||
: public std::unary_function<std::pair<Hd, Tl>, bool>
|
||||
{
|
||||
private:
|
||||
typedef const std::pair<Hd, Tl>& const_reference;
|
||||
|
||||
typedef regression_test_erase_if_fn< Hd> hd_erase_if_fn;
|
||||
|
||||
typedef regression_test_erase_if_fn< Tl> tl_erase_if_fn;
|
||||
typedef regression_test_erase_if_fn<Hd> hd_erase_if_fn;
|
||||
typedef regression_test_erase_if_fn<Tl> tl_erase_if_fn;
|
||||
|
||||
public:
|
||||
bool
|
||||
operator()(const_reference r_t) const
|
||||
{
|
||||
return (hd_erase_if_fn()(r_t.first)&&
|
||||
tl_erase_if_fn()(r_t.second));
|
||||
return (hd_erase_if_fn()(r_t.first) && tl_erase_if_fn()(r_t.second));
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace test
|
||||
|
||||
} // namespace pb_ds
|
||||
|
||||
#endif // #ifndef PB_DS_REGRESSION_TEST_ERASE_IF_FN_HPP
|
||||
#endif
|
||||
|
|
|
@ -52,82 +52,41 @@
|
|||
|
||||
namespace pb_ds
|
||||
{
|
||||
|
||||
namespace test
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
#define PB_DS_CLASS_T_DEC \
|
||||
template<typename Cntnr>
|
||||
|
||||
#define PB_DS_CLASS_C_DEC \
|
||||
regression_test_traits< \
|
||||
Cntnr>
|
||||
|
||||
template<typename Cntnr>
|
||||
struct regression_test_traits
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
typedef typename Cntnr::value_type value_type;
|
||||
|
||||
typedef typename Cntnr::const_reference const_reference;
|
||||
|
||||
typedef
|
||||
pb_ds::test::native_priority_queue<
|
||||
std::string,
|
||||
true>
|
||||
native_type;
|
||||
|
||||
typedef pb_ds::test::native_priority_queue<std::string, true> native_type;
|
||||
typedef typename native_type::value_type native_value_type;
|
||||
|
||||
template<typename T>
|
||||
struct erase_if_fn : public regression_test_erase_if_fn<
|
||||
T>
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
public:
|
||||
struct erase_if_fn : public regression_test_erase_if_fn<T>
|
||||
{ };
|
||||
|
||||
template<typename Gen>
|
||||
static value_type
|
||||
generate_value(Gen& r_gen, size_t max)
|
||||
{
|
||||
return basic_type(r_gen, max);
|
||||
}
|
||||
{ return basic_type(r_gen, max); }
|
||||
|
||||
static native_value_type
|
||||
native_value(const_reference r_val)
|
||||
{
|
||||
return (native_value_type(r_val));
|
||||
}
|
||||
{ return native_value_type(r_val); }
|
||||
|
||||
static bool
|
||||
cmp(const_reference r_val, const native_value_type& r_native_val)
|
||||
{
|
||||
return (val_to_string(r_val) == r_native_val);
|
||||
}
|
||||
{ return val_to_string(r_val) == r_native_val; }
|
||||
|
||||
static std::string
|
||||
val_to_string(const_reference r_val)
|
||||
{
|
||||
return (std::string(r_val));
|
||||
}
|
||||
|
||||
{ return std::string(r_val); }
|
||||
};
|
||||
|
||||
#undef PB_DS_CLASS_T_DEC
|
||||
|
||||
#undef PB_DS_CLASS_C_DEC
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace test
|
||||
|
||||
} // namespace pb_ds
|
||||
|
||||
#endif // #ifndef PB_DS_REGRESSION_TEST_TRAIT_HPP
|
||||
#endif
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
// warranty.
|
||||
|
||||
/**
|
||||
* @file res_recorder.hpp
|
||||
* @file result_recorder.hpp
|
||||
* Contains a class for recording results
|
||||
*/
|
||||
|
||||
|
@ -48,96 +48,61 @@
|
|||
#define PB_DS_RES_RECORDER_HPP
|
||||
|
||||
#include <statistic/sample_mean.hpp>
|
||||
#include <statistic/sample_var.hpp>
|
||||
#include <statistic/sample_variance.hpp>
|
||||
#include <statistic/sample_mean_confidence_checker.hpp>
|
||||
|
||||
namespace pb_ds
|
||||
{
|
||||
|
||||
namespace test
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
#define PB_DS_CLASS_T_DEC \
|
||||
template<typename Value_Type>
|
||||
|
||||
#define PB_DS_CLASS_C_DEC \
|
||||
res_recorder< \
|
||||
Value_Type>
|
||||
|
||||
/*
|
||||
* Records results until the probability that the sample mean is 10% away
|
||||
* from the true mean is ~ 0.05.
|
||||
*/
|
||||
template<typename Value_Type = double>
|
||||
class res_recorder
|
||||
template<typename Value_Type>
|
||||
class result_recorder
|
||||
{
|
||||
public:
|
||||
typedef Value_Type value_type;
|
||||
|
||||
public:
|
||||
res_recorder();
|
||||
result_recorder()
|
||||
: m_sample_mean(value_type()), m_sample_var(value_type())
|
||||
{ }
|
||||
|
||||
bool
|
||||
add_res(value_type res);
|
||||
add_result(value_type res);
|
||||
|
||||
inline value_type
|
||||
sample_mean() const;
|
||||
get_sample_mean() const
|
||||
{ return m_sample_mean; }
|
||||
|
||||
private:
|
||||
typedef std::list< value_type> list_t;
|
||||
|
||||
private:
|
||||
list_t m_l;
|
||||
typedef std::list<value_type> list_type;
|
||||
|
||||
list_type m_l;
|
||||
value_type m_sample_mean;
|
||||
|
||||
value_type m_sample_var;
|
||||
};
|
||||
|
||||
PB_DS_CLASS_T_DEC
|
||||
PB_DS_CLASS_C_DEC::
|
||||
res_recorder() :
|
||||
m_sample_mean(0)
|
||||
{ }
|
||||
|
||||
PB_DS_CLASS_T_DEC
|
||||
inline typename PB_DS_CLASS_C_DEC::value_type
|
||||
PB_DS_CLASS_C_DEC::
|
||||
sample_mean() const
|
||||
{
|
||||
return (m_sample_mean);
|
||||
}
|
||||
|
||||
PB_DS_CLASS_T_DEC
|
||||
template<typename Value_Type>
|
||||
bool
|
||||
PB_DS_CLASS_C_DEC::
|
||||
add_res(value_type res)
|
||||
result_recorder<Value_Type>::
|
||||
add_result(value_type res)
|
||||
{
|
||||
m_l.push_back(res);
|
||||
m_sample_mean = sample_mean(m_l.begin(), m_l.end());
|
||||
m_sample_var = sample_variance(m_l.begin(), m_l.end(), m_sample_mean);
|
||||
|
||||
m_sample_mean = pb_ds::test::detail::sample_mean(m_l.begin(), m_l.end());
|
||||
|
||||
const value_type sample_var =
|
||||
pb_ds::test::detail::sample_var(m_l.begin(), m_l.end(), m_sample_mean);
|
||||
|
||||
return (pb_ds::test::detail::sample_mean_confidence_checker(m_sample_mean,
|
||||
sample_var,
|
||||
std::distance(m_l.begin(), m_l.end()),
|
||||
0.1));
|
||||
size_t dist = std::distance(m_l.begin(), m_l.end());
|
||||
return sample_mean_confidence_checker(m_sample_mean, m_sample_var,
|
||||
dist, 0.1);
|
||||
}
|
||||
|
||||
#undef PB_DS_CLASS_T_DEC
|
||||
|
||||
#undef PB_DS_CLASS_C_DEC
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace test
|
||||
|
||||
} // namespace pb_ds
|
||||
|
||||
#endif // #ifndef PB_DS_RES_RECORDER_HPP
|
||||
#endif
|
||||
|
|
@ -54,16 +54,11 @@
|
|||
|
||||
namespace pb_ds
|
||||
{
|
||||
|
||||
namespace test
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
#define PB_DS_VTYPE \
|
||||
typename std::iterator_traits< \
|
||||
It>::value_type
|
||||
#define PB_DS_VTYPE typename std::iterator_traits<It>::value_type
|
||||
|
||||
template<typename It>
|
||||
PB_DS_VTYPE
|
||||
|
@ -71,17 +66,14 @@ namespace pb_ds
|
|||
{
|
||||
const PB_DS_VTYPE total = std::accumulate(b, e, PB_DS_VTYPE(0));
|
||||
const size_t num = std::distance(b, e);
|
||||
|
||||
return (total / num);
|
||||
return total / num;
|
||||
}
|
||||
|
||||
#undef PB_DS_VTYPE
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace test
|
||||
|
||||
} // namespace pb_ds
|
||||
|
||||
#endif // #ifndef PB_DS_SAMPLE_MEAN_HPP
|
||||
#endif
|
||||
|
||||
|
|
|
@ -53,25 +53,24 @@
|
|||
|
||||
namespace pb_ds
|
||||
{
|
||||
|
||||
namespace test
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/*
|
||||
* Checks that a sample mean sm is in the relative interval
|
||||
* relative_interval of a true mean (assuming i.i.d. samples),
|
||||
* given a sample variance sv taken over num_samples samples,
|
||||
* with confidence ~ 0.95.
|
||||
*
|
||||
* See "Probability, Random Variables, and Stochastic Processes" (Third edition)
|
||||
* Athanasios Papoulis, Chapter 9.
|
||||
* See "Probability, Random Variables, and Stochastic Processes"
|
||||
* (Third edition) Athanasios Papoulis, Chapter 9.
|
||||
*/
|
||||
template<typename Value_Type>
|
||||
bool
|
||||
sample_mean_confidence_checker(Value_Type sm, Value_Type sv, std::size_t num_samples, double relative_interval)
|
||||
sample_mean_confidence_checker(Value_Type sm, Value_Type sv,
|
||||
std::size_t num_samples,
|
||||
double relative_interval)
|
||||
{
|
||||
enum
|
||||
{
|
||||
|
@ -85,14 +84,11 @@ namespace pb_ds
|
|||
// This is z_u (normal-dist percentile) for u = 0.975.
|
||||
const Value_Type z = 1.976;
|
||||
|
||||
return (sv / ::sqrt(double(num_samples)) <= relative_interval* sm / z);
|
||||
return (sv / ::sqrt(double(num_samples)) <= relative_interval * sm / z);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace test
|
||||
|
||||
} // namespace pb_ds
|
||||
|
||||
#endif // #ifndef PB_DS_SAMPLE_MEAN_CONFIDENCE_CHECKER_HPP
|
||||
#endif
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
// warranty.
|
||||
|
||||
/**
|
||||
* @file sample_var.hpp
|
||||
* @file sample_variance.hpp
|
||||
* Contains a function for calculating a sample variance
|
||||
*/
|
||||
|
||||
|
@ -54,49 +54,38 @@
|
|||
|
||||
namespace pb_ds
|
||||
{
|
||||
|
||||
namespace test
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
#define PB_DS_VTYPE \
|
||||
typename std::iterator_traits< \
|
||||
It>::value_type
|
||||
#define PB_DS_VTYPE typename std::iterator_traits<It>::value_type
|
||||
|
||||
template<typename It>
|
||||
PB_DS_VTYPE
|
||||
sample_var(It b, It e, PB_DS_VTYPE sm)
|
||||
sample_variance(It b, It e, PB_DS_VTYPE sm)
|
||||
{
|
||||
PB_DS_VTYPE ss = 0;
|
||||
|
||||
size_t num_res = 0;
|
||||
|
||||
while (b != e)
|
||||
{
|
||||
const PB_DS_VTYPE d =* b - sm;
|
||||
|
||||
ss += d* d;
|
||||
|
||||
++num_res;
|
||||
|
||||
++b;
|
||||
}
|
||||
|
||||
if (num_res == 1)
|
||||
return (0);
|
||||
return 0;
|
||||
|
||||
return (::sqrt(ss / (num_res - 1)));
|
||||
return ::sqrt(ss / (num_res - 1));
|
||||
}
|
||||
|
||||
#undef PB_DS_VTYPE
|
||||
|
||||
} // namespace detail
|
||||
|
||||
} // namespace test
|
||||
|
||||
} // namespace pb_ds
|
||||
|
||||
#endif // #ifndef PB_DS_SAMPLE_VAR_HPP
|
||||
#endif
|
||||
|
Loading…
Add table
Reference in a new issue