Skip to content

lebellig/dim-checker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DimChecker

Useful tool for functions, neural networks, or callable objects outputs dimensions checking. It allows fast testing and relies on pattern string for easy use.

DimChecker().test_dims(nn, "bcl->bn(2*c+1)l", n=16)

Define Pattern

Write pattern

A pattern is defined as two formulas separated by an arrow:

pattern = "bcl -> b(2*c)l"
DimChecker().test_dims(nn, pattern)

On the left side of the arrow we have the inputs formula and the outputs formula on the right.

in_formula = "bcl"
out_formula = "b(2*c)l"
pattern = in_formula + "->" + out_formula
DimChecker().test_dims(nn, pattern)

Write formulas

simple case

Dimensions are defined by a single letter. Here a common machine learning input tensor of shape $\textit{Batch} \times \textit{Channel} \times \textit{Length}$ :

formula = "bcl"

For 2D images of shape $\textit{Batch} \times \textit{Channel} \times \textit{Height} \times \textit{Width}$ we may use:

formula = "bchw"

arithmetical expression

several inputs or outputs

To use several inputs or outputs we only need to separate them by commas:

# several inputs
pattern = "bcl, bl -> bcl"
# several outputs
pattern = "bcl -> bcl, bl"
# several inputs or outputs
pattern = "bcl, bc ->bcl, bl"
DimChecker().test_dims(nn, pattern)

Add Constraints

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages