def inner_product_d(x_d, y_d):
    """Inner product for sparse vectors."""
    inner_prod = 0.0
    for k, v in x_d.items():
        if k in y_d:
            inner_prod += v * y_d[k]
    return inner_prod