Example #1
0
    def groupify(self, group_sym, syms=[], names=[], inherent_type=None):
        """Creates a group."""
        self._needs_not(group_sym)
        self._needs_inherent_type(inherent_type)
        self._needs_iter(syms)
        self._needs_iter(names)
        self._needs_all_unique(syms)
        self._needs_all_unique(names)

        properties = []
        for sym in syms:
            self._needs(sym)
            properties.append(self.get_properties(sym))

        if inherent_type in self._group_types:
            names = self._group_types[inherent_type]['names']

        group_properties = op_defs.create_group(
            properties,
            names=self._default_list(syms, names),
            inherent_type=inherent_type
        )
        self._adj[group_sym] = self._op('groupify', *syms)
        self._properties[group_sym] = group_properties
        return group_sym
Example #2
0
    def extend_group(self, new_group_sym, old_group_sym, new_syms=[], inherent_type=None):
        self._needs_not(new_group_sym)
        new_properties = []

        old_properties = self.get_properties(old_group_sym)['elements']
        new_properties.extend(old_properties)
        new_properties.extend(map(self.get_properties, new_syms))
        self._adj[new_group_sym] = self._op('extend_group', old_group_sym, *new_syms)
        self._properties[new_group_sym] = op_defs.create_group(new_properties)
        return new_group_sym
Example #3
0
    def combine_groups(self, new_group_sym, sym_groups=[], inherent_type=None):
        self._needs_not(new_group_sym)
        new_properties = []
        for group in sym_groups:
            old_properties = self.get_properties(group)
            self._needs_type(group, 'group')
            new_properties.extend(old_properties['elements'])

        self._adj[new_group_sym] = self._op('combine_groups', *sym_groups)
        self._properties[new_group_sym] = op_defs.create_group(new_properties)
        return new_group_sym
Example #4
0
    def register_group_type(self, name, field_names=[], field_properties=[]):
        self._needs_all_unique(field_names)

        real_field_props = []
        if len(field_properties) == 0:
            for field_name in field_names:
                self._needs(field_name)
                real_field_props.append(self.get_properties(field_name))
        else:
            real_field_props = field_properties
        self._group_types[name] = op_defs.create_group(real_field_props, field_names, inherent_type=name)
Example #5
0
    def pregroup(self, pregroup_name, syms=[], names=[], inherent_type=None):
        """Group input symbols.

        This is often a convenient operation to apply when creating functions.
        """
        self._needs_iter(syms)
        self._needs_inherent_type(inherent_type)
        self._needs_all_unique(syms)
        self._needs_all_unique(names)
        props = []
        for sym in syms:
            self._needs_input(sym)
            props.append(self.get_properties(sym))

        group_prop = op_defs.create_group(props, names=self._default_list(syms, names), inherent_type=inherent_type)
        self.emplace(pregroup_name, group_prop)
        self.degroupify(syms, pregroup_name)
        return pregroup_name