Skip to content

Conversation

@henryiii
Copy link
Member

@henryiii henryiii commented Nov 25, 2019

This completes the array numpy-like interface, with set support. You can now do:

h = bh.Histogram(
    bh.axis.Regular(10, 0, 1), bh.axis.Regular(10, 0, 1), storage=bh.storage.Mean()
)

# New! Accumulators now support the buffer interface directly!
a = np.full((2, 2), bh.accumulators.Mean())

# New! Set with array
h[3:5, 3:5] = a

If you set with an array, and you leave off one or both endpoints, you can set the flow bins too:

h =  h = bh.Histogram(bh.axis.Regular(10, 0, 1))
h[:] = np.arange(10) # Flow bins are still 0
h[:] = np.arange(11) # ERROR: must match size with or without flow bins
h[:] = np.arange(12) # Flow bins are set
h[0:] = np.arange(11) # Overflow bin is set
h[0:10] = np.arange(12) # ERROR: flow bins cannot be set with specified endpoints

A few notes:

These are not supposed to be deficiencies, just choices.

Dimension adding broadcasting is not supported.

You have to be explicit unless setting with a scalar:

h2[:, :] = 0 # Allowed
h2[:, :] = arr.flatten() # Not allowed, must explicitly add an axis
h2[:, :] = arr.flatten()[:, np.newaxis] # Will broadcast if first dimension matches like numpy

Explicit is better than implicit (and in some cases, Numpy actually does this too, such as when setting a non-complete range on the left).

Mismatched data type dimensions not supported

You can't write

h[...] = 1

If h has a 2, 3, or 4 item dtype (accumulators).


Currently, setting a histogram with another histogram is not supported, use h[...] = h2.view().

Removes the old experimental copy_in, this now can be accomplished in Python without the C++ due to the full no-copy views on all storages!

Now only adds the helpful message about compiling if it was truly not able to import _core.

Includes more docs, including a fix for another invalid statement.

Closes #189.

@henryiii henryiii requested a review from HDembinski November 26, 2019 00:46
@henryiii henryiii merged commit 57bbb7f into develop Nov 26, 2019
@henryiii henryiii deleted the henryiii-arrset branch November 26, 2019 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set with array

2 participants