mirror of
https://github.com/k2-fsa/icefall.git
synced 2025-12-11 06:55:27 +00:00
Bug fixes to ScheduledFloat
This commit is contained in:
parent
ae73469b7e
commit
b973929d7c
@ -40,29 +40,27 @@ class PiecewiseLinear(object):
|
|||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
assert len(args) >= 1
|
assert len(args) >= 1
|
||||||
if len(args) == 1 and isinstance(args[0], PiecewiseLinear):
|
if len(args) == 1 and isinstance(args[0], PiecewiseLinear):
|
||||||
return args[0]
|
self.pairs = list(args[0].pairs)
|
||||||
for (x,y) in args:
|
else:
|
||||||
|
self.pairs = [ (float(x), float(y)) for x,y in args ]
|
||||||
|
for (x,y) in self.pairs:
|
||||||
assert isinstance(x, float) or isinstance(x, int)
|
assert isinstance(x, float) or isinstance(x, int)
|
||||||
assert isinstance(y, float) or isinstance(y, int)
|
assert isinstance(y, float) or isinstance(y, int)
|
||||||
|
|
||||||
for i in range(len(args) - 1):
|
for i in range(len(self.pairs) - 1):
|
||||||
assert args[i + 1] > args[i], args
|
assert self.pairs[i + 1][0] > self.pairs[i][0], self.pairs
|
||||||
self.pairs = [ (float(x), float(y)) for x,y in args ]
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
# e.g. 'PiecewiseLinear((0., 10.), (100., 0.))'
|
# e.g. 'PiecewiseLinear((0., 10.), (100., 0.))'
|
||||||
return f'PiecewiseLinear({str(self.pairs)[1:-1]})'
|
return f'PiecewiseLinear({str(self.pairs)[1:-1]})'
|
||||||
|
|
||||||
def __call__(self, x):
|
def __call__(self, x):
|
||||||
print("x=", x)
|
|
||||||
if x <= self.pairs[0][0]:
|
if x <= self.pairs[0][0]:
|
||||||
print("a", self.pairs[0][1])
|
|
||||||
return self.pairs[0][1]
|
return self.pairs[0][1]
|
||||||
elif x >= self.pairs[-1][0]:
|
elif x >= self.pairs[-1][0]:
|
||||||
print("b")
|
|
||||||
return self.pairs[-1][1]
|
return self.pairs[-1][1]
|
||||||
else:
|
else:
|
||||||
print("c")
|
|
||||||
cur_x, cur_y = self.pairs[0]
|
cur_x, cur_y = self.pairs[0]
|
||||||
for i in range(1, len(self.pairs)):
|
for i in range(1, len(self.pairs)):
|
||||||
next_x, next_y = self.pairs[i]
|
next_x, next_y = self.pairs[i]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user