# the `post_op` annotation tells TinyChain to reflect over this function
# and assume that it defines a POST Op
# the annotation on `x` tells TinyChain to expect a `Tensor`
def average(x: tc.tensor.Tensor) -> tc.Number:
# the return annotation tells the calling code to expect a `Number`
if __name__ == "__main__":
cxt = tc.Context() # initialize a new Op context
# `average` is now a TinyChain `Op`, not a native Python function,
# so it needs to be made addressable by the calling context
cxt.x = tc.tensor.Dense.ones([3]) # initialize a new Dense tensor
cxt.result = cxt.average(x=tc.URI("$x")) # call our custom `Op`
actual = HOST.post(ENDPOINT, cxt) # execute the `Op` defined by `cxt`
assert actual == 1 # verify the result