Esempio n. 1
0
def untake(x, idx, vs):
    if isinstance(idx, list) and (len(idx) == 0
                                  or not isinstance(idx[0], slice)):
        idx = onp.array(idx, dtype='int64')

    def mut_add(A):
        onp.add.at(A, idx, x)
        return A

    return SparseObject(vs, mut_add)
Esempio n. 2
0
def untake(x, idx, vs):
    def mut_add(A):
        # in numpy codebase, this used to be:
        # onp.add.at(A, idx, x)
        # according to https://docs-cupy.chainer.org/en/stable/reference/ufunc.html?highlight=ufunc.at,
        # scatter_add is the correct function to use.
        # TODO: PR into cupy codebase the ability to use scatter_add with float64?
        ocpx.scatter_add(A, idx, x)
        return A

    return SparseObject(vs, mut_add)
Esempio n. 3
0
def untake(x, idx, vs):
    def mut_add(A):
        onp.add.at(A, idx, x)
        return A
    return SparseObject(vs, mut_add)