Skip to content

Commit

Permalink
Classize benchmarks/indexing.py
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiisoup committed Jan 24, 2018
1 parent d5ad4a0 commit 4189d71
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
1 change: 0 additions & 1 deletion asv_bench/benchmarks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from __future__ import division
from __future__ import print_function
import itertools
import random

import numpy as np

Expand Down
28 changes: 8 additions & 20 deletions asv_bench/benchmarks/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pandas as pd
import xarray as xr

from . import randn, randint, requires_dask
from . import parameterized, randn, randint, requires_dask


nx = 3000
Expand Down Expand Up @@ -61,7 +61,7 @@


class Base(object):
def setup(self, key):
def setup(self, *args, **kwargs):
self.ds = xr.Dataset(
{'var1': (('x', 'y'), randn((nx, ny), frac_nan=0.1)),
'var2': (('x', 't'), randn((nx, nt))),
Expand All @@ -73,53 +73,41 @@ def setup(self, key):


class Indexing(Base):
@parameterized(['key'], (list(basic_indexes.keys())))
def time_indexing_basic(self, key):
self.ds.isel(**basic_indexes[key]).load()

time_indexing_basic.param_names = ['key']
time_indexing_basic.params = [list(basic_indexes.keys())]

@parameterized(['key'], (list(outer_indexes.keys())))
def time_indexing_outer(self, key):
self.ds.isel(**outer_indexes[key]).load()

time_indexing_outer.param_names = ['key']
time_indexing_outer.params = [list(outer_indexes.keys())]

@parameterized(['key'], (list(vectorized_indexes.keys())))
def time_indexing_vectorized(self, key):
self.ds.isel(**vectorized_indexes[key]).load()

time_indexing_vectorized.param_names = ['key']
time_indexing_vectorized.params = [list(vectorized_indexes.keys())]


class Assignment(Base):
@parameterized(['key'], (list(basic_indexes.keys())))
def time_assignment_basic(self, key):
ind = basic_indexes[key]
val = basic_assignment_values[key]
self.ds['var1'][ind.get('x', slice(None)),
ind.get('y', slice(None))] = val

time_assignment_basic.param_names = ['key']
time_assignment_basic.params = [list(basic_indexes.keys())]

@parameterized(['key'], (list(outer_indexes.keys())))
def time_assignment_outer(self, key):
ind = outer_indexes[key]
val = outer_assignment_values[key]
self.ds['var1'][ind.get('x', slice(None)),
ind.get('y', slice(None))] = val

time_assignment_outer.param_names = ['key']
time_assignment_outer.params = [list(outer_indexes.keys())]

@parameterized(['key'], (list(vectorized_indexes.keys())))
def time_assignment_vectorized(self, key):
ind = vectorized_indexes[key]
val = vectorized_assignment_values[key]
self.ds['var1'][ind.get('x', slice(None)),
ind.get('y', slice(None))] = val

time_assignment_vectorized.param_names = ['key']
time_assignment_vectorized.params = [list(vectorized_indexes.keys())]


class IndexingDask(Indexing):
def setup(self, key):
Expand Down

0 comments on commit 4189d71

Please sign in to comment.