Skip to main content

make a function callable for once or N times

Project description

callonce

Usage

from callonce import callonce


@callonce
def _return_true() -> bool:
    return True


def _call_return_true():
    return _return_true()


def _call_return_true_3times():
    return _return_true(times=3)


def test_call_once():
    assert _call_return_true() == True
    assert _call_return_true() == None


def test_call_3times():
    assert _call_return_true_3times() == True
    assert _call_return_true_3times() == True
    assert _call_return_true_3times() == True
    assert _call_return_true_3times() == None

We offer a printonce function for easy debug in deep learning model, e.g., PyTorch. You don't have to remove the printonce when training the model in loop because the shape will be printed only once.

from callonce import printonce
from torch import nn

class Net(nn.Module):

    def __init__(self):
        self.linear = nn.Linear(4, 8)

    def forward(self, x):
        printonce('x:', x.shape)
        y = self.linear(x)
        printonce('y:', y.shape)
        return y

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

callonce-0.1.0.tar.gz (2.2 kB view hashes)

Uploaded Source

Built Distribution

callonce-0.1.0-py3-none-any.whl (3.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page