what does partial do in python code example
Example: what does partial do in python
>>> add(1,2)
3
>>> add1 = partial(add, 4)
>>> add1(6)
10
>>> add1(10)
14
# It can basically be used to call classes using a single variable again and again
# For more you can refer to this code
class Conv2dAuto(nn.Conv2d):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.padding = (self.kernel_size[0] // 2, self.kernel_size[1] // 2) # dynamic add padding based on the kernel_size
conv3x3 = partial(Conv2dAuto, kernel_size=3, bias=False)
conv = conv3x3(in_channels=32, out_channels=64)
# Here conv3x3 can be used again and again without specifying the args and calling the class again and again