-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathparameter_checks.py
97 lines (83 loc) · 2.35 KB
/
parameter_checks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def check_range_and_int(val, name, low=0, high=127):
"""Checks a parameter to match Loihi
Calls two methods to check if the parameter value is
integer and in a range between low and high.
Parameters
----------
val : int
The value of the parameter
name : str
The name of the parameter
low : int, optional
The lower bound of the parameter
high : int, optional
The upper bound of the parameter
"""
check_int(val, name)
check_range(val, name, low, high)
def check_lower_and_int(val, name, low=0):
"""Checks a parameter to match Loihi
Calls two methods to check if the parameter value is
integer and in greater than low.
Parameters
----------
val : int
The value of the parameter
name : str
The name of the parameter
low : int, optional
The lower bound of the parameter
"""
check_int(val, name)
check_lower(val, name, low)
def check_lower(val, name, low=0):
"""Checks if a parameter is greater or equal than low
Parameters
----------
val : int
The value of the parameter
name : str
The name of the parameter
low : int, optional
The lower bound of the parameter
Raises
------
Exception
If value is lower than low.
"""
if (val < low):
raise Exception(str(name) + " has to be greater or equal to " +str(low)+ ".")
def check_range(val, name, low=0, high=127):
"""Checks if a parameter is between low and high
Parameters
----------
val : int
The value of the parameter
name : str
The name of the parameter
low : int, optional
The lower bound of the parameter
high : int, optional
The upper bound of the parameter
Raises
------
Exception
If value is lower than low of greater than high.
"""
if (val < low) or (val > high):
raise Exception(str(name) + " has to be between " +str(low)+ " and " +str(high)+ ".")
def check_int(val, name):
"""Checks if a parameter is of type integer
Parameters
----------
val : int
The value of the parameter
name : str
The name of the parameter
Raises
------
Exception
If value not integer
"""
if not isinstance(val, int):
raise Exception(str(name) + " has to be an integer.")