Storable factory for named tuples.
166940
def namedtuple_storable(namedtuple, *args, **kwargs):
    
    return default_storable(namedtuple, namedtuple._fields, *args, **kwargs)
1352482
def dict_factory(cursor, row):
    """"""
    d = {}
    for idx, col in enumerate(cursor.description):
        d[col[0]] = row[idx]
    return d
1083124
def from_dict(cls, d, **kwargs):
        """"""
        args = []
        for k in DATASET_KEYS:
            val = kwargs.get(k, d.get(k))
            # force modifiers to tuple
            if k == 'modifiers' and val is not None:
                val = tuple(val)
            args.append(val)

        return cls(*args)
617914
def slicing(args, length):
    """"""
    if isinstance(args, tuple):
        for arg in args:
            yield from slicing_singlevalue(arg, length)
    else:
        yield from slicing_singlevalue(args, length)
385108
def as_tuple(self, value):
        """"""
        if isinstance(value, list):
            value = tuple(value)
        return value
1192429
def _basis_polynomial_factory(cls, kind):
        """"""
        valid_kind = cls._validate(kind)
        basis_polynomial = getattr(np.polynomial, valid_kind)
        return basis_polynomial
738144
private static ImmutableBiMap<FactoryMethodDescriptor, ImplementationMethodDescriptor>
      createDuplicateMethodDescriptorsBiMap(
          ImmutableSet<FactoryMethodDescriptor> factoryMethodDescriptors,
          ImmutableSet<ImplementationMethodDescriptor> implementationMethodDescriptors) {

    ImmutableBiMap.Builder<FactoryMethodDescriptor, ImplementationMethodDescriptor> builder =
        ImmutableBiMap.builder();

    for (FactoryMethodDescriptor factoryMethodDescriptor : factoryMethodDescriptors) {
      for (ImplementationMethodDescriptor implementationMethodDescriptor :
          implementationMethodDescriptors) {

        boolean areDuplicateMethodDescriptors =
            areDuplicateMethodDescriptors(factoryMethodDescriptor, implementationMethodDescriptor);
        if (areDuplicateMethodDescriptors) {
          builder.put(factoryMethodDescriptor, implementationMethodDescriptor);
          break;
        }
      }
    }

    return builder.build();
  }
883500
def _to_args(x):
    """"""
    if not isinstance(x, (list, tuple, np.ndarray)):
        x = [x]
    return x
806635
def row_factory(cursor, row):
    """"""
    d = {}
    for idx, col in enumerate(cursor.description):
        d[col[0]] = row[idx]
    return d
1168416
def set_to_tuple(tokens):
    """"""
    internal_assert(len(tokens) == 1, "invalid set maker tokens", tokens)
    if "comp" in tokens or "list" in tokens:
        return "(" + tokens[0] + ")"
    elif "test" in tokens:
        return "(" + tokens[0] + ",)"
    else:
        raise CoconutInternalException("invalid set maker item", tokens[0])
829842
def is_named_tuple(cls):
    """"""
    b = cls.__bases__
    if len(b) != 1 or b[0] != tuple:
        return False
    f = getattr(cls, "_fields", None)
    if not isinstance(f, tuple):
        return False
    return all(type(n) == str for n in f)
549246
def fromiterable(cls, itr):
        """"""
        x, y, z = itr
        return cls(x, y, z)
1325463
def enum(cls, options, values):
    """"""
    names, real = zip(*options)
    del names  # unused

    def factory(i, name):
      return cls(i, name, (len(real),), lambda a: real[a[0]], values)
    return factory
1303567
def canonical(self):
        """"""
        try:
            return tuple(map(lambda x: x.lower(), self.name()))
        except:
            return tuple([x.lower() for x in self.name()])
368447
def iter_referents_tuples(self):
        
        tlow, thigh = self['targetset_arity'].get_tuple()
        clow, chigh = self['contrast_arity'].get_tuple()
        singletons = list([int(i) for i,_ in self.iter_singleton_referents()])
        t = len(singletons)
        low = int(max(1, tlow))
        high = int(min([t,  thigh]))
        for elements in itertools.chain.from_iterable(itertools.combinations(singletons, r) \
                for r in reversed(xrange(low, high+1))):
            if clow <= t-len(elements) <= chigh:
                yield  elements
1163069
def cache_generator(self, key, generator):
        """"""
        results = []
        for result in generator:
            results.append(result)
            yield result

        self.inferred[key] = tuple(results)
27674
private Collection<Tuple> getCombinedTuples( List<VarDef> combinedVars, Collection<Tuple> tuples)
    {
    // Apply any once-only constraints.
    Set<Tuple> onceTuples = getOnceTupleDefs( combinedVars);
    if( !onceTuples.isEmpty())
      {
      for( Tuple tuple : tuples)
        {
        tuple.setOnce( onceTuples.contains( tuple));
        }
      }
    
    return tuples;
    }