jacinle#
The Jacinle library.
This main library contains a set of useful utility functions and classes for general Python scripting.
There are a few automatically imported submodules that can be accessed by jacinle.<submodule>
.
Command Line Tools
A customized argument parser. |
|
|
Ask a yes/no question via input() and return their answer. |
|
Make a directory if it does not exist. |
|
A utility function to guard the current git repo. |
Logging
|
Get logger with given name. |
|
set the output file for all loggers. |
Configuration
See jacinle.config.environ_v2 for more details.
|
The global configuration dictionary. |
A context manager to enable configuration definition mode. |
|
|
A decorator to enable configuration definition mode when calling a function. |
A context manager to enable configuration setting mode. |
|
|
A decorator to enable configuration setting mode when calling a function. |
|
Get the environment variable with the given name. |
|
Return if the verbose mode is enabled. |
|
Return if the debug mode is enabled. |
Utilities (Core)
An empty context manager that does nothing. |
|
A context manager that catches KeyboardInterrupt and does nothing. |
|
A customized enumeration class, adding helper functions for string-based argument parsing. |
|
A clock that can be used to measure the time. |
|
|
A helper decorator to mark a function as deprecated. |
|
Import a module by its module name (e.g., jacinle.utils.imp). |
|
Import a module by its filename (e.g., /Users/jiayuan/Projects/Jacinle/jacinle/utils/imp.py). |
|
Load a source file as a module. |
|
A special object to indicate that a value is not set. |
|
A go-style for loop for dict, list, tuple, set, etc. |
|
A decorator to run a function only once. |
|
A function that tries to run a function, and returns None if it fails (without raising exceptions). |
|
Execute a function on each element of the iterables, and return the results. |
|
Execute a filter function on each element of the iterable, and return the results. |
|
Get the first element of an iterable. |
|
Get the first n elements of an iterable. |
|
A map function that recursively follows the structure of the iterable. |
|
Convert a method name to a function that calls the method. |
|
Execute a method on each element of the iterable, and return the results. |
|
Make a decorator that can be used with or without arguments. |
|
A context manager that runs a with statement only if the condition is true. |
|
A context manager that runs a group of with statements only if the condition is true. |
|
Merge two iterables into a single iterable. |
|
Update a dictionary recursively. |
|
Get a flattened dictionary with keys as the path to the value. |
|
Get the keys of a flattened dictionary. |
|
Assert that an instance is of a certain type. |
|
Assert that the input is None. |
|
Assert that the input is not None. |
|
A property that raises an error if the value is None. |
|
A decorator that synchronizes the execution of a function. |
|
A decorator that raises a TimeoutError if the execution time of the function exceeds the timeout. |
|
Make a dummy function that raises an error when called. |
|
A helper function to generate the repr string from the __str__ method. |
|
Get the class name of an instance or a class object. |
|
Get a full name of a function, including the module name. |
|
Get a full name of a method, including the module name and the class name. |
|
Get the class name of a method. |
|
|
|
Indent the text by the given level. |
|
Structure print. |
|
Structure format. |
|
Print the key-value pairs. |
|
Format the key-value pairs. |
|
Create a |
|
Redirect the print to a function. |
A context manager that suppress the stdout. |
|
A context manager that suppress the stdout. |
|
A context manager that suppress the stdout and stderr. |
|
|
Return a list of (field_name, field_value) pairs for the given dataclass instance. |
|
Print the file docstring. |
Utilities (IO)
|
Load a file with automatic file type detection. |
|
Dump a file with automatic file type detection. |
|
Load a pickle file. |
|
Dump a pickle file. |
|
List all files in a directory. |
|
Create a directory if it does not exist without raising errors when the directory already exists. |
Utilities (Cache)
|
A decorator that converts a function into a cached property. |
|
A decorator that caches the result of a function. |
|
A decorator that caches the result of a function into a file. |
Utilities (TQDM)
Get the current tqdm instance. |
|
|
Wrapped tqdm, where default kwargs will be load, and support for i in tqdm(10) usage. |
|
Create a tqdm progress bar with the given kwargs. |
|
Create a tqdm progress bar for the given iterable, and use it as the progress bar for |
|
Create a tqdm progress bar for a zip of the given iterables, and use it as the progress bar. |
Utilities (Math)
|
A safe sum function that uses the first value as the initial value. |
|
A mean function that returns the default value when the input is empty. |
|
A standard deviation function that returns the default value when the input is empty. |
|
A root mean square function that returns the default value when the input is empty. |
|
A product function that returns the default value when the input is empty. |
|
Divide n by d and round up. |
|
Reset the global seed for all random number generators. |
|
|
|
A context manager that sets the global seed to the given value, and restores it after the context. |
Utilities (Container)
|
A simple global dict-like object. |
A simple container that wraps a dict and provides attribute access to the dict. |
|
A simple container that wraps a dict and provides attribute access to the dict. |
|
Create a object that allows only a fixed set of attributes to be set. |
|
A set that keeps the order of the elements. |
Utilities (Defaults)
See jacinle.utils.defaults for more details.
|
Defaults manager can be used to create program or thread-level registries. |
|
|
|
|
|
|
A class that stores options in a single file. |
|
|
A helper function handles the case of "fall-through" default arguments. |
|
A special value to indicate that the default value of an argument will be determined in a deferred manner. |
Utilities (Exception and Debugging)
Add a hook to ipdb when an exception is raised. |
|
|
A context manager to temporarily enable the ipdb exception hook. |
|
A context manager that enters ipdb when timeout. |
|
A decorator to log the function call. |
|
A context manager to profile the code in the context. |
|
A context manager to time the code in the context. |
|
Format an exception info tuple into a string. |
Utilities (Network and Misc)
Get the local IP address of the machine. |
|
Generate a time string with format: %Y%m%d-%H%M%S-%f. |
|
Generate a UUID4 string. |
Submodules
A simple wrapper around tornado for simple web applications. |