haydnv / tinychain

A next-gen database + SaaS framework for rapid development and integration of enterprise services

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support multiple axes in `Tensor` reduce methods

haydnv opened this issue · comments

i.e. min, max, sum, product

Example:

# ...

@tc.post
def average(tensor, *axes):
    assert hasattr(axes, "__len__")

    if axes:
        return tensor.sum(axes) / functools.reduce(operator.mul, tensor.shape[x] for x in axes)
    else:
        return tensor.sum() / tensor.size