lf1-io / padl

Functional deep learning
Apache License 2.0
106 stars 4 forks source link

Print statements should have a fixed/ limited column width #368

Closed blythed closed 2 years ago

blythed commented 2 years ago

πŸ›°οΈ Feature

Don't want this type of thing.


      └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
      β”‚                                                                                                                       β”‚
      β–Ό args                                                                                                                  β–Ό x
   0: [audio_part: ..>>..]                                                                       + NoisePart(in_channels=30, height=5, width=5)
      β”‚
      β–Ό (audio, noise)
   1: combine_audio_and_noise                                                                                              
      β”‚
      β–Ό args
   2: Batchify(dim=0)                                                                                                      
      β”‚
      β–Ό input
   3: Generator(channel_number_parameter=96, network_depth=5, in_channels=50, convolution_type='regular', image_channels=3)
      β”‚
      β–Ό args
   4: Unbatchify(dim=0, cpu=True)                                                                                          
      β”‚
      β–Ό x
   5: rescale_image_tensor                                                                                                 
      β”‚
      β–Ό x
   6: switch_dimensions                                                                                                    
      β”‚
      β–Ό (obj, mode)
   7: fromarray

Signatures with many parameters should be wrapped over several lines.

jasonkhadka commented 2 years ago

Description

PR https://github.com/lf1-io/padl/pull/376 fixes this

@transform
class Generator:
    def __init__(self, channel_number=96, 
                 network_depth=5,
                 in_channels=50, 
                 convolution_type='regular', 
                 image_channels=3):
        self.channel_number = channel_number
        self.network_depth = network_depth
        self.convolution_type = convolution_type
        self.image_channels = image_channels

    def __call__(self, input):
        return input

f = identity - 'f'

gen = Generator(channel_number=96, 
                 network_depth=5,
                 in_channels=50, 
                 convolution_type='regular', 
                image_channels=3)

1. Full args

comp = (
    f
    >> batch
    >> f
    >> gen
)

Compose - "comp":

      β”‚
      β–Ό args
   0: Identity(-?-)                                                                                              
      β”‚
      β–Ό args
   1: Batchify(dim=0)                                                                                            
      β”‚
      β–Ό args
   2: Identity(-?-)                                                                                              
      β”‚
      β–Ό input
   3: Generator(channel_number=96, network_depth=5, in_channels=50, convolution_type='regular', image_channels=3)

2. Shortened args

comp = (
    f
    >> batch
    >> f + f
    >> gen

)
Compose - "comp":

      β”‚
      β–Ό args
   0: Identity(-?-)                                     
      β”‚
      β–Ό args
   1: Batchify(dim=0)                                   
      └────────────────────────────────────────────────────┐
      β”‚                                                    β”‚
      β–Ό args                                               β–Ό args
   2: Identity(-?-)                                      + Identity(-?-)
      β”‚
      β–Ό input
   3: Generator(channel_number=96, network_depth=5, ...)

3. Even shorter

comp = (
    f
    >> batch
    >> f + f + f
    >> gen

)

Compose - "comp":

      β”‚
      β–Ό args
   0: Identity(-?-)                    
      β”‚
      β–Ό args
   1: Batchify(dim=0)                  
      └───────────────────────────────────────────────────┐
      └───────────────────────────────────┐               β”‚
      β”‚                                   β”‚               β”‚
      β–Ό args                              β–Ό args          β–Ό args
   2: Identity(-?-)                     + Identity(-?-) + Identity(-?-)
      β”‚
      β–Ό input
   3: Generator(channel_number=96, ...)