/usr/lib/python2.7/dist-packages/pymc/datatypes.py is in python-pymc 2.2+ds-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | from numpy import obj2sctype, ndarray
from numpy import bool_
from numpy import byte, short, intc, int_, longlong, intp
from numpy import ubyte, ushort, uintc, uint, ulonglong, uintp
from numpy import single, float_, longfloat
from numpy import csingle, complex_, clongfloat
# These are only used for membership tests, but things break if they are sets
# rather than lists. TK, Jan 2012.
integer_dtypes = [int, uint, byte, short, intc, int_, longlong, intp, ubyte, ushort, uintc, uint, ulonglong, uintp]
try:
integer_dtypes.append(long)
except NameError:
pass # long is just int for Python 3
float_dtypes = [float, single, float_, longfloat]
complex_dtypes = [complex, csingle, complex_, clongfloat]
bool_dtypes = [bool, bool_]
def check_type(stochastic):
"""
type, shape = check_type(stochastic)
Checks the type of a stochastic's value. Output value 'type' may be
bool, int, float, or complex. Nonnative numpy dtypes are lumped into
these categories. Output value 'shape' is () if the stochastic's value
is scalar, or a nontrivial tuple otherwise.
"""
val = stochastic.value
if val.__class__ in bool_dtypes:
return bool, ()
elif val.__class__ in integer_dtypes:
return int, ()
elif val.__class__ in float_dtypes:
return float, ()
elif val.__class__ in complex_dtypes:
return complex, ()
elif isinstance(val, ndarray):
if obj2sctype(val) in bool_dtypes:
return bool, val.shape
elif obj2sctype(val) in integer_dtypes:
return int, val.shape
elif obj2sctype(val) in float_dtypes:
return float, val.shape
elif obj2sctype(val) in complex_dtypes:
return complex, val.shape
else:
return 'object', val.shape
else:
return 'object', ()
continuous_types = [float, complex]
def is_continuous(stochastic):
dtype, shape = check_type(stochastic)
if dtype in continuous_types:
return True
else:
return False
|