Exemple #1
0
def test_numpy_mm2():
    """
    Test @ based NumpyTensor matrix multiply
    """
    x = sy.NumpyTensor(numpy_tensor=np.array([[1, 2, 3, 4]]))
    y = x @ (x.transpose())
    assert (y.child.child == np.array([[30]])).all()
Exemple #2
0
def test_numpy_transpose():
    """
    Test basic NumpyTensor transpose
    """
    x = sy.NumpyTensor(numpy_tensor=np.array([[1, 2, 3, 4]]))
    y = x.transpose(0, 1)
    assert (y.child.child == np.array([[1], [2], [3], [4]])).all()
Exemple #3
0
def test_numpy_dot():
    """
    Test basic NumpyTensor dot product
    """
    x = sy.NumpyTensor(numpy_tensor=np.array([[1, 2, 3, 4]]))
    y = x.dot(x.transpose())
    assert (y.child.child == np.array([[30]])).all()
Exemple #4
0
def test_numpy_add():
    """
    Test basic NumpyTensor addition
    """

    x = sy.NumpyTensor(numpy_tensor=[[1, 2, 3, 4]])
    y = x + x
    assert (y.child.child == np.array([2, 4, 6, 8])).all()
Exemple #5
0
def test_numpy_divide():
    """
    Test basic NumpyTensor division
    """

    x = sy.NumpyTensor(numpy_tensor=np.array([[1, 2, 3, 4]]))
    y = x / x
    assert (y.child.child == np.array([1, 1, 1, 1])).all()
Exemple #6
0
def test_numpy_multiply():
    """
    Test basic NumpyTensor multiplication
    """

    x = sy.NumpyTensor(numpy_tensor=np.array([[1, 2, 3, 4]]))
    y = x * x
    assert (y.child.child == np.array([1, 4, 9, 16])).all()
Exemple #7
0
def test_numpy_subtract():
    """
    Test basic NumpyTensor subtraction
    """

    x = sy.NumpyTensor(numpy_tensor=np.array([[1, 2, 3, 4]]))
    y = x - x
    assert (y.child.child == np.array([0, 0, 0, 0])).all()
Exemple #8
0
    def numpy_tensor(self):
        """This method will cast the current tensor to one with numpy as the underlying
        representation. The tensor chain will be Wrapper > NumpyTensor > np.ndarray"""

        if not self.is_wrapper:
            return syft.NumpyTensor(self.numpy())
        else:
            raise Exception(
                "Can only cast a data tensor to NumpyTensor. You called this ",
                "on a wrapper. Add NumpyTensor to the chain by hand if you want "
                "this functionality.",
            )