mxnet icon indicating copy to clipboard operation
mxnet copied to clipboard

Add convenient method for numerical Ops under Numpy namespace

Open xidulu opened this issue 5 years ago • 0 comments

Description

This PR adds convenient method for numerical Ops (e.g. exp) under Numpy namespace (i.e. numpy extension ops not included).

This modification will significantly mitigate your pain of writing endless F.np in the hybrid_block.

Take sampling from gumbel distribution as an example

# Before
def gumbel_sample(pi):
    eps = F.np.random.uniform(F.np.zeros_like(pi))
    L = -F.np.log(-F.np.log(eps)) + F.np.log(pi)

# After
def gumbel_sample(pi):
    eps = F.np.random.uniform(F.np.zeros_like(pi)) # I wish this line get shortened in the future.
    L = -(-eps.log()).log() + pi.log()

xidulu avatar Mar 06 '20 14:03 xidulu