utils – Utilities functions operating on the graph

Reference

  • exception theano.gof.utils.MethodNotDefined[source]
  • To be raised by functions defined as part of an interface.

When the user sees such an error, it is because an important interfacefunction has been left out of an implementation class.

  • theano.gof.utils.addtag_trace(_thing, user_line=None)[source]
  • Add tag.trace to an node or variable.

The argument is returned after being affected (inplace).

Parameters:

  • thing – The object where we add .tag.trace.
  • user_line – The max number of user line to keep.

Notes

We alse use config.traceback.limit for the maximum number of stack levelwe look.

  • theano.gof.utils.deprecated(filename, msg='')[source]
  • Decorator which will print a warning message on the first call.

Use it like this:

  1. @deprecated('myfile', 'do something different…')
  2. def fn_name(…)

And it will print:

  1. WARNING myfile.fn_name deprecated. do something different...
  • theano.gof.utils.difference(seq1, seq2)[source]
  • Returns all elements in seq1 which are not in seq2: i.e seq1\seq2.
  • theano.gof.utils.flatten(a)[source]
  • Recursively flatten tuple, list and set in a list.
  • theano.gof.utils.hashfrom_file(_file_path)[source]
  • Return the SHA256 hash of a file.
  • theano.gof.utils.memoize(f)[source]
  • Cache the return value for each tuple of arguments (which must be hashable).
  • theano.gof.utils.remove(predicate, coll)[source]
  • Return those items of collection for which predicate(item) is true.

Examples

  1. >>> def even(x):
  2. ... return x % 2 == 0
  3. >>> remove(even, [1, 2, 3, 4])
  4. [1, 3]
  • theano.gof.utils.simpleextract_stack(_f=None, limit=None, skips=[])[source]
  • This is traceback.extract_stack from python 2.7 with this change:

    • Comment the update of the cache.
    • Skip internal stack trace level. The update of the cache call os.stat to verify is the cache is upto date. This take too much time on cluster.

limit - The number of stack level we want to return. If None, meanall what we can.

  • skips - partial path of stack level we don’t want to keep and count.
  • When we find one level that isn’t skipped, we stop skipping.
  • theano.gof.utils.toposort(prereqs_d)[source]
  • Sorts prereqs_d.keys() topologically.

prereqs_d[x] contains all the elements that must come before xin the ordering.

  • theano.gof.utils.uniq(seq)[source]
  • Do not use set, this must always return the same value at the same index.If we just exchange other values, but keep the same pattern of duplication,we must keep the same order.