Skip to content

A one-function package designed to do one thing.. show you the types!

License

Notifications You must be signed in to change notification settings

InfiniteSwerve/ShowMeTheTypes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Show Me The Types (SMTT)

This is a package designed to provide a single utility: showing you the types!

If you frequently end up handling lists of tuples of tensors, lists of tensors, nested lists and tuples, or other similarly convoluted structures, SMTT might be able to make your life just a bit easier. Instead of thinking about needing len, .shape, .size(), or printing out the structure and parsing the brackets and parens, you can just do tt(data), and get an instant overview of the structure.

from showmethetypes import SMTT
import torch

tt = SMTT()
structure = [(torch.randn(2,3), torch.randn(500, 5, 128)) for _ in range(5)]

tt(structure)
list (5)
    └── tuple
        ├── Tensor (dtype: torch.float32)
        │   │   (device: cpu)
        │   ├── dim_0 (2)
        │   └── dim_1 (3)
        └── Tensor (dtype: torch.float32)
            │   (device: cpu)
            ├── dim_0 (500)
            ├── dim_1 (5)
            └── dim_2 (128)

Installation

Done locally through pip

git clone https://github.com/InfiniteSwerve/ShowMeTheTypes.git
cd ShowMeTheTypes
pip install -e .

Behavior

SMTT will by default display the type for whatever you pass it, and traverse all nested types if the passed object has a __getitem__ method.

The default behavior is to iterate across all subtypes, which means it will print out everything the object contains. Some types, like lists, are usually monomorphic, so SMTT will assume monomorphism and only print out the nested structure in the first item of the list.

SMTT will also infer your current imports and use the specific handlers available for any libraries in your locals().

Coverage

SMTT is quite fresh, and so the current coverage only includes objects that I've needed to work with directly. If you feel sad about any missing types, feel free to raise an issue requesting it, or even make a PR! Creating new handlers for types is quite straightforward.

Testing

You can run the tests with pytest --nbval. Since the core functionality doesn't change, the testing focus is on regression tests. For this we use pytest and nbval, using the cell outputs of jupyter notebooks to make sure the untouched cell outputs haven't changed.

The libraries with any coverage are listed here, and you can find detailed coverage information in handlers.py.

Library Total Coverage
stdlib No
Pytorch No
Numpy No

About

A one-function package designed to do one thing.. show you the types!

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published