def apply(algorithm, namedArgs):               # pylint: disable-msg=C6409,W0622
  """Invoke the given algorithm with a dictionary of args.

  Args:
    algorithm: The name of an algorithm or a lambda.
    namedArgs: A dictionary of named arguments to pass to the given algorithm.

  Returns:
    The algorithm result.  This is cast to the appropriate type if it's
    recognized.  Otherwise, a dictionary representing the algorithm
    invocation JSON is returned.
  """
  if isinstance(algorithm, basestring):
    signature = algorithms.getSignature(algorithm)
    # pylint: disable-msg=W0212
    return algorithms._applySignature(signature, **namedArgs)
  else:
    applied = namedArgs.copy()
    applied['algorithm'] = algorithm
    return applied
def call(algorithm, *args, **kwargs):           # pylint: disable-msg=C6409
  """Invoke the given algorithm with the specified args.

  Args:
    algorithm: The name of the algorithm or a lambda.
    *args: The positional arguments to pass to the specified algorithm.
    **kwargs: The named arguments to pass to the specified algorithm.

  Returns:
    The algorithm result.  This is cast to the appropriate type if it's
    recognized.  Otherwise, a dictionary representing the algorithm
    invocation JSON is returned.
  """
  if isinstance(algorithm, basestring):
    signature = algorithms.getSignature(algorithm)
    # pylint: disable-msg=W0212
    return algorithms._applySignature(signature, *args, **kwargs)
  else:
    # Merge positional args into the keyword ones.
    applied = {'algorithm': algorithm}
    applied.update(dict(zip(algorithm['args'], args)))
    applied.update(kwargs)
    return applied