aboutsummaryrefslogtreecommitdiffstats
path: root/utils/misc.py
diff options
context:
space:
mode:
Diffstat (limited to 'utils/misc.py')
-rw-r--r--utils/misc.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/utils/misc.py b/utils/misc.py
new file mode 100644
index 0000000..708d759
--- /dev/null
+++ b/utils/misc.py
@@ -0,0 +1,65 @@
+# author : S. Mandalia
+# shivesh.mandalia@outlook.com
+#
+# date : March 19, 2020
+
+"""
+Miscellaneous utility methods.
+"""
+
+
+__all__ = ['is_num', 'is_pos']
+
+
+def is_num(val: (int, float)) -> bool:
+ """
+ Check if the input value is a non-infinite number.
+
+ Parameters
+ ----------
+ val : Value to check.
+
+ Returns
+ ----------
+ is_num : Whether it is a non-infinite number.
+
+ Examples
+ ----------
+ >>> from utils.misc import is_num
+ >>> print(is_num(10))
+ True
+ >>> print(is_num(None))
+ False
+
+ """
+ if not isinstance(val, (int, float)):
+ return False
+ return True
+
+
+def is_pos(val: (int, float)) -> bool:
+ """
+ Check if the input value is a non-infinite positive number.
+
+ Parameters
+ ----------
+ val : Value to check.
+
+ Returns
+ ----------
+ is_pos : Whether it is a non-infinite positive number.
+
+ Examples
+ ----------
+ >>> from utils.misc import is_pos
+ >>> print(is_pos(10))
+ True
+ >>> print(is_pos(-10))
+ False
+
+ """
+ if not is_num(val):
+ return False
+ if not val >= 0:
+ return False
+ return True