Python numpy.issubclass_() Examples

The following are 13 code examples for showing how to use numpy.issubclass_(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module numpy , or try the search function .

Example 1
Project: lambda-packs   Author: ryfeus   File: fitpack2.py    License: MIT License 6 votes vote down vote up
def __init__(self, theta, phi, r, tt, tp, w=None, eps=1E-16):
        if np.issubclass_(w, float):
            w = ones(len(theta)) * w
        nt_, np_ = 8 + len(tt), 8 + len(tp)
        tt_, tp_ = zeros((nt_,), float), zeros((np_,), float)
        tt_[4:-4], tp_[4:-4] = tt, tp
        tt_[-4:], tp_[-4:] = np.pi, 2. * np.pi
        tt_, tp_, c, fp, ier = dfitpack.spherfit_lsq(theta, phi, r, tt_, tp_,
                                                     w=w, eps=eps)
        if ier < -2:
            deficiency = 6 + (nt_ - 8) * (np_ - 7) + ier
            message = _spherefit_messages.get(-3) % (deficiency, -ier)
            warnings.warn(message)
        elif ier not in [0, -1, -2]:
            message = _spherefit_messages.get(ier, 'ier=%s' % (ier))
            raise ValueError(message)

        self.fp = fp
        self.tck = tt_, tp_, c
        self.degrees = (3, 3) 
Example 2
Project: Computable   Author: ktraunmueller   File: fitpack2.py    License: MIT License 6 votes vote down vote up
def __init__(self, theta, phi, r, tt, tp, w=None, eps=1E-16):
        if np.issubclass_(w, float):
            w = ones(len(theta)) * w
        nt_, np_ = 8 + len(tt), 8 + len(tp)
        tt_, tp_ = zeros((nt_,), float), zeros((np_,), float)
        tt_[4:-4], tp_[4:-4] = tt, tp
        tt_[-4:], tp_[-4:] = np.pi, 2. * np.pi
        tt_, tp_, c, fp, ier = dfitpack.spherfit_lsq(theta, phi, r, tt_, tp_,
                                                     w=w, eps=eps)
        if ier < -2:
            deficiency = 6 + (nt_ - 8) * (np_ - 7) + ier
            message = _spherefit_messages.get(-3) % (deficiency, -ier)
            warnings.warn(message)
        elif not ier in [0, -1, -2]:
            message = _spherefit_messages.get(ier, 'ier=%s' % (ier))
            raise ValueError(message)
        self.fp = fp
        self.tck = tt_, tp_, c
        self.degrees = (3, 3) 
Example 3
Project: nata   Author: GoLP-IST   File: attrs.py    License: MIT License 6 votes vote down vote up
def __call__(self, instance, attribute, value):
        if isinstance(value, np.ndarray):
            value_type = value.dtype
        else:
            value_type = type(value)

        if self.dtype is not None and not np.issubdtype(value_type, self.dtype):
            # TODO: add better error message
            raise TypeError(
                f"Attribute '{attribute.name}' of {instance.__class__} "
                + f"must have dtype {self.dtype}"
            )

        if self.subclass is not None and not np.issubclass_(
            type(value), self.subclass
        ):
            # TODO: add better error message
            raise TypeError(
                f"Attribute '{attribute.name}' of {instance.__class__} "
                + f"must be of subclass {self.subclass}"
            ) 
Example 4
Project: GraphicDesignPatternByPython   Author: Relph1119   File: fitpack2.py    License: MIT License 6 votes vote down vote up
def __init__(self, theta, phi, r, tt, tp, w=None, eps=1E-16):
        if np.issubclass_(w, float):
            w = ones(len(theta)) * w
        nt_, np_ = 8 + len(tt), 8 + len(tp)
        tt_, tp_ = zeros((nt_,), float), zeros((np_,), float)
        tt_[4:-4], tp_[4:-4] = tt, tp
        tt_[-4:], tp_[-4:] = np.pi, 2. * np.pi
        tt_, tp_, c, fp, ier = dfitpack.spherfit_lsq(theta, phi, r, tt_, tp_,
                                                     w=w, eps=eps)
        if ier < -2:
            deficiency = 6 + (nt_ - 8) * (np_ - 7) + ier
            message = _spherefit_messages.get(-3) % (deficiency, -ier)
            warnings.warn(message)
        elif ier not in [0, -1, -2]:
            message = _spherefit_messages.get(ier, 'ier=%s' % (ier))
            raise ValueError(message)

        self.fp = fp
        self.tck = tt_, tp_, c
        self.degrees = (3, 3) 
Example 5
Project: coremltools   Author: apple   File: type_mapping.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def type_to_builtin_type(type):
    # Infer from numpy type if it is one
    if type.__module__ == np.__name__:
        return numpy_type_to_builtin_type(type)

    # Otherwise, try to infer from a few generic python types
    if np.issubclass_(type, bool):
        return types_bool
    elif np.issubclass_(type, six.integer_types):
        return types_int32
    elif np.issubclass_(type, six.string_types):
        return types_str
    elif np.issubclass_(type, float):
        return types_fp32
    else:
        raise TypeError("Could not determine builtin type for " + str(type)) 
Example 6
Project: Splunking-Crime   Author: nccgroup   File: fitpack2.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def __init__(self, theta, phi, r, tt, tp, w=None, eps=1E-16):
        if np.issubclass_(w, float):
            w = ones(len(theta)) * w
        nt_, np_ = 8 + len(tt), 8 + len(tp)
        tt_, tp_ = zeros((nt_,), float), zeros((np_,), float)
        tt_[4:-4], tp_[4:-4] = tt, tp
        tt_[-4:], tp_[-4:] = np.pi, 2. * np.pi
        tt_, tp_, c, fp, ier = dfitpack.spherfit_lsq(theta, phi, r, tt_, tp_,
                                                     w=w, eps=eps)
        if ier < -2:
            deficiency = 6 + (nt_ - 8) * (np_ - 7) + ier
            message = _spherefit_messages.get(-3) % (deficiency, -ier)
            warnings.warn(message)
        elif ier not in [0, -1, -2]:
            message = _spherefit_messages.get(ier, 'ier=%s' % (ier))
            raise ValueError(message)

        self.fp = fp
        self.tck = tt_, tp_, c
        self.degrees = (3, 3) 
Example 7
Project: lambda-packs   Author: ryfeus   File: fitpack2.py    License: MIT License 5 votes vote down vote up
def __init__(self, theta, phi, r, w=None, s=0., eps=1E-16):
        if np.issubclass_(w, float):
            w = ones(len(theta)) * w
        nt_, tt_, np_, tp_, c, fp, ier = dfitpack.spherfit_smth(theta, phi,
                                                                r, w=w, s=s,
                                                                eps=eps)
        if ier not in [0, -1, -2]:
            message = _spherefit_messages.get(ier, 'ier=%s' % (ier))
            raise ValueError(message)

        self.fp = fp
        self.tck = tt_[:nt_], tp_[:np_], c[:(nt_ - 4) * (np_ - 4)]
        self.degrees = (3, 3) 
Example 8
Project: Computable   Author: ktraunmueller   File: fitpack2.py    License: MIT License 5 votes vote down vote up
def __init__(self, theta, phi, r, w=None, s=0., eps=1E-16):
        if np.issubclass_(w, float):
            w = ones(len(theta)) * w
        nt_, tt_, np_, tp_, c, fp, ier = dfitpack.spherfit_smth(theta, phi,
                                                                r, w=w, s=s,
                                                                eps=eps)
        if not ier in [0, -1, -2]:
            message = _spherefit_messages.get(ier, 'ier=%s' % (ier))
            raise ValueError(message)
        self.fp = fp
        self.tck = tt_[:nt_], tp_[:np_], c[:(nt_ - 4) * (np_ - 4)]
        self.degrees = (3, 3) 
Example 9
Project: GraphicDesignPatternByPython   Author: Relph1119   File: fitpack2.py    License: MIT License 5 votes vote down vote up
def __init__(self, theta, phi, r, w=None, s=0., eps=1E-16):
        if np.issubclass_(w, float):
            w = ones(len(theta)) * w
        nt_, tt_, np_, tp_, c, fp, ier = dfitpack.spherfit_smth(theta, phi,
                                                                r, w=w, s=s,
                                                                eps=eps)
        if ier not in [0, -1, -2]:
            message = _spherefit_messages.get(ier, 'ier=%s' % (ier))
            raise ValueError(message)

        self.fp = fp
        self.tck = tt_[:nt_], tp_[:np_], c[:(nt_ - 4) * (np_ - 4)]
        self.degrees = (3, 3) 
Example 10
Project: IDTxl   Author: pwollstadt   File: estimator.py    License: GNU General Public License v3.0 5 votes vote down vote up
def find_estimator(est):
    """Return estimator class.

    Return an estimator class. If input is a class, check if it implements
    methods 'estimate' and 'is_parallel' necessary for network analysis
    (see abstract class 'Estimator' for documentation). If input is a string,
    search for class with that name in IDTxl and return it.

    Args:
        est : str | Class
            name of an estimator class implemented in IDTxl or custom estimator
            class

    Returns
        Class
            Estimator class
    """
    if inspect.isclass(est):
        # Test if provided class implements the Estimator class. This
        # constraint may be relaxed in the future.
        if not np.issubclass_(est, Estimator):
            raise RuntimeError('Provided class should implement abstract class'
                               ' Estimator.')
        return est
    elif type(est) is str:
        module_list = _package_contents()
        estimator = None
        for m in module_list:
            try:
                module = importlib.import_module('.' + m, __package__)
                return getattr(module, est)
            except AttributeError:
                pass
        if not estimator:
            raise RuntimeError('Estimator {0} not found.'.format(est))
    else:
        raise TypeError('Please provide an estimator class or the name of an '
                        'estimator as string.') 
Example 11
Project: holoviews   Author: holoviz   File: util.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def numpy_scalar_to_python(scalar):
    """
    Converts a NumPy scalar to a regular python type.
    """
    scalar_type = type(scalar)
    if np.issubclass_(scalar_type, np.float_):
        return float(scalar)
    elif np.issubclass_(scalar_type, np.int_):
        return int(scalar)
    return scalar 
Example 12
Project: Splunking-Crime   Author: nccgroup   File: fitpack2.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, theta, phi, r, w=None, s=0., eps=1E-16):
        if np.issubclass_(w, float):
            w = ones(len(theta)) * w
        nt_, tt_, np_, tp_, c, fp, ier = dfitpack.spherfit_smth(theta, phi,
                                                                r, w=w, s=s,
                                                                eps=eps)
        if ier not in [0, -1, -2]:
            message = _spherefit_messages.get(ier, 'ier=%s' % (ier))
            raise ValueError(message)

        self.fp = fp
        self.tck = tt_[:nt_], tp_[:np_], c[:(nt_ - 4) * (np_ - 4)]
        self.degrees = (3, 3) 
