-
Notifications
You must be signed in to change notification settings - Fork 25
Class families #200
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
Class families #200
Conversation
|
@HDembinski, do you want correct >>> bh.Histogram # Correct
boost_histogram.Histogram
>>> import boost_histogram.cpp as bh
>>> bh.histogram # Correct
boost_histogram.cpp.histogram
>>> bh.axis.regular # Should be boost_histogram.cpp.axis.regular
boost_histogram.axis.RegularShould this report the correct module "boost_histogram.cpp.axis", and have the correct name "regular"? Also, I'm thinking if we move the repr's to Python, the CPP classes can have the original BoostHistogram reprs, which would be rather nice. It would give Python users access to the ascii histogram, which was one of the most popular parts of the talk at CHEP. Also, is the line printout available separately in Boost.Histogram? Also, do you want The cpp module is 100% yours, I'll craft it any way you like. But I need input. |
|
Separate question: Where do you like to set from numpy.core.overrides import set_module
@set_module("boost_histogram")
class Histogram ...
# (we probably would use our own set_module, it's just 4 lines)vs. class Histogram ...
Histogram.__module__ = "boost_histogram"vs. from _internal.hist import Histogram
Histogram.__module__ = "boost_histogram"I'm currently doing #2, but can switch if you have a preference; I don't. |
0c20aa8 to
5e0b004
Compare
|
I am ok with "wrong" |
|
Option 2 looks fine. |
I think it is ok if it is not correct. If you feel super strong about it and you are ok with having extra code complexity to have it right, I am ok with this. I personally think it is not worth it. Everything should look nice for the main module, but the cpp module is only there for convenience of some people who use C++ Boost.Histogram. This is a much smaller fraction of the user base and I think this fraction does not look at
Ok, good idea.
Feel free to adapt the code for boost-histogram. In Python, it is much easier to detect the terminal width. |
I don't feel super strong about it, but I've already written the code now to get it right on the plane (it's needed for returning the correct Axis from Histogram in cpp mode anyway), so the extra complexity is not that high to add it (lower than before). I'll complete the PR then make a comparison. It would take about 30 seconds to remove it if we decide to. It would be a bit harder to add to accumulators, so if you don't mind, I'd like to leave those unwrapped even if we wrap Storage/Transform. (And, three of the accumulators are going to be included in boost-histogram anyway, so they technically are not the same as in Boost.Histogram). |
|
Sounds all good. Sorry for prematurely removing the Storage class. |
f5f4933 to
2496a2e
Compare
fce67bf to
2a14ef7
Compare
2a14ef7 to
7fe70ec
Compare
|
I think this is finally ready for review, @HDembinski. I've listed the changes in the issue description. One key feature of building a general system to select between the normal and Future cleanup (later PR) will restructure the Also, due to the drastically different design direction I ended up taking, |
|
Edit: one more simplification I forgot to put in will be pushed in a moment |
HDembinski
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this solution at first glance, which makes me uncomfortable, but I don't want to block this. I hope you know what you are doing. In any case, this is not a change of the public interface, so go ahead.
|
Okay, there are lots of other fixes here I'd like to get in, and it will unblock future work. I do have an alternate solution in mind you might like better, a little simpler in some ways but with different tradeoffs. This is still a good base to compare them if we do want to try that solution. Let's try to discuss it early next week. |
|
(I'll write up an issue in the next few days that describes the current solution and proposes the alternative I have in mind, so you can pick or iterate. If we keep the current one, I can still use that to start the docs for it) |
|
It is not so urgent, I think. I am much more eager to fix the bugs that nsmith pointed out. |
|
We can always make the implementation nicer later :). |
|
Although if you want to depend on these facilities in hist, then it is kinda part of the public interface, although for developers and not for users. |
|
Yes, it affects the public interface for developers building on it, so we'll need to iron it out for Hist, but no rush quite yet. I'll probably aim for end-of-the-week then to write it up (busy week ahead), and no reason to work on it before 0.6.0. |
* Warning for uninitialized storage * Drop free functions, add __module__ and __all__ * Fix a few more missing __module__s * Clean up __all__ * Remove .reduce and .project from cpp class * Move Axis repr to Python and add transforms * Lookup for transforms works * Using repr from Python for Histogram * Use Boost.Histogram << as repr for cpp.histogram * Helpful error when C++ code not built * Use register for Axes * Use simpler storage scheme * Remove final _to_ function * CPP histogram returns CPP axis now * Revamp decorator system, now could be useful in other packages * Adding subclassing test * Adding Storage/Transforms to the register system * Simplify: no longer require @register for direct subclasses * Unicode strings in repr on Python 2 (fix test) * Simplify use of _compute_common_index * Drop a few extra __module__ sets that were superfluous * Fix __module__ on accumulators and slicing
Adding class families.
@set_family.cppclasses are now distinct, with reprs directly from C++'s<<.cppaxes are now distinct classes with C++ calling conventions, closes cpp mode methods #207@set_family@register(class_list)andcastinstead of a collection of_to_*functions and various._CLASSESand such. If there is just one C++ class associated (through subclassing) to a Python class,@registeris not needed.__module__is now being set to the correct locations using@set_module__all__has been added to public modules. It is always the third line, after the future stuff.Note that accumulators currently do not participate in the family scheme.