These are my notes in random order from today:
Sep 10, 2019
Digging Deep in Transforms
-
02_data_transforms.ipynbnotebook - no order in v2 of the library for DataBlock API so can’t have mistakes when order is not correct as it was in v1
-
filtknows which set transform is applied to - transform creates a callable object, after creating you should call it and pass some data
-
_TfmMetais meta class ofTransform -
...for pass in Python (or do nothing) -
Foo2 = type(‘Foo2’, (object), {})will create a class calledFoo2 -
typeis class that constructs things - reason for meta classes is to change how Python works underneath the hood
- meta class is a way to not use
typeconstructor, but some other constructor in fastai v2 - meta class is called every time we create a class (not when objects are created)
-


3. Data model — Python 3.7.4 documentation
- class’s namespace is
__dict__object -
_TfmMetauses_TfmDictinstead of plain dict as the namespace dict - it behaves as the normal dict except for cases when ‘encodes’ and ‘decodes’ parameters are passed
-
TypeDispatch— allows for the same function to work differently for different types - Python method dispatching — can be single or multiple
- Multiple Dispatching — Python 3 Patterns, Recipes and Idioms
- Method dispatching in Python
- PEP 443 — Single-dispatch generic functions | Python.org
-
TypeDispatchhas dictfuncswhere key is a type and value is the function to call (NICE!) -
_p1_annograbs the first parameter annotation - how to use
Transformsubclass as a decorator? This will allow to dynamically add functionality to a given transform later outside the class definition. - Using class as decorator needs to be a callable, but not in the
__init__sense. We need to reimplement__call__()method. If parameter is callable it will be added to class’s methods. -
__new__()should have an expectableShift + Tabautocomplete for the signature. Signature is customized in__new__()forTransform