def to_mask(obj, m=None, indices=None):
if not pimms.is_map(obj) and pimms.is_vector(obj) and len(obj) < <NUM_LIT:4> and m is None:<EOL><INDENT>if   len(obj) == <NUM_LIT:1>: obj = obj[<NUM_LIT:0>]<EOL>elif len(obj) == <NUM_LIT:2>: (obj, m) = obj<EOL>else:<EOL><INDENT>(obj, m, q) = obj<EOL>if indices is None:<EOL><INDENT>if pimms.is_map(q): indices = q.get('<STR_LIT>', False)<EOL>else: indices = q<EOL><DEDENT><DEDENT><DEDENT>if indices is None: indices = False<EOL>if is_vset(obj):<EOL><INDENT>lbls = obj.labels<EOL>idcs = obj.indices<EOL>obj = obj.properties<EOL><DEDENT>else:<EOL><INDENT>obj = pimms.itable(obj)<EOL>lbls = np.arange(<NUM_LIT:0>, obj.row_count, <NUM_LIT:1>, dtype=np.int)<EOL>idcs = lbls<EOL><DEDENT>if m is None: return idcs if indices else lbls<EOL>if is_tuple(m):<EOL><INDENT>if len(m) == <NUM_LIT:0>: return np.asarray([], dtype=np.int)<EOL>p = to_property(obj, m[<NUM_LIT:0>])<EOL>if len(m) == <NUM_LIT:2> and hasattr(m[<NUM_LIT:1>], '<STR_LIT>'):<EOL><INDENT>m = reduce(lambda q,u: np.logical_or(q, p == u), m[<NUM_LIT:1>], np.zeros(len(p), dtype=np.bool))<EOL><DEDENT>elif len(m) == <NUM_LIT:2>:<EOL><INDENT>m = (p == m[<NUM_LIT:1>])<EOL><DEDENT>elif len(m) == <NUM_LIT:3>:<EOL><INDENT>m = np.logical_and(m[<NUM_LIT:1>] < p, p <= m[<NUM_LIT:2>])<EOL><DEDENT><DEDENT>elif pimms.is_str(m):<EOL><INDENT>m = np.asarray(obj[m], dtype=np.bool)<EOL><DEDENT>elif pimms.is_map(m):<EOL><INDENT>if len(m) != <NUM_LIT:1>: raise ValueError('<STR_LIT>')<EOL>(k,v) = next(six.iteritems(m))<EOL>if not hasattr(v, '<STR_LIT>'): raise ValueError('<STR_LIT>')<EOL>if not pimms.is_str(k): raise ValueError('<STR_LIT>')<EOL>v = [to_mask(obj, u, indices=indices) for u in v]<EOL>if   k in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT:&>', '<STR_LIT>'):<EOL><INDENT>return reduce(np.intersect1d, v)<EOL><DEDENT>elif k in ('<STR_LIT>',  '<STR_LIT>', '<STR_LIT:v>', '<STR_LIT:|>' '<STR_LIT>'):<EOL><INDENT>return reduce(np.union1d, v)<EOL><DEDENT><DEDENT>return idcs[m] if indices else lbls[m]<EOL>
to_mask(obj, m) yields the set of indices from the given vertex-set or itable object obj that
  correspond to the given mask m.
to_mask((obj, m)) is equivalent to to_mask(obj, m).

The mask m may take any of the following forms:
   * a list of vertex indices
   * a boolean array (one value per vertex)
   * a property name, which can be cast to a boolean array
   * a tuple (property, value) where property is a list of values, one per vertex, and value
     is the value that must match in order for a vertex to be included (this is basically
     equivalent to the mask (property == value); note that property may also be a property
     name
   * a tuple (property, min, max), which specifies that the property must be between min and
     max for a vertex to be included (min < p <= max)
   * a tuple (property, (val1, val2...)), which specifies that the property must be any of
     the values in (val1, val2...) for a vertex to be included
   * None, indicating that all labels should be returned
   * a dict/mapping with one item whose key is either 'and', or 'or' and whose value is a list,
     each of whose elements matches one of the above.

Note that the optional argument indices (default: False) may be set to true to yield the
vertex indices instead of the vertex labels. If obj is not a VertexSet object, then this
option is ignored.