<commit_before>from syft import TensorBase
import unittest
import numpy as np

# Here's our "unit tests".
class AddTests(unittest.TestCase):
    def testSimple(self):
        t = TensorBase(np.array([1,2,3]))
        self.assertTrue(np.array_equal(t + np.array([1,2,3]), [2,4,6]))

    def testInplace(self):
        t = TensorBase(np.array([1,2,3]))
        t += np.array([1,2,3])
        self.assertTrue(np.array_equal(t.data, [2,4,6]))

    def testScalar(self):
        t = TensorBase(np.array([1,2,3]))
        self.assertTrue(np.array_equal(t + 2, [3, 4, 5]))

class SubTests(unittest.TestCase):
    def testSimple(self):
        t = TensorBase(np.array([1,2,3]))
        self.assertTrue(np.array_equal(t - np.array([1,2,3]), [0,0,0]))

    def testInplace(self):
        t = TensorBase(np.array([1,2,3]))
        t -= np.array([1,2,3])
        self.assertTrue(np.array_equal(t.data, [0,0,0]))

    def testScalar(self):
        t = TensorBase(np.array([1,2,3]))
        self.assertTrue(np.array_equal(t - 1, [0, 1, 2]))

class MultTests(unittest.TestCase):
    def testSimple(self):
        t = TensorBase(np.array([1,2,3]))
        self.assertTrue(np.array_equal(t * np.array([1,2,3]), [1,4,9]))

    def testInplace(self):
        t = TensorBase(np.array([1,2,3]))
        t *= np.array([1,2,3])
        self.assertTrue(np.array_equal(t.data, [1,4,9]))

    def testScalar(self):
        t = TensorBase(np.array([1,2,3]))
        self.assertTrue(np.array_equal(t * 2, [2, 4, 6]))

class DivTests(unittest.TestCase):
    def testSimple(self):
        t = TensorBase(np.array([2,4,8]))
        self.assertTrue(np.array_equal(t / np.array([2,2,2]), [1,2,4]))

    def testInplace(self):
        t = TensorBase(np.array([1,2,3]))
        t *= np.array([1,2,3])
        self.assertTrue(np.array_equal(t.data, [1,4,9]))

    def testScalar(self):
        t = TensorBase(np.array([2,4,6]))
        self.assertTrue(np.array_equal(t / 2, [1, 2, 3]))

class AbsTests(unittest.TestCase):
       
    def testabs(self):
        t = TensorBase(np.array([-1,-2,3]))
        self.assertTrue(np.array_equal(t.abs(),[1,2,3]))
    def testabs_(self):
        t = TensorBase(np.array([-1,-2,3]))
        self.assertTrue(np.array_equal(t.abs_(),t.data))  

class ShapeTests(unittest.TestCase):
    def testShape(self):
        t = TensorBase(np.array([[0, 1], [0, 5]]))
        self.assertTrue(np.array_equal(t.shape(), (2, 2)))

class SumTests(unittest.TestCase):
    def testDimNoneInt(self):
        t = TensorBase(np.array([1,2,3]))
        self.assertTrue(np.array_equal(t.sum(), 6))

    def testDimIsNotNoneInt(self):
        t = TensorBase(np.array([[0, 1], [0, 5]]))
        self.assertTrue(np.array_equal(t.sum(dim=1), [1, 5]))

def main():
    unittest.main()

if __name__ == '__main__':
    main()<commit_msg>Update test_tensor.py<commit_after>from syft import TensorBase
import unittest
import numpy as np

# Here's our "unit tests".
class AddTests(unittest.TestCase):
    def testSimple(self):
        t = TensorBase(np.array([1,2,3]))
        self.assertTrue(np.array_equal(t + np.array([1,2,3]), [2,4,6]))

    def testInplace(self):
        t = TensorBase(np.array([1,2,3]))
        t += np.array([1,2,3])
        self.assertTrue(np.array_equal(t.data, [2,4,6]))

    def testScalar(self):
        t = TensorBase(np.array([1,2,3]))
        self.assertTrue(np.array_equal(t + 2, [3, 4, 5]))

