<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def skeleton_length(labels, indices=None):
    '''Compute the length of all skeleton branches for labeled skeletons
    
    labels - a labels matrix
    indices - the indexes of the labels to be measured. Default is all
    
    returns an array of one skeleton length per label.
    '''
    global __skel_length_table
    if __skel_length_table is None:
        tbl = np.zeros(512, np.float32)
        for ii in range(-1, 2):
            for jj in range(-1, 2):
                if ii == 0 and jj == 0:
                    continue
                #
                # Set the bit to search for and the center bit
                #
                idx = 2 ** (ii + 1 + (jj + 1) * 3) | 16
                mask = (np.arange(512) & idx) == idx
                #
                # If we are four-connected to another pixel that is
                # connected to this one, they are 8-connected and that
                # is the distance.
                #
                #  bad     good
                #  x 1 0   0 0 0
                #  x 1 1   0 1 0
                #  x x x   0 x 1
                if ii != 0 and jj != 0:
                    for adjacent_i, adjacent_j in (
                        (ii-1, jj), (ii, jj-1), (ii+1, jj), (ii, jj+1)):
                        if any([_ < -1 or _ > 1 
                                for _ in (adjacent_i, adjacent_j)]):
                            continue
                        aidx = 2 ** (adjacent_i+1 + (adjacent_j + 1) * 3)
                        mask = mask & ((np.arange(512) & aidx) != aidx)
                tbl[mask] += np.sqrt(ii*ii + jj*jj) / 2
        __skel_length_table = tbl
    if indices is None:
        indices = np.arange(1, np.max(labels)+1)
    else:
        indices = np.asanyarray(indices)
    if len(indices) == 0:
        return np.zeros(0)
    score = __skel_length_table[table_idx_from_labels(labels)]
    
    result = np.bincount(labels.ravel(), 
                         weights = score.ravel(),
                         minlength=np.max(indices)+1)
    return result[indices]