summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHameer Abbasi <hameerabbasi@yahoo.com>2019-02-20 02:28:36 +0500
committerHameer Abbasi <hameerabbasi@yahoo.com>2019-02-20 02:28:36 +0500
commit7ce362e5ce1667ef60b2f45d52ebb08339a2c8b0 (patch)
treec49ab4c9bdd255c5f0a5822c7ae9c04c36c072e5
parent8aa669b22946e8f5aaaa591c37262b26ebd7976a (diff)
downloadnumpy-7ce362e5ce1667ef60b2f45d52ebb08339a2c8b0.tar.gz
Get rid of __getattr__ magic.
-rw-r--r--benchmarks/benchmarks/bench_function_base.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/benchmarks/benchmarks/bench_function_base.py b/benchmarks/benchmarks/bench_function_base.py
index a82d424e7..8a7bf362d 100644
--- a/benchmarks/benchmarks/bench_function_base.py
+++ b/benchmarks/benchmarks/bench_function_base.py
@@ -150,27 +150,28 @@ class SortGenerator(object):
np.random.shuffle(a[start:end])
return a
- def __getattr__(self, name):
+ @classmethod
+ def get_array(cls, array_type, size, dtype):
import re
import functools
token_specification = [
(r'sorted\_block\_([0-9]+)',
- lambda size, dtype, x: self._type_sorted_block(size, dtype, x)),
+ lambda size, dtype, x: cls._type_sorted_block(size, dtype, x)),
(r'swapped\_pair\_([0-9]+)\_percent',
- lambda size, dtype, x: self._type_swapped_pair(size, dtype, x / 100.0)),
+ lambda size, dtype, x: cls._type_swapped_pair(size, dtype, x / 100.0)),
(r'random\_unsorted\_area\_([0-9]+)\_percent',
- lambda size, dtype, x: self._type_random_unsorted_area(size, dtype, x / 100.0, self.AREA_SIZE)),
+ lambda size, dtype, x: cls._type_random_unsorted_area(size, dtype, x / 100.0, cls.AREA_SIZE)),
(r'random_bubble\_([0-9]+)\_fold',
- lambda size, dtype, x: self._type_random_unsorted_area(size, dtype, x * self.BUBBLE_SIZE / size, self.BUBBLE_SIZE)),
+ lambda size, dtype, x: cls._type_random_unsorted_area(size, dtype, x * cls.BUBBLE_SIZE / size, cls.BUBBLE_SIZE)),
]
for pattern, function in token_specification:
- match = re.fullmatch(pattern, name)
+ match = re.fullmatch(pattern, array_type)
if match is not None:
- return functools.partial(function, x=int(match.group(1)))
+ return function(size, dtype, int(match.group(1)))
- raise AttributeError
+ raise ValueError("Incorrect array_type specified.")
class Sort(Benchmark):
@@ -229,7 +230,7 @@ class Sort(Benchmark):
def setup(self, kind, dtype, array_type):
np.random.seed(1234)
- self.arr = getattr(SortGenerator(), array_type)(self.ARRAY_SIZE, dtype)
+ self.arr = SortGenerator.get_array(array_type, self.ARRAY_SIZE, dtype)
def time_sort_inplace(self, kind, dtype, array_type):
self.arr.sort(kind=kind)