Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New axis: piecewise_regular #47

Open
HDembinski opened this issue Jun 19, 2018 · 6 comments · May be fixed by #386
Open

New axis: piecewise_regular #47

HDembinski opened this issue Jun 19, 2018 · 6 comments · May be fixed by #386

Comments

@HDembinski
Copy link
Collaborator

A composed axis of several connected regular axis without gaps. Should use regular_axis underneath.

@HDembinski HDembinski added this to the 4.1 milestone Jan 19, 2019
@swornim1
Copy link

swornim1 commented Apr 2, 2019

I would like to work on this project. Please explain the further details required to accomplish the task. Thank you.

@HDembinski
Copy link
Collaborator Author

Hi,

thank you for your interest.

you should look into the implementation of boost::histogram::axis::regular to get an idea how this axis would work, also have a look at the Axis concept in the documentation.

I gave this axis more thought in the meantime and it should be even more generalized: piecewise is a new axis which pieces several other axis types together.

template <class... Ts>
class piecewise { ... };

The Ts... are other axis types.

It is created by a make_piecewise factory function.

template <class... Ts>
piecewise<Ts...> make_piecewise(Ts... ts) {
    ...
}

Upon construction, piecewise checks that the boundaries of its axis arguments are connected, meaning that the uppermost bin edge of the first axis is equal to the lowermost bin edge of the second axis, etc. It keeps a std::tuple of the axis types. When a value is passed to the index method, it looks the sub-axis up whose range covers the argument value and passes the value to index method of that sub-axis. The index returned is shifted by the number of bins left of that sub-axis.

@HDembinski HDembinski modified the milestones: 1.71, 1.72 Aug 20, 2019
@HDembinski HDembinski removed this from the 1.72 milestone Oct 19, 2019
@ryanelandt
Copy link

Are you looking for a new axis that pieces together:

  1. truly arbitrary axis types,
  2. arbitrary regular axis types, or
  3. arbitrary regular and variable axis types?
    In other words:
make_piecewise(axis::category, axis::boolean, axis::regular)           // 1
make_piecewise(axis::regular<sqrt>, axis:regular, axis::regular<log>)  // 2
make_piecewise(axis::variable, axis::regular)                          // 3

If it's the first one, what is the use case?

@HDembinski
Copy link
Collaborator Author

I was originally thinking only of 2) but 3) is a natural generalization. As a further generalization, it would be great to also stitch integer axes together, but then the code needs to ensure that integer axes cannot be mixed with regular or variable axes. This can be achieved with a static_assert on the value_type of the axes, they either need to be all integer or all floating point. make_piecewise should check axis::trait::continuous and reject axes that are not continuous.

We cannot do 1). It only makes sense to stitch continuous unbounded axes together, so we don't need to worry about stitching axis::category or axis::boolean.

@ryanelandt
Copy link

I can see how piecing together floating axis types might give spacing that is difficult to achieve with a simple transformation (e.g., sqrt, log, etc). But, I'm not seeing why one would want to stitch together integer axes. If I understand it correctly, the width of an integer axis is always one. Is there a potential advantage?

@HDembinski
Copy link
Collaborator Author

But, I'm not seeing why one would want to stitch together integer axes.

True, it makes no sense if we do not allow gaps between consecutive axes. I had not read the whole issue again to refresh my memory, so I was considering to allow gaps between axes. In that case it might be useful to stitch several integer axes together with gaps between them.

You could use a category axis to have gaps in an integer range, but bin lookup for a category axis is more expensive and you need to allocate memory from the heap for a category axis, as opposed to an integer axis.

@ryanelandt ryanelandt linked a pull request Jun 13, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants