mirror of
https://github.com/boostorg/histogram.git
synced 2025-05-11 13:14:06 +00:00
more refactoring
This commit is contained in:
parent
103fa6cf0a
commit
fbe82e3c58
@ -16,30 +16,17 @@ namespace histogram {
|
|||||||
class histogram : public histogram_base {
|
class histogram : public histogram_base {
|
||||||
public:
|
public:
|
||||||
histogram() {}
|
histogram() {}
|
||||||
|
histogram(const histogram& o);
|
||||||
|
explicit histogram(const axes_type& axes);
|
||||||
|
|
||||||
histogram(const histogram& o) :
|
#define BOOST_HISTOGRAM_CTOR(z, n, unused) \
|
||||||
histogram_base(o),
|
histogram( BOOST_PP_ENUM_PARAMS_Z(z, n, const axis_type& a) ) : \
|
||||||
data_(o.data_)
|
|
||||||
{}
|
|
||||||
|
|
||||||
explicit
|
|
||||||
histogram(const axes_type& axes) :
|
|
||||||
histogram_base(axes),
|
|
||||||
data_(field_count())
|
|
||||||
{}
|
|
||||||
|
|
||||||
#define BOOST_NHISTOGRAM_CTOR(z, n, unused) \
|
|
||||||
histogram( BOOST_PP_ENUM_PARAMS_Z(z, n, const axis_type& a) ) : \
|
|
||||||
histogram_base( BOOST_PP_ENUM_PARAMS_Z(z, n, a) ), \
|
histogram_base( BOOST_PP_ENUM_PARAMS_Z(z, n, a) ), \
|
||||||
data_(field_count()) \
|
data_(field_count()) \
|
||||||
{}
|
{}
|
||||||
|
|
||||||
// generates constructors taking 1 to AXIS_LIMIT arguments
|
// generates constructors taking 1 to AXIS_LIMIT arguments
|
||||||
BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_NHISTOGRAM_CTOR, nil)
|
BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_CTOR, nil)
|
||||||
|
|
||||||
unsigned depth() const { return data_.depth(); }
|
|
||||||
|
|
||||||
double sum() const;
|
|
||||||
|
|
||||||
template <typename Container>
|
template <typename Container>
|
||||||
inline
|
inline
|
||||||
@ -61,7 +48,7 @@ BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_NHISTOGRAM_CTOR, ni
|
|||||||
data_.increase(k);
|
data_.increase(k);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BOOST_NHISTOGRAM_FILL(z, n, unused) \
|
#define BOOST_HISTOGRAM_FILL(z, n, unused) \
|
||||||
inline \
|
inline \
|
||||||
void fill( BOOST_PP_ENUM_PARAMS_Z(z, n, double x) ) \
|
void fill( BOOST_PP_ENUM_PARAMS_Z(z, n, double x) ) \
|
||||||
{ \
|
{ \
|
||||||
@ -70,7 +57,7 @@ BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_NHISTOGRAM_CTOR, ni
|
|||||||
}
|
}
|
||||||
|
|
||||||
// generates fill functions taking 1 to AXIS_LIMT arguments
|
// generates fill functions taking 1 to AXIS_LIMT arguments
|
||||||
BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_NHISTOGRAM_FILL, nil)
|
BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_FILL, nil)
|
||||||
|
|
||||||
template <typename Container>
|
template <typename Container>
|
||||||
inline
|
inline
|
||||||
@ -92,7 +79,7 @@ BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_NHISTOGRAM_FILL, ni
|
|||||||
data_.increase(k, w);
|
data_.increase(k, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BOOST_NHISTOGRAM_WFILL(z, n, unused) \
|
#define BOOST_HISTOGRAM_WFILL(z, n, unused) \
|
||||||
inline \
|
inline \
|
||||||
void wfill( BOOST_PP_ENUM_PARAMS_Z(z, n, double x), double w ) \
|
void wfill( BOOST_PP_ENUM_PARAMS_Z(z, n, double x), double w ) \
|
||||||
{ \
|
{ \
|
||||||
@ -101,9 +88,10 @@ BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_NHISTOGRAM_FILL, ni
|
|||||||
}
|
}
|
||||||
|
|
||||||
// generates wfill functions taking 1 to AXIS_LIMT arguments
|
// generates wfill functions taking 1 to AXIS_LIMT arguments
|
||||||
BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_NHISTOGRAM_WFILL, nil)
|
BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_WFILL, nil)
|
||||||
|
|
||||||
template <typename Container>
|
template <typename Container>
|
||||||
|
inline
|
||||||
double value(const Container& idx)
|
double value(const Container& idx)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
@ -112,6 +100,7 @@ BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_NHISTOGRAM_WFILL, n
|
|||||||
}
|
}
|
||||||
|
|
||||||
// C-style call
|
// C-style call
|
||||||
|
inline
|
||||||
double value(unsigned n, const int* idx)
|
double value(unsigned n, const int* idx)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
@ -119,7 +108,8 @@ BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_NHISTOGRAM_WFILL, n
|
|||||||
return data_.value(linearize(idx));
|
return data_.value(linearize(idx));
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BOOST_NHISTOGRAM_VALUE(z, n, unused) \
|
#define BOOST_HISTOGRAM_VALUE(z, n, unused) \
|
||||||
|
inline \
|
||||||
double value( BOOST_PP_ENUM_PARAMS_Z(z, n, int i) ) \
|
double value( BOOST_PP_ENUM_PARAMS_Z(z, n, int i) ) \
|
||||||
const \
|
const \
|
||||||
{ \
|
{ \
|
||||||
@ -128,9 +118,10 @@ BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_NHISTOGRAM_WFILL, n
|
|||||||
}
|
}
|
||||||
|
|
||||||
// generates value functions taking 1 to AXIS_LIMT arguments
|
// generates value functions taking 1 to AXIS_LIMT arguments
|
||||||
BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_NHISTOGRAM_VALUE, nil)
|
BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_VALUE, nil)
|
||||||
|
|
||||||
template <typename Container>
|
template <typename Container>
|
||||||
|
inline
|
||||||
double variance(const Container& idx)
|
double variance(const Container& idx)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
@ -139,6 +130,7 @@ BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_NHISTOGRAM_VALUE, n
|
|||||||
}
|
}
|
||||||
|
|
||||||
// C-style call
|
// C-style call
|
||||||
|
inline
|
||||||
double variance(unsigned n, const int* idx)
|
double variance(unsigned n, const int* idx)
|
||||||
const
|
const
|
||||||
{
|
{
|
||||||
@ -146,7 +138,8 @@ BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_NHISTOGRAM_VALUE, n
|
|||||||
return data_.variance(linearize(idx));
|
return data_.variance(linearize(idx));
|
||||||
}
|
}
|
||||||
|
|
||||||
#define BOOST_NHISTOGRAM_VARIANCE(z, n, unused) \
|
#define BOOST_HISTOGRAM_VARIANCE(z, n, unused) \
|
||||||
|
inline \
|
||||||
double variance( BOOST_PP_ENUM_PARAMS_Z(z, n, int i) ) \
|
double variance( BOOST_PP_ENUM_PARAMS_Z(z, n, int i) ) \
|
||||||
const \
|
const \
|
||||||
{ \
|
{ \
|
||||||
@ -155,7 +148,11 @@ BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_NHISTOGRAM_VALUE, n
|
|||||||
}
|
}
|
||||||
|
|
||||||
// generates variance functions taking 1 to AXIS_LIMT arguments
|
// generates variance functions taking 1 to AXIS_LIMT arguments
|
||||||
BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_NHISTOGRAM_VARIANCE, nil)
|
BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_VARIANCE, nil)
|
||||||
|
|
||||||
|
unsigned depth() const { return data_.depth(); }
|
||||||
|
|
||||||
|
double sum() const;
|
||||||
|
|
||||||
bool operator==(const histogram& o) const
|
bool operator==(const histogram& o) const
|
||||||
{ return histogram_base::operator==(o) &&
|
{ return histogram_base::operator==(o) &&
|
||||||
|
@ -4,6 +4,16 @@
|
|||||||
namespace boost {
|
namespace boost {
|
||||||
namespace histogram {
|
namespace histogram {
|
||||||
|
|
||||||
|
histogram::histogram(const histogram& o) :
|
||||||
|
histogram_base(o),
|
||||||
|
data_(o.data_)
|
||||||
|
{}
|
||||||
|
|
||||||
|
histogram::histogram(const axes_type& axes) :
|
||||||
|
histogram_base(axes),
|
||||||
|
data_(field_count())
|
||||||
|
{}
|
||||||
|
|
||||||
double
|
double
|
||||||
histogram::sum()
|
histogram::sum()
|
||||||
const
|
const
|
||||||
|
@ -82,7 +82,7 @@ nstore::operator+=(const nstore& o)
|
|||||||
BOOST_HISTOGRAM_NSTORE_ADD(uint32_t);
|
BOOST_HISTOGRAM_NSTORE_ADD(uint32_t);
|
||||||
BOOST_HISTOGRAM_NSTORE_ADD(uint64_t);
|
BOOST_HISTOGRAM_NSTORE_ADD(uint64_t);
|
||||||
#undef BOOST_HISTOGRAM_NSTORE_ADD
|
#undef BOOST_HISTOGRAM_NSTORE_ADD
|
||||||
default: assert(!"invalid depth");
|
default: BOOST_ASSERT(!"invalid depth");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -120,7 +120,7 @@ nstore::variance(size_type i)
|
|||||||
BOOST_HISTOGRAM_NSTORE_VARIANCE(uint32_t);
|
BOOST_HISTOGRAM_NSTORE_VARIANCE(uint32_t);
|
||||||
BOOST_HISTOGRAM_NSTORE_VARIANCE(uint64_t);
|
BOOST_HISTOGRAM_NSTORE_VARIANCE(uint64_t);
|
||||||
#undef BOOST_HISTOGRAM_NSTORE_VARIANCE
|
#undef BOOST_HISTOGRAM_NSTORE_VARIANCE
|
||||||
default: assert(!"invalid depth");
|
default: BOOST_ASSERT(!"invalid depth");
|
||||||
}
|
}
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
@ -141,9 +141,9 @@ nstore::destroy()
|
|||||||
void
|
void
|
||||||
nstore::grow()
|
nstore::grow()
|
||||||
{
|
{
|
||||||
assert(depth_ > 0);
|
BOOST_ASSERT(depth_ > 0);
|
||||||
assert(depth_ < sizeof(uint64_t));
|
BOOST_ASSERT(depth_ < sizeof(uint64_t));
|
||||||
assert(buffer_ != 0);
|
BOOST_ASSERT(buffer_ != 0);
|
||||||
buffer_ = std::realloc(buffer_, size_ * 2 * depth_);
|
buffer_ = std::realloc(buffer_, size_ * 2 * depth_);
|
||||||
if (!buffer_) throw std::bad_alloc();
|
if (!buffer_) throw std::bad_alloc();
|
||||||
size_type i = size_;
|
size_type i = size_;
|
||||||
@ -164,7 +164,7 @@ nstore::grow()
|
|||||||
void
|
void
|
||||||
nstore::wconvert()
|
nstore::wconvert()
|
||||||
{
|
{
|
||||||
assert(depth_ < sizeof(wtype));
|
BOOST_ASSERT(depth_ < sizeof(wtype));
|
||||||
buffer_ = std::realloc(buffer_, size_ * sizeof(wtype));
|
buffer_ = std::realloc(buffer_, size_ * sizeof(wtype));
|
||||||
if (!buffer_) throw std::bad_alloc();
|
if (!buffer_) throw std::bad_alloc();
|
||||||
size_type i = size_;
|
size_type i = size_;
|
||||||
@ -196,7 +196,7 @@ nstore::ivalue(size_type i)
|
|||||||
BOOST_HISTOGRAM_NSTORE_IVALUE(uint32_t);
|
BOOST_HISTOGRAM_NSTORE_IVALUE(uint32_t);
|
||||||
BOOST_HISTOGRAM_NSTORE_IVALUE(uint64_t);
|
BOOST_HISTOGRAM_NSTORE_IVALUE(uint64_t);
|
||||||
#undef BOOST_HISTOGRAM_NSTORE_IVALUE
|
#undef BOOST_HISTOGRAM_NSTORE_IVALUE
|
||||||
default: assert(!"invalid depth");
|
default: BOOST_ASSERT(!"invalid depth");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user