Skip to content

Commit ccf23e9

Browse files
authored
Merge pull request #53 from histogrammar/turn_off_specialize_for_count
Turn off specialize() for Count objects
2 parents 4f20f1b + 61ab072 commit ccf23e9

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

histogrammar/defs.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ def specialize(self):
123123
These objects wouldn't satisfy any of ``addImplicitMethod``'s checks anyway.
124124
"""
125125
if spec:
126+
# MB 20220517: warning, this is a slow function.
127+
# Adding functions to each object, ideally avoid this.
126128
histogrammar.specialized.addImplicitMethods(self)
127129

128130
self.fill = FillMethod(self, self.fill)
@@ -236,8 +238,12 @@ def plot(self, httpServer=None, **parameters):
236238

237239
def __getstate__(self):
238240
state = dict(self.__dict__)
239-
del state["fill"]
240-
del state["plot"]
241+
for s in ['fill', 'plot']:
242+
# these states are set dynamically by FillMethod and PlotMethod, in factory.specialize().
243+
# MB 20220517: turned off specialize() for Count objects,
244+
# for which specialized fill and plot methods are not needed.
245+
if s in state:
246+
del state[s]
241247
return state
242248

243249
def __setstate__(self, dict):
@@ -1345,9 +1351,9 @@ def _c99StorageType(self):
13451351
def _cudaStorageType(self):
13461352
return self._c99StructName()
13471353

1348-
def fillnumpy(self, data):
1354+
def fillnumpy(self, data, weights=1.0):
13491355
self._checkForCrossReferences()
1350-
self._numpy(data, 1.0, [None])
1356+
self._numpy(data, weights, shape=[None])
13511357

13521358
def _checkNPQuantity(self, q, shape):
13531359
import numpy

histogrammar/primitives/count.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def ed(entries):
5050
raise ValueError("entries ({0}) cannot be negative".format(entries))
5151
out = Count()
5252
out.entries = float(entries)
53-
return out.specialize()
53+
return out
5454

5555
@staticmethod
5656
def ing(transform=identity):
@@ -69,7 +69,6 @@ def __init__(self, transform=identity):
6969
self.entries = 0.0
7070
self.transform = serializable(transform)
7171
super(Count, self).__init__()
72-
self.specialize()
7372

7473
@inheritdoc(Container)
7574
def zero(self):
@@ -80,7 +79,7 @@ def __add__(self, other):
8079
if isinstance(other, Count):
8180
out = Count(self.transform)
8281
out.entries = self.entries + other.entries
83-
return out.specialize()
82+
return out
8483
else:
8584
raise ContainerException("cannot add {0} and {1}".format(self.name, other.name))
8685

@@ -106,7 +105,7 @@ def __mul__(self, factor):
106105
else:
107106
out = self.zero()
108107
out.entries = factor * self.entries
109-
return out.specialize()
108+
return out
110109

111110
@inheritdoc(Container)
112111
def __rmul__(self, factor):
@@ -208,7 +207,7 @@ def _cudaUnpackAndFill(self, data, bigendian, alignment):
208207
def _cudaStorageType(self):
209208
return "float"
210209

211-
def _numpy(self, data, weights, shape):
210+
def _numpy(self, _, weights, shape):
212211
import numpy
213212
if isinstance(weights, numpy.ndarray):
214213
assert len(weights.shape) == 1

0 commit comments

Comments
 (0)