# 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


def as_counts_array(counts):
    """Convert input to counts array."""
    if isinstance(counts, (Mapping, MappingView)):
        return numpy.fromiter(counts.values(), dtype=int)
    if isinstance(counts, (GeneratorType, map, filter)):
        return numpy.fromiter(counts, dtype=int)
    return numpy.asarray(counts)


def check_k(k):
    """
    if k is an integer, just check
    if an array set k = prod(k)
    if None, return

    Raises
    ------
    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:

# 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



def as_counts_array(counts):
    """Convert input to counts array."""
    if isinstance(counts, (Mapping, MappingView)):
        return numpy.fromiter(counts.values(), dtype=int)
    if isinstance(counts, (GeneratorType, map, filter)):
        return numpy.fromiter(counts, dtype=int)
    return numpy.asarray(counts)


def check_k(k):
    """
    if k is an integer, just check
    if an array set k = prod(k)
    if None, return

    Raises
    ------
    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)