histogram/doc/concepts.qbk
Hans Dembinski e742787353 improvements
2017-11-07 16:57:18 +01:00

59 lines
2.8 KiB
Plaintext

[section Concepts]
Users can extend the library with new axis and storage types.
[section:axis Axis type]
An `axis_type` converts input values into bin indices.
An `axis_type` is required to:
* derive from [classref boost::histogram::axis::axis_base] or [classref boost::histogram::axis::axis_base_uoflow]
* be default/copy/move constructable
* be copy/move assignable
* be equal comparable
* have a nested type `value_type` reflecting the type of the input values (may be a const reference if the input value is expensive to copy)
* have a nested type `bin_type`, which is a type that represents the bin, typically a semi-open interval (may be a const reference if the bin type is expensive to copy)
* have the following methods:
* `int index(value_type x) const`: takes an input value and returns the bin index
* `bin_type operator[](int index) const`: takes an index and returns the corresponding bin instance
* optionally, be streamable by implementation a free function
* `std::ostream operator<<(std::ostream&, const axis_type&)`
* optionally, be serializable, by implementing a member function template
* `template <class Archive> void serialize(Archive& ar, unsigned /* version */)`
The latter two are not needed, if the histogram that uses the custom axis type is never serialized or streamed.
It is recommended to take a look at the existing axis types, like [classref boost::histogram::axis::integer], which serve as templates to create new ones.
[endsect]
[section:storage Storage type]
A `storage_type` handles memory for the bin counters and provides a uniform interface for incrementing bin counters and reading their values.
A `storage_type` is required to:
* be default/copy/move constructable
* be copy/move assignable
* be equal comparable
* have a nested type `value_type`, the external type used to represent the bin count (internally it may be a different type)
* have a constructor `storage_type(std::size_t n)`, which prepares the storage of `n` bins.
* have the following methods and operators:
* `std::size_t size() const`
* `void increase(std::size_t index)`
* `void add(std::size_t index, const value_type& n)`
* `void add(std::size_t index, const value_type& value, const value_type& variance)`
* `value_type value(std::size_t index) const`
* `value_type variance(std::size_t index) const`
* `storage_type& operator+=(const storage_type& other)`
* `storage_type& operator*=(const value_type x)`
* optionally, it can have a method to support weighted fills:
* `void weighted_increase(std::size_t index, const value_type& weight)`
[classref boost::histogram::array_storage] is a simple storage type which does not support weighted fills. It may serve as a template to create a new storage type.
[endsect]
[endsect]