1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """Special module for checking types."""
24
25
26 io_module = True
27 try:
28 from io import IOBase
29 file = None
30 except ImportError:
31 io_module = False
32 from numpy import complex64, complex128, float32, float64, int16, int32
33 try:
34 from numpy import complex256
35 except ImportError:
36 complex256 = complex128
37 try:
38 from numpy import float16
39 except ImportError:
40 float16 = float32
41 try:
42 from numpy import float128
43 except ImportError:
44 float128 = float64
45 try:
46 from numpy import int8
47 except ImportError:
48 int8 = int16
49 try:
50 from numpy import int64
51 except ImportError:
52 int64 = int32
53
55 """Check if the given number is a Python or numpy complex.
56
57 @param num: The number to check.
58 @type num: anything.
59 @return: True if the number is a complex, False otherwise.
60 @rtype: bool
61 """
62
63
64 if isinstance(num, complex):
65 return True
66
67
68 if isinstance(num, complex64):
69 return True
70 if isinstance(num, complex128):
71 return True
72 if isinstance(num, complex256):
73 return True
74
75
76 return False
77
78
80 """Check if the given Python object is a file.
81
82 @param obj: The Python object.
83 @type obj: anything
84 @return: True if the object is a file, False otherwise.
85 @rtype: bool
86 """
87
88
89 if io_module:
90 return isinstance(obj, IOBase)
91
92
93 else:
94 return isinstance(obj, file)
95
96
98 """Check if the given number is a Python or numpy float.
99
100 @param num: The number to check.
101 @type num: anything.
102 @return: True if the number is a float, False otherwise.
103 @rtype: bool
104 """
105
106
107 if isinstance(num, float):
108 return True
109
110
111 if isinstance(num, float16):
112 return True
113 if isinstance(num, float32):
114 return True
115 if isinstance(num, float64):
116 return True
117 if isinstance(num, float128):
118 return True
119
120
121 return False
122
123
125 """Check if the given number is a Python or numpy int.
126
127 @param num: The number to check.
128 @type num: anything.
129 @return: True if the number is a int, False otherwise.
130 @rtype: bool
131 """
132
133
134 if isinstance(num, int):
135 return True
136
137
138 if isinstance(num, int8):
139 return True
140 if isinstance(num, int16):
141 return True
142 if isinstance(num, int32):
143 return True
144 if isinstance(num, int64):
145 return True
146
147
148 return False
149
150
152 """Check if the given value is a Python list.
153
154 @param val: The value to check.
155 @type val: anything.
156 @return: True if the value is a list, False otherwise.
157 @rtype: bool
158 """
159
160
161 if not isinstance(val, list):
162 return False
163
164
165 return True
166
167
169 """Check if the given value is a Python list of lists.
170
171 @param val: The value to check.
172 @type val: anything.
173 @return: True if the value is a list of lists, False otherwise.
174 @rtype: bool
175 """
176
177
178 if not isinstance(val, list):
179 return False
180
181
182 if not isinstance(val[0], list):
183 return False
184
185
186 return True
187
188
190 """Check if the given number is a Python or numpy int or float.
191
192 @param num: The number to check.
193 @type num: anything.
194 @return: True if the number is an int or float, False otherwise.
195 @rtype: bool
196 """
197
198
199 if is_float(num):
200 return True
201
202
203 if is_int(num):
204 return True
205
206
207 return False
208
209
211 """Check if the given Python object is a unicode string.
212
213 @param obj: The Python object.
214 @type obj: anything
215 @return: True if the object is a unicode string, False otherwise.
216 @rtype: bool
217 """
218
219
220 return isinstance(obj, unicode)
221