|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# ***************************************************************************** |
| 3 | +# Copyright (c) 2020, Intel Corporation All rights reserved. |
| 4 | +# |
| 5 | +# Redistribution and use in source and binary forms, with or without |
| 6 | +# modification, are permitted provided that the following conditions are met: |
| 7 | +# |
| 8 | +# Redistributions of source code must retain the above copyright notice, |
| 9 | +# this list of conditions and the following disclaimer. |
| 10 | +# |
| 11 | +# Redistributions in binary form must reproduce the above copyright notice, |
| 12 | +# this list of conditions and the following disclaimer in the documentation |
| 13 | +# and/or other materials provided with the distribution. |
| 14 | +# |
| 15 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 16 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 17 | +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 18 | +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
| 19 | +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 20 | +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
| 25 | +# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | +# ***************************************************************************** |
| 27 | +import string |
| 28 | +import time |
| 29 | + |
| 30 | +import numba |
| 31 | +import pandas |
| 32 | +import numpy as np |
| 33 | + |
| 34 | +from sdc.tests.test_utils import test_global_input_data_float64 |
| 35 | +from sdc.tests.tests_perf.test_perf_base import TestBase |
| 36 | +from sdc.tests.tests_perf.test_perf_utils import (calc_compilation, get_times, |
| 37 | + perf_data_gen_fixed_len) |
| 38 | +from .generator import generate_test_cases |
| 39 | +from .generator import TestCase as TC |
| 40 | + |
| 41 | + |
| 42 | +def get_rolling_params(window=100, min_periods=None): |
| 43 | + """Generate supported rolling parameters""" |
| 44 | + rolling_params = [f'{window}'] |
| 45 | + if min_periods: |
| 46 | + rolling_params.append(f'min_periods={min_periods}') |
| 47 | + |
| 48 | + return ', '.join(rolling_params) |
| 49 | + |
| 50 | + |
| 51 | +# python -m sdc.runtests sdc.tests.tests_perf.test_perf_series_rolling.TestSeriesRollingMethods |
| 52 | +class TestSeriesRollingMethods(TestBase): |
| 53 | + # more than 19 columns raise SystemError: CPUDispatcher() returned a result with an error set |
| 54 | + max_columns_num = 19 |
| 55 | + |
| 56 | + @classmethod |
| 57 | + def setUpClass(cls): |
| 58 | + super().setUpClass() |
| 59 | + |
| 60 | + def _test_case(self, pyfunc, name, total_data_length, data_num=1, |
| 61 | + input_data=test_global_input_data_float64): |
| 62 | + test_name = 'Series.rolling.{}'.format(name) |
| 63 | + |
| 64 | + if input_data is None: |
| 65 | + input_data = test_global_input_data_float64 |
| 66 | + |
| 67 | + full_input_data_length = sum(len(i) for i in input_data) |
| 68 | + for data_length in total_data_length: |
| 69 | + base = { |
| 70 | + 'test_name': test_name, |
| 71 | + 'data_size': data_length, |
| 72 | + } |
| 73 | + data = perf_data_gen_fixed_len(input_data, full_input_data_length, data_length) |
| 74 | + test_data = pandas.Series(data) |
| 75 | + |
| 76 | + args = [test_data] |
| 77 | + for i in range(data_num - 1): |
| 78 | + np.random.seed(i) |
| 79 | + extra_data = np.random.ranf(data_length) |
| 80 | + args.append(pandas.Series(extra_data)) |
| 81 | + |
| 82 | + self._test_jit(pyfunc, base, *args) |
| 83 | + self._test_py(pyfunc, base, *args) |
| 84 | + |
| 85 | + |
| 86 | +cases = [ |
| 87 | + TC(name='apply', size=[10 ** 7], params='func=lambda x: numpy.nan if len(x) == 0 else x.mean()'), |
| 88 | + TC(name='corr', size=[10 ** 7]), |
| 89 | + TC(name='count', size=[10 ** 7]), |
| 90 | + TC(name='cov', size=[10 ** 7]), |
| 91 | + TC(name='kurt', size=[10 ** 7]), |
| 92 | + TC(name='max', size=[10 ** 7]), |
| 93 | + TC(name='mean', size=[10 ** 7]), |
| 94 | + TC(name='median', size=[10 ** 7]), |
| 95 | + TC(name='min', size=[10 ** 7]), |
| 96 | + TC(name='quantile', size=[10 ** 7], params='0.2'), |
| 97 | + TC(name='skew', size=[10 ** 7]), |
| 98 | + TC(name='std', size=[10 ** 7]), |
| 99 | + TC(name='sum', size=[10 ** 7]), |
| 100 | + TC(name='var', size=[10 ** 7]), |
| 101 | +] |
| 102 | + |
| 103 | + |
| 104 | +generate_test_cases(cases, TestSeriesRollingMethods, 'series', 'rolling({})'.format(get_rolling_params())) |
0 commit comments