Example 13
Project: coremltools   Author: apple   File: type_mapping.py    License: BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def numpy_type_to_builtin_type(nptype):
    if type(nptype) == np.dtype:
        nptype = nptype.type

    if np.issubclass_(nptype, np.bool) or np.issubclass_(nptype, np.bool_):
        # numpy as 2 bool types it looks like. what is the difference?
        return types_bool
    elif np.issubclass_(nptype, np.int8):
        return types_int8
    elif np.issubclass_(nptype, np.int16):
        return types_int16
    elif np.issubclass_(nptype, np.int32):
        return types_int32
    elif np.issubclass_(nptype, np.int64):
        return types_int64
    elif np.issubclass_(nptype, np.uint8):
        return types_int8
    elif np.issubclass_(nptype, np.uint16):
        return types_int16
    elif np.issubclass_(nptype, np.uint32):
        return types_int32
    elif np.issubclass_(nptype, np.uint64):
        return types_int64
    elif np.issubclass_(nptype, np.int):
        # Catch all int
        return types_int32
    elif np.issubclass_(nptype, np.object_):
        # symbolic shape is considered int32
        return types_int32
    elif np.issubclass_(nptype, np.float16):
        return types_fp16
    elif np.issubclass_(nptype, np.float32) or np.issubclass_(nptype, np.single):
        return types_fp32
    elif np.issubclass_(nptype, np.float64) or np.issubclass_(nptype, np.double):
        return types_fp64
    elif (
        np.issubclass_(nptype, six.string_types)
        or np.issubclass_(nptype, np.string_)
        or np.issubclass_(nptype, np.str_)
    ):
        return types_str
    else:
        raise TypeError("Unsupported numpy type: %s" % (nptype))


# Tries to get the equivalent builtin type of a
# numpy or python type.