MCPcopy Create free account
hub / github.com/boostorg/histogram / fetcher

Class fetcher

src/python/histogram.cpp:172–202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170
171template <typename T>
172struct fetcher {
173 long n = -1;
174 union {
175 T value = 0;
176 const T* carray;
177 };
178 bp::object keep_alive;
179
180 void assign(bp::object o) {
181 // skipping check for currently held type, since it is always value
182 bp::extract<T> get_value(o);
183 if (get_value.check()) {
184 value = get_value();
185 n = 0;
186 return;
187 }
188#ifdef HAVE_NUMPY
189 np::ndarray a = np::from_object(o, np::dtype::get_builtin<T>(), 1);
190 carray = reinterpret_cast<const T*>(a.get_data());
191 n = a.shape(0);
192 keep_alive = a; // this may be a temporary object
193 return;
194#endif
195 throw std::invalid_argument("argument must be a number");
196 }
197
198 const T& operator[](long i) const noexcept {
199 if (n > 0) return carray[i];
200 return value;
201 }
202};
203
204template <typename T>
205struct span {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected