diff --git a/histogrammar/defs.py b/histogrammar/defs.py index 8ef0f55..63e60a2 100644 --- a/histogrammar/defs.py +++ b/histogrammar/defs.py @@ -123,6 +123,8 @@ def specialize(self): These objects wouldn't satisfy any of ``addImplicitMethod``'s checks anyway. """ if spec: + # MB 20220517: warning, this is a slow function. + # Adding functions to each object, ideally avoid this. histogrammar.specialized.addImplicitMethods(self) self.fill = FillMethod(self, self.fill) @@ -236,8 +238,12 @@ def plot(self, httpServer=None, **parameters): def __getstate__(self): state = dict(self.__dict__) - del state["fill"] - del state["plot"] + for s in ['fill', 'plot']: + # these states are set dynamically by FillMethod and PlotMethod, in factory.specialize(). + # MB 20220517: turned off specialize() for Count objects, + # for which specialized fill and plot methods are not needed. + if s in state: + del state[s] return state def __setstate__(self, dict): @@ -1345,9 +1351,9 @@ def _c99StorageType(self): def _cudaStorageType(self): return self._c99StructName() - def fillnumpy(self, data): + def fillnumpy(self, data, weights=1.0): self._checkForCrossReferences() - self._numpy(data, 1.0, [None]) + self._numpy(data, weights, shape=[None]) def _checkNPQuantity(self, q, shape): import numpy diff --git a/histogrammar/primitives/count.py b/histogrammar/primitives/count.py index 58be22c..17dc442 100644 --- a/histogrammar/primitives/count.py +++ b/histogrammar/primitives/count.py @@ -50,7 +50,7 @@ def ed(entries): raise ValueError("entries ({0}) cannot be negative".format(entries)) out = Count() out.entries = float(entries) - return out.specialize() + return out @staticmethod def ing(transform=identity): @@ -69,7 +69,6 @@ def __init__(self, transform=identity): self.entries = 0.0 self.transform = serializable(transform) super(Count, self).__init__() - self.specialize() @inheritdoc(Container) def zero(self): @@ -80,7 +79,7 @@ def __add__(self, other): if isinstance(other, Count): out = Count(self.transform) out.entries = self.entries + other.entries - return out.specialize() + return out else: raise ContainerException("cannot add {0} and {1}".format(self.name, other.name)) @@ -106,7 +105,7 @@ def __mul__(self, factor): else: out = self.zero() out.entries = factor * self.entries - return out.specialize() + return out @inheritdoc(Container) def __rmul__(self, factor): @@ -208,7 +207,7 @@ def _cudaUnpackAndFill(self, data, bigendian, alignment): def _cudaStorageType(self): return "float" - def _numpy(self, data, weights, shape): + def _numpy(self, _, weights, shape): import numpy if isinstance(weights, numpy.ndarray): assert len(weights.shape) == 1