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
14 changes: 10 additions & 4 deletions histogrammar/defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions histogrammar/primitives/count.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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))

Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down