# Path: ndd/exceptions.py
# class NddError(Exception):
#     """Base class for ndd exceptions."""


import json
import logging
import numpy
import ndd.fnsb
from collections.abc import Mapping, MappingView
from types import GeneratorType
from ndd.exceptions import NddError
    NddError
        If k is not valid (wrong type, negative, too large...)

    """
    MAX_LOGK = 200 * numpy.log(2)

    if k is None:
        return k
    try:
        k = numpy.float64(k)
    except ValueError:
        raise NddError('%r is not a valid cardinality' % k)
    if k.ndim:
        # if k is a sequence, set k = prod(k)
        if k.ndim > 1:
            raise NddError('k must be a scalar or 1D array')
        logk = numpy.sum(numpy.log(x) for x in k)
        if logk > MAX_LOGK:
            # too large a number; backoff to n_bins?
            # TODO: log warning
            raise NddError('k is too large (%e).'
                           'Must be < 2^200 ' % numpy.exp(logk))
        k = numpy.prod(k)
    else:
        # if a scalar check size
        if k <= 0:
            raise NddError('k must be > 0 (%r)' % k)
        if numpy.log(k) > MAX_LOGK:
            raise NddError('k is too large (%e).' 'Must be < 2^200 ' % k)
    if not k.is_integer():

# Path: ndd/exceptions.py
# class NddError(Exception):
#     """Base class for ndd exceptions."""


# Path: ndd/counts.py
import json
import logging
import numpy
import ndd.fnsb
from collections.abc import Mapping, MappingView
from types import GeneratorType
from ndd.exceptions import NddError

    NddError
        If k is not valid (wrong type, negative, too large...)

    """
    MAX_LOGK = 200 * numpy.log(2)

    if k is None:
        return k
    try:
        k = numpy.float64(k)
    except ValueError:
        raise NddError('%r is not a valid cardinality' % k)
    if k.ndim:
        # if k is a sequence, set k = prod(k)
        if k.ndim > 1:
            raise NddError('k must be a scalar or 1D array')
        logk = numpy.sum(numpy.log(x) for x in k)
        if logk > MAX_LOGK:
            # too large a number; backoff to n_bins?
            # TODO: log warning
            raise NddError('k is too large (%e).'
                           'Must be < 2^200 ' % numpy.exp(logk))
        k = numpy.prod(k)
    else:
        # if a scalar check size
        if k <= 0:
            raise NddError('k must be > 0 (%r)' % k)
        if numpy.log(k) > MAX_LOGK:
            raise NddError('k is too large (%e).' 'Must be < 2^200 ' % k)
    if not k.is_integer():

        raise NddError('k must be a whole number (got %r).' % k)