Skip to content

Commit

Permalink
build trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
h3x4g0ns committed Jan 29, 2024
1 parent 5591fb7 commit 1e39903
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Chronos


![pypi build](https://img.shields.io/github/workflow/status/h3x4g0ns/py-chronos/pypi-build)
![Build Status](https://img.shields.io/github/actions/workflow/status/h3x4g0ns/py-chronos/python-publish.yml)
[![PyPI version](https://badge.fury.io/py/py-quantize-chronos.svg)](https://badge.fury.io/py/py-quantize-chronos)

## About this Project
Expand Down
1 change: 1 addition & 0 deletions build/lib/chronos/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .chronos import *
53 changes: 53 additions & 0 deletions build/lib/chronos/chronos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from tqdm import tqdm
import numpy as np
import types, time

# lookup table for the trajectories and their derivatives
FXS = {
"$1$": lambda x: 1,
"$x$": lambda x: x,
"$x^2$": lambda x: x**2,
"$x^3$": lambda x: x**3,
"$log(x)$": lambda x: np.log(x),
"$xlog(x)$": lambda x: x*np.log(x),
"$2^x$": lambda x: 2**x
}

# num of iterations before we can potentially stop early
EARLY_STOP = 20

# main timer function
def timer(func: types.FunctionType, silent: bool=False, num: int=50):
# init variables for storage
x = np.arange(1, num+1)
y = []
# time the function
if not silent:
header = tqdm
else:
header = lambda x: x
for i in header(x):
start = time.time()
func(i)
end = time.time()
y.append(end-start)
loss, coeffs = [], []

# run regression for every trajectory
for func in FXS.values():
# find best fit via least squares
coeff = np.linalg.lstsq(np.array([func(i) for i in x]).reshape(-1, 1), y, rcond=None)[0]
coeffs.append(coeff)
# find total loss
cost = np.sum(np.abs(y - coeff*func(x)))
loss.append(cost)

# find the best fit
best = np.argmin(loss)
# return name of best fit and its coefficient
return list(FXS.keys())[best], coeffs[best]


# empty function for testing functionality
def test():
return "Hello World"
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = py-quantize-chronos
version = 0.1.7
version = 0.1.8
author = Ekansh Agrawal
author_email = [email protected]
description = utility tool that analyzes symbolic runtime of python functions
Expand Down

0 comments on commit 1e39903

Please sign in to comment.