Skip to content

Instantly share code, notes, and snippets.

@ayorgo
ayorgo / abbreviate.py
Last active April 14, 2019 11:19
Python gists
from math import log
def abbreviate(value, base=1000, precision=2, suffixes=None):
if suffixes is None:
suffixes = ['', 'K', 'M', 'B', 'T']
if value == 0:
return f'{0}{suffixes[0]}'
@ayorgo
ayorgo / computational_performance.py
Created June 7, 2020 20:05
Computational performance measurement tool
from typing import List
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from timeit import repeat
from multiprocessing import Pool, cpu_count
def time_inline(function: str, *arg) -> float:
stmt = f'{function}(*{arg})'
return min(repeat(stmt, repeat=5, number=1, globals=globals()))
from typing import List
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from memory_profiler import memory_usage
from multiprocessing import Pool, cpu_count
import gc
def mem_inline(function, *arg) -> float:
return memory_usage(proc=(function, arg), max_usage=True)#[0]
# Interesting way of calling pip from inside python
# Source: https://colab.research.google.com/github/cleanlab/cleanlab-docs/blob/master/v2.4.0/tutorials/datalab/tabular.ipynb
if "google.colab" in str(get_ipython()): # Check if it's running in Google Colab
%pip install cleanlab==v2.4.0
cmd = ' '.join([dep for dep in dependencies if dep != "cleanlab"])
%pip install $cmd