madlib-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iyerr3 <...@git.apache.org>
Subject [GitHub] incubator-madlib pull request: Feature/svm grouping
Date Thu, 05 Nov 2015 21:45:55 GMT
Github user iyerr3 commented on a diff in the pull request:

    https://github.com/apache/incubator-madlib/pull/1#discussion_r44073931
  
    --- Diff: src/ports/postgres/modules/utilities/in_mem_group_control.py_in ---
    @@ -7,6 +7,141 @@
     import plpy
     from control import MinWarning
     from utilities import unique_string
    +from collections import namedtuple
    +from collections import Iterable
    +
    +
    +class BaseState(object):
    +    """@brief Abstraction for intermediate iteration state"""
    +    def __init__(self, **kwargs):
    +        self._state = {}
    +        self._is_none = None
    +        self.initialize(**kwargs)
    +
    +    def __len__(self):
    +        return len(self._state)
    +
    +    def __del__(self):
    +        del self._state
    +
    +    def __getitem__(self, k):
    +        return self._state[k]
    +
    +    def __setitem__(self, k, v):
    +        self._state[k] = v
    +
    +    @property
    +    def keys(self):
    +        return self._state.keys()
    +
    +    @property
    +    def values(self):
    +        if self.is_none():
    +            return []
    +        return [s for x in self._state.values() for s in x]
    +
    +    def delete(self, keys_to_remove):
    +        for k in keys_to_remove:
    +            try:
    +                del self._state[k]
    +            except KeyError:
    +                pass
    +        self._is_none = None
    +
    +    def initialize(self, 
    +                   col_grp_key='', 
    +                   col_grp_state='', 
    +                   ret_states=None, **kwargs):
    +        self.update(col_grp_key, col_grp_state, ret_states)
    +
    +    def update(self, 
    +               col_grp_key, 
    +               col_grp_state, 
    +               ret_states):
    +        failed_grp_keys = []
    +        if ret_states is None:
    +            return failed_grp_keys
    +        t0 = ret_states[0]
    +        # no key column in table ret_states
    +        if col_grp_key not in t0:
    +            return failed_grp_keys
    +        # initialize state to None
    +        if col_grp_state == '':
    +            self._is_none = True
    +            for s in ret_states:
    +                self._state[s[col_grp_key]] = None
    +            return failed_grp_keys
    +        for t in ret_states:
    +            _grp_key, _grp_state = t[col_grp_key], t[col_grp_state]
    +            if _grp_state is None: failed_grp_keys.append(_grp_key)
    --- End diff --
    
    Let's put the statement in a separate line per [Pep 8](https://www.python.org/dev/peps/pep-0008/#other-recommendations)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message