예제 #1
0
def test_group_add_bin():
    # original group_add
    obj = np.random.randn(10, 1)

    lab = np.array([0, 0, 0, 1, 1, 1, 2, 2, 2, 2], dtype=np.int32)
    cts = np.array([3, 3, 4], dtype=np.int32)
    exp = np.zeros((3, 1), np.float64)
    lib.group_add(exp, cts, obj, lab)

    # bin-based group_add
    bins = np.array([3, 6], dtype=np.int32)
    out  = np.zeros((3, 1), np.float64)
    counts = np.zeros(len(out), dtype=np.int32)
    lib.group_add_bin(out, counts, obj, bins)

    assert_almost_equal(out, exp)
예제 #2
0
def algo4():
    rizer = lib.DictFactorizer()
    labs1, _ = rizer.factorize(labels, sort=False)
    k1 = len(rizer.uniques)

    rizer = lib.DictFactorizer()
    labs2, _ = rizer.factorize(labels2, sort=False)
    k2 = len(rizer.uniques)

    group_id = labs1 * k2 + labs2
    max_group = k1 * k2

    if max_group > 1e6:
        rizer = lib.Int64Factorizer(len(group_id))
        group_id, _ = rizer.factorize(group_id.astype('i8'), sort=True)
        max_group = len(rizer.uniques)

    out = np.empty(max_group)
    counts = np.zeros(max_group, dtype='i4')
    lib.group_add(out, counts, data, group_id)
예제 #3
0
def algo4():
    rizer = lib.DictFactorizer()
    labs1, _ = rizer.factorize(labels, sort=False)
    k1 = len(rizer.uniques)

    rizer = lib.DictFactorizer()
    labs2, _ = rizer.factorize(labels2, sort=False)
    k2 = len(rizer.uniques)

    group_id = labs1 * k2 + labs2
    max_group = k1 * k2

    if max_group > 1e6:
        rizer = lib.Int64Factorizer(len(group_id))
        group_id, _ = rizer.factorize(group_id.astype('i8'), sort=True)
        max_group = len(rizer.uniques)

    out = np.empty(max_group)
    counts = np.zeros(max_group, dtype='i4')
    lib.group_add(out, counts, data, group_id)
예제 #4
0
def f2():
    rizer = lib.DictFactorizer()
    labs, counts = rizer.factorize(xarr, sort=False)
    k = len(rizer.uniques)
    out = np.empty(k)
    lib.group_add(out, counts, data, labs)
예제 #5
0
def algo3_sort():
    rizer = lib.DictFactorizer()
    labs, counts = rizer.factorize(labels, sort=True)
    k = len(rizer.uniques)
    out = np.empty(k)
    lib.group_add(out, counts, data, labs)
예제 #6
0
def f2():
    rizer = lib.DictFactorizer()
    labs, counts = rizer.factorize(xarr, sort=False)
    k = len(rizer.uniques)
    out = np.empty(k)
    lib.group_add(out, counts, data, labs)
예제 #7
0
def algo3_sort():
    rizer = lib.DictFactorizer()
    labs, counts = rizer.factorize(labels, sort=True)
    k = len(rizer.uniques)
    out = np.empty(k)
    lib.group_add(out, counts, data, labs)