def dict_diff(dict_a, dict_b):
    """
    Performs an elementwise subtraction of dict_b from dict_a
    """
    diff_dict = {}
    a = set(dict_a.keys())
    b = set(dict_b.keys())
    a_only = a.difference(b)
    b_only = b.difference(a)
    common = a.intersection(b)
    for k in a_only:
        diff_dict[k] = dict_a[k]
    for k in b_only:
        diff_dict[k] = -dict_b[k]
    for k in common:
        diff_dict[k] = dict_a[k] - dict_b[k]
    return diff_dict
