k1lib.fmt module

This module is for color formats, units and whatnot. This is exposed automatically with:

from k1lib.imports import *
fmt.txt # exposed
k1lib.fmt.size(_bytes=0)[source]

Formats disk size. Example:

# returns "50.0 bytes"
fmt.size(50)
# returns "12.0 MB"
fmt.size(1.2e7)
k1lib.fmt.sizeOf(l: Iterator[float])Tuple[str, Iterator[float]][source]

Figures out appropriate scale, scales back the Iterator, and return both. Example:

x = torch.abs(torch.randn(2)) * 1e4 + 1e5
label, t = fmt.sizeOf(x) # label is "kB"
(t | toTensor()).min() # min value should be close to 100
k1lib.fmt.comp(flop=0)[source]

Formats computation amount. Example:

# returns "50.0 FLOPs"
fmt.computation(50)
# returns "50.0 MFLOPs"
fmt.computation(5e7)
k1lib.fmt.compRate(flops=0)[source]

Formats computation rate. Example:

# returns "50.0 FLOPS"
fmt.computationRate(50)
# returns "50.0 MFLOPS"
fmt.computationRate(5e7)
k1lib.fmt.time(seconds=0)[source]

Formats small times. Example:

fmt.time(50) # returns "50.0 s"
fmt.time(4000) # returns "4000.0 s"
fmt.time(0.02) # returns "20.0 ms"
fmt.time(1e-5) # returns "10.0 us"
k1lib.fmt.item(n=0)[source]

Formats generic item. Example:

# returns "50.0"
fmt.item(50)
# returns "500.0 k"
fmt.item(5e5)
class k1lib.fmt.txt[source]

Bases: object

Text formatting. Example:

# will print out red text
print(fmt.txt.red("some text"))
static darkcyan(s: str)[source]
static red(s: str)[source]
static green(s: str)[source]
static yellow(s: str)[source]
static blue(s: str)[source]
static purple(s: str)[source]
static cyan(s: str)[source]
static bold(s: str)[source]
static grey(s: str)[source]
static darkgrey(s: str)[source]
static underline(s: str)[source]
static identity(s: str)[source]