mailr21258 - in /branches/relax_disp: ./ lib/check_types.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on October 27, 2013 - 19:06:
Author: bugman
Date: Sun Oct 27 19:06:06 2013
New Revision: 21258

URL: http://svn.gna.org/viewcvs/relax?rev=21258&view=rev
Log:
Merged revisions 21257 via svnmerge from 
svn+ssh://bugman@xxxxxxxxxxx/svn/relax/trunk

........
  r21257 | bugman | 2013-10-27 19:04:56 +0100 (Sun, 27 Oct 2013) | 3 lines
  
  Created the is_int() and is_num() functions for the lib.check_types module.
........

Modified:
    branches/relax_disp/   (props changed)
    branches/relax_disp/lib/check_types.py

Propchange: branches/relax_disp/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Sun Oct 27 19:06:06 2013
@@ -1,1 +1,1 @@
-/trunk:1-21245
+/trunk:1-21257

Modified: branches/relax_disp/lib/check_types.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_disp/lib/check_types.py?rev=21258&r1=21257&r2=21258&view=diff
==============================================================================
--- branches/relax_disp/lib/check_types.py (original)
+++ branches/relax_disp/lib/check_types.py Sun Oct 27 19:06:06 2013
@@ -29,7 +29,7 @@
     file = None
 except ImportError:
     io_module = False
-from numpy import complex64, complex128, float32, float64
+from numpy import complex64, complex128, float32, float64, int16, int32
 try:
     from numpy import complex256
 except ImportError:
@@ -42,7 +42,14 @@
     from numpy import float128
 except ImportError:
     float128 = float64    # Support for 32-bit numpy versions.
-
+try:
+    from numpy import int8
+except ImportError:
+    int8 = int16    # Support for old numpy versions.
+try:
+    from numpy import int64
+except ImportError:
+    int64 = int32    # Support for 32-bit numpy versions.
 
 def is_complex(num):
     """Check if the given number is a Python or numpy complex.
@@ -114,6 +121,54 @@
     return False
 
 
+def is_int(num):
+    """Check if the given number is a Python or numpy int.
+
+    @param num: The number to check.
+    @type num:  anything.
+    @return:    True if the number is a int, False otherwise.
+    @rtype:     bool
+    """
+
+    # Standard int.
+    if isinstance(num, int):
+        return True
+
+    # Numpy int.
+    if isinstance(num, int8):
+        return True
+    if isinstance(num, int16):
+        return True
+    if isinstance(num, int32):
+        return True
+    if isinstance(num, int64):
+        return True
+
+    # Not a int.
+    return False
+
+
+def is_num(num):
+    """Check if the given number is a Python or numpy int or float.
+
+    @param num: The number to check.
+    @type num:  anything.
+    @return:    True if the number is an int or float, False otherwise.
+    @rtype:     bool
+    """
+
+    # A float.
+    if is_float(num):
+        return True
+
+    # An integer.
+    if is_int(num):
+        return True
+
+    # Not a float.
+    return False
+
+
 def is_unicode(obj):
     """Check if the given Python object is a unicode string.
 




Related Messages


Powered by MHonArc, Updated Sun Oct 27 19:20:02 2013