def forward(a, b, d, f): c = (a / b) + (d * f) h = sail.exp(c) g = h - sail.max(h, 1, True) + d - c i = sail.sum(h) return i
def test_integer(self): choices = unary_elementwise_options times = [] for c in choices: arr1 = np.random.uniform(0, 1, (c)).astype(np.int32) x1 = sail.Tensor(arr1) x3 = sail.exp(x1) arr3 = np.exp(arr1) self.assert_eq_np_sail(arr3, x3, eps=1e-6) return
def test_base(self, rq): choices = unary_elementwise_options times = [] for c in choices: arr1 = np.random.uniform(0, 1, (c)) x1 = sail.Tensor(arr1, requires_grad=rq) t = time.time() x3 = sail.exp(x1) times.append(time.time() - t) arr3 = np.exp(arr1) self.assert_eq_np_sail(arr3, x3, eps=1e-6) self.assert_eq(x3.requires_grad, rq) return
def test_broadcast(self): choices = unary_broadcasted_options times = [] for c in choices: for i in range(len(c)): b = list(c) b[i] = 1 arr1 = np.random.uniform(1, 2, (b)) x1 = sail.Tensor(arr1, requires_grad=False) x2 = sail.broadcast_to(x1, c) arr2 = np.broadcast_to(arr1, c) t = time.time() x3 = sail.exp(x2) times.append(time.time() - t) arr3 = np.exp(arr2) self.assert_eq_np_sail(arr3, x3, eps=1e-6) return
.. note:: If tensor shapes do not match, they must be broadcastable to a common shape. Args: base (Tensor): Base exppnent (Tensor): Exponent Examples: >>> base = sail.random.uniform(0, 1, (20, 3)) >>> exponent = sail.random.uniform(1, 2, (20, 3)) >>> c = sail.power(base, exponent) """ add_docstring(sail.power, descr) descr = r""" sail.exp(tensor) -> Tensor Returns e the power `tensor`. .. math:: \text{out} = \text{e}^{\text{tensor}} Args: tensor (Tensor): The exponent Examples: >>> power = sail.random.uniform(1, 2, (20, 3)) >>> b = sail.exp(power) """ add_docstring(sail.exp, descr)
def forward(a): c = sail.exp(a) d = sail.sum(c) return d