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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file callonce-0.1.0.tar.gz.

File metadata

  • Download URL: callonce-0.1.0.tar.gz
  • Upload date:
  • Size: 2.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for callonce-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4342a0583b7fd8ad9f15cc0eca51b45b4e35bd33dfcbc626fa0e44fe1510dc0d
MD5 0fd19453743856a6908780e5b1f1007c
BLAKE2b-256 bdf920334ed9da3ebfaa41d4ae00dc74395a8988295296ffc611b8d2932af700

See more details on using hashes here.

File details

Details for the file callonce-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: callonce-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for callonce-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 384b6aae856edd1a8597f54122bdcf36cd2b5a5e40192c1e8e0c7275b55435ed
MD5 455663e9b049b0b873833e94973f84a3
BLAKE2b-256 b5c4bb90d5c86ede754fcf9294a612c5d95d77feb4614987edcd7156b8d6316e

See more details on using hashes here.

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