Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions boost_histogram/_internal/hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .axis import _to_axis, Axis
from .axistuple import AxesTuple
from .sig_tools import inject_signature
from .storage import Double, _to_storage
from .storage import Double

import warnings
import numpy as np
Expand Down Expand Up @@ -115,8 +115,6 @@ def __init__(self, *axes, **kwargs):
with KWArgs(kwargs) as k:
storage = k.optional("storage", Double())

storage = storage._get_storage_()

# Allow a tuple to represent a regular axis
axes = [_arg_shortcut(arg) for arg in axes]

Expand Down Expand Up @@ -218,7 +216,7 @@ def _axis(self, i):

@property
def _storage_type(self):
return _to_storage(self._hist._storage_type)
return self._hist._storage_type


class BoostHistogram(BaseHistogram):
Expand Down
60 changes: 9 additions & 51 deletions boost_histogram/_internal/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,12 @@

del absolute_import, division, print_function

from .._core import storage as store


class Storage(object):
__slots__ = ()

def __eq__(self, other):
return issubclass(other.__class__, self.__class__) or issubclass(
self.__class__, other.__class__
)

# Override this to allow configurable storages
@classmethod
def _get_storage_(cls):
return cls._STORAGE()


class Int(Storage):
_STORAGE = store.int


class Double(Storage):
_STORAGE = store.double


class AtomicInt(Storage):
_STORAGE = store.atomic_int


class Unlimited(Storage):
_STORAGE = store.unlimited


class Weight(Storage):
_STORAGE = store.weight


class Mean(Storage):
_STORAGE = store.mean


class WeightedMean(Storage):
_STORAGE = store.weighted_mean


def _to_storage(st):
for base in Storage.__subclasses__():
if st == base._STORAGE:
return base

raise TypeError("Invalid storage passed in")
from .._core import storage

Int = storage.int
Double = storage.double
AtomicInt = storage.atomic_int
Unlimited = storage.unlimited
Weight = storage.weight
Mean = storage.mean
WeightedMean = storage.weighted_mean
46 changes: 10 additions & 36 deletions boost_histogram/storage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import, division, print_function
from __future__ import absolute_import

del absolute_import, division, print_function
del absolute_import

import warnings

Expand All @@ -14,37 +14,11 @@
WeightedMean,
)


class DepStorageMixin(object):
@classmethod
def _get_storage_(cls):
warnings.warn("Use Int instead", DeprecationWarning)
return cls._STORAGE()


class int(DepStorageMixin, Int):
pass


class double(DepStorageMixin, Double):
pass


class unlimited(DepStorageMixin, Unlimited):
pass


class atomic_int(DepStorageMixin, AtomicInt):
pass


class weight(DepStorageMixin, Weight):
pass


class mean(DepStorageMixin, Mean):
pass


class weighted_mean(DepStorageMixin, WeightedMean):
pass
# for lazy folks
int = Int()
double = Double()
unlimited = Unlimited()
atomic_int = AtomicInt()
weight = Weight()
mean = Mean()
weighted_mean = WeightedMean()