Merge branch 'cleanup' into doc

This commit is contained in:
klemens-morgenstern 2016-06-18 21:04:21 +02:00
commit 98c6fbc575
3 changed files with 19 additions and 17 deletions

View File

@ -99,12 +99,13 @@ BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_BASE_CTOR
return lin.k; return lin.k;
} }
template<typename Range>
inline inline
size_type linearize(const int* idx) const { size_type linearize(const Range &r) const {
detail::linearize lin(false); detail::linearize lin(false);
int i = axes_.size(); int i = axes_.size();
while (i--) { while (i--) {
lin.j = idx[i]; lin.j = r[i];
apply_visitor(lin, axes_[i]); apply_visitor(lin, axes_[i]);
} }
return lin.k; return lin.k;

View File

@ -169,13 +169,12 @@ BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_WFILL, ni
void fill(double x0, ...); void fill(double x0, ...);
#endif #endif
// C-style call // C-style call
inline template<typename Iterator>
double value_c(unsigned n, const int* idx) inline double value(boost::iterator_range<Iterator> range) const
const
{ {
if (n != dim()) if (range.size() != dim())
throw std::range_error("wrong number of arguments"); throw std::range_error("wrong number of arguments");
return data_.value(linearize(idx)); return data_.value(linearize(range));
} }
#define BOOST_HISTOGRAM_VALUE(z, n, unused) \ #define BOOST_HISTOGRAM_VALUE(z, n, unused) \
@ -184,20 +183,20 @@ BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_WFILL, ni
const \ const \
{ \ { \
const int idx[n] = { BOOST_PP_ENUM_PARAMS_Z(z, n, i) }; \ const int idx[n] = { BOOST_PP_ENUM_PARAMS_Z(z, n, i) }; \
return value_c(n, idx); /* size is checked here */ \ return value(boost::make_iterator_range( \
boost::begin(idx), boost::end(idx) \
)); /* size is checked here */ \
} }
// 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_HISTOGRAM_VALUE, nil) BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_VALUE, nil)
// C-style call template<typename Iterator>
inline inline double variance(boost::iterator_range<Iterator> range) const
double variance_c(unsigned n, const int* idx)
const
{ {
if (n != dim()) if (range.size() != dim())
throw std::runtime_error("wrong number of arguments"); throw std::runtime_error("wrong number of arguments");
return data_.variance(linearize(idx)); return data_.variance(linearize(range));
} }
#define BOOST_HISTOGRAM_VARIANCE(z, n, unused) \ #define BOOST_HISTOGRAM_VARIANCE(z, n, unused) \
@ -206,7 +205,9 @@ BOOST_PP_REPEAT_FROM_TO(1, BOOST_HISTOGRAM_AXIS_LIMIT, BOOST_HISTOGRAM_VALUE, ni
const \ const \
{ \ { \
const int idx[n] = { BOOST_PP_ENUM_PARAMS_Z(z, n, i) }; \ const int idx[n] = { BOOST_PP_ENUM_PARAMS_Z(z, n, i) }; \
return variance_c(n, idx); /* size is checked here */ \ return variance(boost::make_iterator_range( \
boost::begin(idx), boost::end(idx) \
)); /* size is checked here */ \
} }
// generates variance functions taking 1 to AXIS_LIMT arguments // generates variance functions taking 1 to AXIS_LIMT arguments

View File

@ -184,7 +184,7 @@ histogram_value(python::tuple args, python::dict kwargs) {
for (unsigned i = 0; i < self.dim(); ++i) for (unsigned i = 0; i < self.dim(); ++i)
idx[i] = extract<int>(args[1 + i]); idx[i] = extract<int>(args[1 + i]);
return object(self.value_c(self.dim(), idx)); return object(self.value(boost::make_iterator_range(idx, idx + self.dim())));
} }
python::object python::object
@ -206,7 +206,7 @@ histogram_variance(python::tuple args, python::dict kwargs) {
for (unsigned i = 0; i < self.dim(); ++i) for (unsigned i = 0; i < self.dim(); ++i)
idx[i] = extract<int>(args[1 + i]); idx[i] = extract<int>(args[1 + i]);
return object(self.variance_c(self.dim(), idx)); return object(self.variance(boost::make_iterator_range(idx, idx + self.dim())));
} }
class histogram_access { class histogram_access {