Example #1
0
    def test_integer(self):
        a = sail.random.uniform(0, 11, (10, 20)).astype(sail.int32)
        b = sail.random.uniform(0, 11, (20, 10)).astype(sail.int32)

        c = sail.matmul(a, b)
        a = a.numpy()
        b = b.numpy()

        c2 = np.matmul(a, b)

        self.assert_eq_np_sail(c2, c, eps=1e-7)
Example #2
0
    def test_base(self, rq):
        choices = [(3, 3), (12, 18), (2, 33), (32, 64)]
        choices_2 = [[(3, 3), (3, 1), (3, 10)], [(18, 12), (18, 2)],
                     [(33, 1), (33, 33)], [(64, 12)]]
        times = []
        for ca, cbs in zip(choices, choices_2):
            for cb in cbs:
                verif_shape = (ca[0], cb[1])
                arr1 = np.random.uniform(0, 1, (ca))
                arr2 = np.random.uniform(0, 1, (cb))

                x1 = sail.Tensor(arr1, requires_grad=rq)
                x2 = sail.Tensor(arr2, requires_grad=rq)

                x3 = sail.matmul(x1, x2)
                arr3 = np.matmul(arr1, arr2)

                self.assert_eq(x3.shape, verif_shape)
                self.assert_eq_np_sail(arr3, x3, eps=1e-7)
                self.assert_eq(x3.requires_grad, rq)

        return
Example #3
0
	tensor (Tensor): Input data
	axis (int or tuple of ints, optional): If provided, then `axis` represents the axis the min will be computed over. If `axis` is a tuple, then the axes provided will be used to compute the min
	keepdims (boolean, optional): If True, then the axes that are reduced will be replaced with 1, otherwise, those axes will be removed

Examples:
	>>> x = sail.random.uniform(0, 1, (12, 32, 4, 5))
	>>> y = sail.min(x, 1, True)
	>>> y.shape
	(12, 1, 4, 5)
	>>> z = sail.min(x, -2, False)
	>>> z.shape
	(12, 32, 5)
	"""
add_docstring(sail.min, descr)

descr = r"""
sail.matmul(x1, x2) -> Tensor
Returns the matrix multiplication of `x1` and `x2`

.. math::
	\text{out} = \text{x1} \cdot \text{x1}

.. note::
	Both tensor `x1` and `x2` must be 2D, and their inner shapes must match.

Args:
	x1 (Tensor): A 2D Tensor
	x2 (Tensor): A 2D Tensor

Examples:
	>>> a = sail.random.uniform(0, 1, (5, 6))
Example #4
0
 def forward(a, b):
     c = sail.matmul(a, b)
     d = sail.sum(c)
     return d