@@ -101,8 +101,8 @@ using arg_t = variant::variant<c_array_t<double>,
101
101
int ,
102
102
c_array_t <std::string>,
103
103
std::string>;
104
-
105
- using weight_t = variant::variant<variant::monostate, double , c_array_t <double >>;
104
+ template < class T >
105
+ using weight_t = variant::variant<variant::monostate, T , c_array_t <T >>;
106
106
107
107
inline auto get_vargs (const vector_axis_variant& axes, const py::args& args) {
108
108
if (args.size () != axes.size ())
@@ -131,25 +131,26 @@ inline auto get_vargs(const vector_axis_variant& axes, const py::args& args) {
131
131
return vargs;
132
132
}
133
133
134
- inline auto get_weight (py::kwargs& kwargs) {
134
+ template <class T >
135
+ auto get_weight (py::kwargs& kwargs) {
135
136
// default constructed as monostate to indicate absence of weight
136
- variant::variant<variant::monostate, double , c_array_t < double > > weight;
137
+ weight_t <T > weight;
137
138
auto w = optional_arg (kwargs, " weight" );
138
139
if (!w.is_none ()) {
139
- if (is_value<double >(w))
140
- weight = py::cast<double >(w);
140
+ if (is_value<T >(w))
141
+ weight = py::cast<T >(w);
141
142
else
142
- weight = py::cast<c_array_t <double >>(w);
143
+ weight = py::cast<c_array_t <T >>(w);
143
144
}
144
145
return weight;
145
146
}
146
147
147
148
// for accumulators that accept a weight
148
- template <class Histogram , class VArgs >
149
+ template <class weight_type , class Histogram , class VArgs >
149
150
void fill_impl (bh::detail::accumulator_traits_holder<true >,
150
151
Histogram& h,
151
152
const VArgs& vargs,
152
- const weight_t & weight,
153
+ const weight_t <weight_type> & weight,
153
154
py::kwargs& kwargs) {
154
155
finalize_args (kwargs);
155
156
@@ -162,11 +163,11 @@ void fill_impl(bh::detail::accumulator_traits_holder<true>,
162
163
}
163
164
164
165
// for accumulators that accept a weight and a double
165
- template <class Histogram , class VArgs >
166
+ template <class weight_type , class Histogram , class VArgs >
166
167
void fill_impl (bh::detail::accumulator_traits_holder<true , const double &>,
167
168
Histogram& h,
168
169
const VArgs& vargs,
169
- const weight_t & weight,
170
+ const weight_t <weight_type> & weight,
170
171
py::kwargs& kwargs) {
171
172
auto s = required_arg (kwargs, " sample" );
172
173
finalize_args (kwargs);
@@ -191,10 +192,14 @@ void fill_impl(bh::detail::accumulator_traits_holder<true, const double&>,
191
192
template <class Histogram >
192
193
Histogram& fill (Histogram& self, py::args args, py::kwargs kwargs) {
193
194
using value_type = typename Histogram::value_type;
194
- detail::fill_impl (bh::detail::accumulator_traits<value_type>{},
195
- self,
196
- detail::get_vargs (bh::unsafe_access::axes (self), args),
197
- detail::get_weight (kwargs),
198
- kwargs);
195
+ using weight_type
196
+ = boost::mp11::mp_if_c<std::is_integral<value_type>::value, int , double >;
197
+
198
+ detail::fill_impl<weight_type>(
199
+ bh::detail::accumulator_traits<value_type>{},
200
+ self,
201
+ detail::get_vargs (bh::unsafe_access::axes (self), args),
202
+ detail::get_weight<weight_type>(kwargs),
203
+ kwargs);
199
204
return self;
200
205
}
0 commit comments