Skip to content

Commit e1cd68b

Browse files
committed
add tic() and toc() functions for easy coarse timing
1 parent b90ea88 commit e1cd68b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

ot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from .da import sinkhorn_lpl1_mm
1717

1818
# utils functions
19-
from .utils import dist, unif
19+
from .utils import dist, unif, tic, toc, toq
2020

2121
__version__ = "0.1.11"
2222

ot/utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,26 @@
66
from scipy.spatial.distance import cdist
77

88

9+
import time
10+
__time_tic_toc=time.time()
11+
12+
def tic():
13+
""" Python implementation of Matlab tic() function """
14+
global __time_tic_toc
15+
__time_tic_toc=time.time()
16+
17+
def toc(message='Elapsed time : {} s'):
18+
""" Python implementation of Matlab toc() function """
19+
t=time.time()
20+
print(message.format(t-__time_tic_toc))
21+
return t-__time_tic_toc
22+
23+
def toq():
24+
""" Python implementation of Julia toc() function """
25+
t=time.time()
26+
return t-__time_tic_toc
27+
28+
929
def kernel(x1,x2,method='gaussian',sigma=1,**kwargs):
1030
"""Compute kernel matrix"""
1131
if method.lower() in ['gaussian','gauss','rbf']:

0 commit comments

Comments
 (0)