Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Commit c358ba9

Browse files
authored
Series.sum optimization (#585)
* Series.sum optimization * Add bool sum * combination of two implementations * Small fix
1 parent fd2e97a commit c358ba9

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

sdc/datatypes/hpat_pandas_series_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2838,8 +2838,8 @@ def hpat_pandas_series_sum_impl(
28382838
_skipna = skipna
28392839

28402840
if _skipna:
2841-
return numpy.nansum(self._data)
2842-
return numpy.sum(self._data)
2841+
return numpy_like.nansum(self._data)
2842+
return numpy_like.sum(self._data)
28432843

28442844
return hpat_pandas_series_sum_impl
28452845

sdc/functions/numpy_like.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,19 @@ def sdc_isnan_float_impl(self):
201201
ty_checker.raise_exc(dtype, 'int or float', 'self.dtype')
202202

203203

204+
def gen_sum_bool_impl():
205+
"""Generate sum bool implementation."""
206+
def _sum_bool_impl(self):
207+
length = len(self)
208+
result = 0
209+
for i in prange(length):
210+
result += self[i]
211+
212+
return result
213+
214+
return _sum_bool_impl
215+
216+
204217
@sdc_overload(sum)
205218
def sdc_sum_overload(self):
206219
"""
@@ -230,9 +243,12 @@ def sdc_sum_number_impl(self):
230243

231244
return sdc_sum_number_impl
232245

246+
if isinstance(dtype, (types.Boolean, bool)):
247+
return gen_sum_bool_impl()
248+
233249

234250
@sdc_overload(nansum)
235-
def sdc_sum_overload(self):
251+
def sdc_nansum_overload(self):
236252
"""
237253
Intel Scalable Dataframe Compiler Developer Guide
238254
*************************************************
@@ -258,6 +274,9 @@ def sdc_nansum_number_impl(self):
258274

259275
return sdc_nansum_number_impl
260276

277+
if isinstance(dtype, (types.Boolean, bool)):
278+
return gen_sum_bool_impl()
279+
261280

262281
def nanmin(a):
263282
pass

sdc/tests/test_series.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,6 +2319,14 @@ def test_impl(S):
23192319
S = pd.Series([1., 2., 3.])
23202320
self.assertEqual(hpat_func(S), test_impl(S))
23212321

2322+
def test_series_sum_bool(self):
2323+
def test_impl(S):
2324+
return S.sum()
2325+
hpat_func = self.jit(test_impl)
2326+
2327+
S = pd.Series([True, True, False])
2328+
self.assertEqual(hpat_func(S), test_impl(S))
2329+
23222330
def test_series_sum_nan(self):
23232331
def test_impl(S):
23242332
return S.sum()

0 commit comments

Comments
 (0)