class SubTests(unittest.TestCase):
    def testSimple(self):
        t = TensorBase(np.array([1,2,3]))
        self.assertTrue(np.array_equal(t - np.array([1,2,3]), [0,0,0]))

    def testInplace(self):
        t = TensorBase(np.array([1,2,3]))
        t -= np.array([1,2,3])
        self.assertTrue(np.array_equal(t.data, [0,0,0]))

    def testScalar(self):
        t = TensorBase(np.array([1,2,3]))
        self.assertTrue(np.array_equal(t - 1, [0, 1, 2]))

class MultTests(unittest.TestCase):
    def testSimple(self):
        t = TensorBase(np.array([1,2,3]))
        self.assertTrue(np.array_equal(t * np.array([1,2,3]), [1,4,9]))

    def testInplace(self):
        t = TensorBase(np.array([1,2,3]))
        t *= np.array([1,2,3])
        self.assertTrue(np.array_equal(t.data, [1,4,9]))

    def testScalar(self):
        t = TensorBase(np.array([1,2,3]))
        self.assertTrue(np.array_equal(t * 2, [2, 4, 6]))

class DivTests(unittest.TestCase):
    def testSimple(self):
        t = TensorBase(np.array([2,4,8]))
        self.assertTrue(np.array_equal(t / np.array([2,2,2]), [1,2,4]))

    def testInplace(self):
        t = TensorBase(np.array([1,2,3]))
        t *= np.array([1,2,3])
        self.assertTrue(np.array_equal(t.data, [1,4,9]))

    def testScalar(self):
        t = TensorBase(np.array([2,4,6]))
        self.assertTrue(np.array_equal(t / 2, [1, 2, 3]))

class AbsTests(unittest.TestCase):
       
    def testabs(self):
        t = TensorBase(np.array([-1,-2,3]))
        self.assertTrue(np.array_equal(t.abs(),[1,2,3]))
    def testabs_(self):
        t = TensorBase(np.array([-1,-2,3]))
        self.assertTrue(np.array_equal(t.abs_(),t.data))  

class ShapeTests(unittest.TestCase):
    def testShape(self):
        t = TensorBase(np.array([[0, 1], [0, 5]]))
        self.assertTrue(np.array_equal(t.shape(), (2, 2)))

class SumTests(unittest.TestCase):
    def testDimNoneInt(self):
        t = TensorBase(np.array([1,2,3]))
        self.assertTrue(np.array_equal(t.sum(), 6))

    def testDimIsNotNoneInt(self):
        t = TensorBase(np.array([[0, 1], [0, 5]]))
        self.assertTrue(np.array_equal(t.sum(dim=1), [1, 5]))
class addmm(unittest.TestCase):
    def testaddmm1d(self):
        t1=TensorBase(np.array([1,2,3]))
        t2=TensorBase(np.array([2,3,4]))
        mat=TensorBase(np.array([5]))
        out=t1.addmm(t2,mat,beta=2,alpha=2)
        self.assertTrue(np.array_equal(out.data,[50]))
    
    def testaddmm2d(self):
        t1=TensorBase(np.array([[1,2],[1,2]]))
        t2=TensorBase(np.array([[1,2],[1,2]]))
        mat=TensorBase(np.array([[2,3],[3,4]]))
        out=t1.addmm(t2,mat,beta=2,alpha=2)
        self.assertTrue(np.array_equal(out.data,[[10,18],[12,20]]))
    
    def testaddmm_1d(self):
        t1=TensorBase(np.array([1,2,3]))
        t2=TensorBase(np.array([2,3,4]))
        mat=TensorBase(np.array([5]))
        t1.addmm_(t2,mat,beta=2,alpha=2)
        self.assertTrue(np.array_equal(t1.data,[50]))
    
    def testaddmm_2d(self):
        t1=TensorBase(np.array([[1,2],[1,2]]))
        t2=TensorBase(np.array([[1,2],[1,2]]))
        mat=TensorBase(np.array([[2,3],[3,4]]))
        t1.addmm_(t2,mat,beta=2,alpha=2)
        self.assertTrue(np.array_equal(t1.data,[[10,18],[12,20]]))

def main():
    unittest.main()

if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.20214190093708165, 'fraction_numerical': 0.05057266101442808, 'mean_word_length': 3.1075137446548564, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7109828', 'n_tokens_mistral': 2672, 'n_tokens_neox': 2629, 'n_words': 364}