Skip to content

Commit

Permalink
Merge pull request #138 from Crunch-io/enable-pruning-in-min-base-size
Browse files Browse the repository at this point in the history
Enable pruning in min base size
  • Loading branch information
slobodan-ilic committed Feb 18, 2019
2 parents 7817a33 + e6c056b commit ffc5514
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ The detailed description can be found

## Changes

#### 1.9.8
- Enable pruning for min-base-size masks

#### 1.9.7
- Implement Min Base Size suppression masks

Expand Down
2 changes: 1 addition & 1 deletion src/cr/cube/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

"""Initialization module for crunch-cube package."""

__version__ = "1.9.7"
__version__ = "1.9.8"
4 changes: 2 additions & 2 deletions src/cr/cube/cube_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def margin(

return self._extract_slice_result_from_cube(margin)

def min_base_size_mask(self, size, hs_dims=None):
def min_base_size_mask(self, size, hs_dims=None, prune=False):
"""Returns MinBaseSizeMask object with correct row, col and table masks.
The returned object stores the necessary information about the base size, as
Expand All @@ -292,7 +292,7 @@ def min_base_size_mask(self, size, hs_dims=None):
>>> cube_slice.min_base_size_mask(50).column_mask
>>> cube_slice.min_base_size_mask(22).table_mask
"""
return MinBaseSizeMask(self, size, hs_dims)
return MinBaseSizeMask(self, size, hs_dims=hs_dims, prune=prune)

@lazyproperty
def mr_dim_ind(self):
Expand Down
36 changes: 27 additions & 9 deletions src/cr/cube/min_base_size_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from __future__ import division
import numpy as np

from cr.cube.util import lazyproperty
from cr.cube.util import lazyproperty, compress_pruned
from cr.cube.enum import DIMENSION_TYPE as DT


Expand All @@ -18,16 +18,22 @@ class MinBaseSizeMask:
marginal values and the shape of the underlying slice.
"""

def __init__(self, slice_, size, hs_dims=None):
def __init__(self, slice_, size, hs_dims=None, prune=False):
self._slice = slice_
self._size = size
self._hs_dims = hs_dims
self._prune = prune

@lazyproperty
def column_mask(self):
"""ndarray, True where column margin <= min_base_size, same shape as slice."""
margin = self._slice.margin(
axis=0, weighted=False, include_transforms_for_dims=self._hs_dims
margin = compress_pruned(
self._slice.margin(
axis=0,
weighted=False,
include_transforms_for_dims=self._hs_dims,
prune=self._prune,
)
)
mask = margin < self._size

Expand All @@ -43,8 +49,13 @@ def column_mask(self):
@lazyproperty
def row_mask(self):
"""ndarray, True where row margin <= min_base_size, same shape as slice."""
margin = self._slice.margin(
axis=1, weighted=False, include_transforms_for_dims=self._hs_dims
margin = compress_pruned(
self._slice.margin(
axis=1,
weighted=False,
include_transforms_for_dims=self._hs_dims,
prune=self._prune,
)
)
mask = margin < self._size

Expand All @@ -60,7 +71,14 @@ def row_mask(self):
@lazyproperty
def table_mask(self):
"""ndarray, True where table margin <= min_base_size, same shape as slice."""
margin = self._slice.margin(axis=None, weighted=False)
margin = compress_pruned(
self._slice.margin(
axis=None,
weighted=False,
include_transforms_for_dims=self._hs_dims,
prune=self._prune,
)
)
mask = margin < self._size

if margin.shape == self._shape:
Expand All @@ -74,13 +92,13 @@ def table_mask(self):

@lazyproperty
def _shape(self):
shape = self._slice.get_shape(hs_dims=self._hs_dims)
shape = self._slice.get_shape(hs_dims=self._hs_dims, prune=self._prune)

if len(shape) != self._slice.ndim:
# TODO: This is an ugly hack that needs to happen due to the fact that we
# purge dimensions with the count of 1, when getting the slice shape. This
# will be addressed in a PR (already on the way) that strives to abandon
# the ad-hoc purging of 1-element dimensions altogether.
shape = (shape[0], 1)
shape = (shape[0], 1) if shape else (1,)

return shape

0 comments on commit ffc5514

Please sign in to comment.