lib/hmmmix/trellis/__init__.py
def pack_edges(states: numpy.typing.NDArray[numpy.int64], outgoing_edges: typing.Dict[numpy.int64, typing.Sequence[WeightedEdge]]):
    """
    pack edges into C friendly compressed-sparse format that can be iterated
    over without hashing or attribute access

    :param states: list of state indices
    :param outgoing_edges: lists of WeightedEdge keyed by state index
    :return: PackedEdges
    """

    n_states = len(states)
    n = sum(len(outgoing_edges[s]) for s in states)

    start_indices = numpy.zeros(shape=(n_states, ), dtype=int)
    end_indices = numpy.zeros(shape=(n_states, ), dtype=int)

    succs = numpy.zeros(shape=(n, ), dtype=int) # successor state indices
    weights = numpy.zeros(shape=(n, ), dtype=numpy.float64)

    i = 0
    for s in states:
        s = int(s)
        assert 0 <= s and s < n_states
        start_indices[s] = i
        for edge in outgoing_edges[s]:
            s_prime = int(edge.succ)
            assert 0 <= s_prime and s_prime < n_states
            succs[i] = edge.succ
            weights[i] = edge.weight
            i += 1
        end_indices[s] = i

    return PackedEdges(
        start_indices=start_indices,
        end_indices=end_indices,
        succs=succs,
        weights=weights,
    )

    pack edges into C friendly compressed-sparse format that can be iterated
    over without hashing or attribute access

    :param states: list of state indices
    :param outgoing_edges: lists of WeightedEdge keyed by state index
    :return: PackedEdges
    
pack edges into C friendly compressed-sparse format that can be iterated
over without hashing or attribute access
pack edges into C friendly compressed - sparse format that can be iterated over without hashing or attribute access
def pack_edges(states: numpy.typing.NDArray[numpy.int64], outgoing_edges: typing.Dict[numpy.int64, typing.Sequence[WeightedEdge]]):
    n_states = len(states)
    n = sum(len(outgoing_edges[s]) for s in states)
    start_indices = numpy.zeros(shape=(n_states, ), dtype=int)
    end_indices = numpy.zeros(shape=(n_states, ), dtype=int)
    succs = numpy.zeros(shape=(n, ), dtype=int) 
    weights = numpy.zeros(shape=(n, ), dtype=numpy.float64)
    i = 0
    for s in states:
        s = int(s)
        assert 0 <= s and s < n_states
        start_indices[s] = i
        for edge in outgoing_edges[s]:
            s_prime = int(edge.succ)
            assert 0 <= s_prime and s_prime < n_states
            succs[i] = edge.succ
            weights[i] = edge.weight
            i += 1
        end_indices[s] = i
    return PackedEdges(
        start_indices=start_indices,
        end_indices=end_indices,
        succs=succs,
        weights=weights,
    )
def pack_edges ( states : numpy . typing . NDArray [ numpy . int64 ] , outgoing_edges : typing . Dict [ numpy . int64 , typing . Sequence [ WeightedEdge ] ] ) : n_states = len ( states ) n = sum ( len ( outgoing_edges [ s ] ) for s in states ) start_indices = numpy . zeros ( shape = ( n_states , ) , dtype = int ) end_indices = numpy . zeros ( shape = ( n_states , ) , dtype = int ) succs = numpy . zeros ( shape = ( n , ) , dtype = int ) weights = numpy . zeros ( shape = ( n , ) , dtype = numpy . float64 ) i = 0 for s in states : s = int ( s ) assert 0 <= s and s < n_states start_indices [ s ] = i for edge in outgoing_edges [ s ] : s_prime = int ( edge . succ ) assert 0 <= s_prime and s_prime < n_states succs [ i ] = edge . succ weights [ i ] = edge . weight i += 1 end_indices [ s ] = i return PackedEdges ( start_indices = start_indices , end_indices = end_indices , succs = succs , weights = weights , )
pack edges into C friendly compressed-sparse format that can be iterated
over without hashing or attribute access
pack edges into C friendly compressed - sparse format that can be iterated over without hashing or attribute access
"""
    pack edges into C friendly compressed-sparse format that can be iterated
    over without hashing or attribute access

    :param states: list of state indices
    :param outgoing_edges: lists of WeightedEdge keyed by state index
    :return: PackedEdges
    """ # successor state indices
None
states
numpy.typing.NDArray[numpy.int64]
list of state indices
list of state indices
outgoing_edges
typing.Dict[numpy.int64, typing.Sequence[WeightedEdge]]
lists of WeightedEdge keyed by state index
lists of WeightedEdge keyed by state index