parameter.py 697 Bytes
Newer Older
1
2
3
4
5
6
7
import sys


class FloatParameter:
    """ Float with tracking. initial value and bounds.

    """
8
9
    def __init__(self, initial, bounds=None, fixed=False):
        bounds = bounds or (-sys.float_info.max, sys.float_info.max)
10
        self.current = float(initial)
11
        self._bounds = [float(_) for _ in bounds]
12
13
14
15
16
17
        self.computed = None
        self._fixed = fixed

    @property
    def fixed(self):
        return self._fixed or self.computed != None
18

19
20
21
22
    @property
    def bounds(self):
        return self._bounds

23
    def __float__(self):
24
25
26
        if self.computed:
            return self.computed()
        return self.current
27
28
29

    def __str__(self):
        return str(self.current)