Пример #1
0
    def test_min_dim(self):
        a = np.array([1])
        b = np.array([1, 2])
        exp = [1]
        act = supp.min_dim(a, b)
        self.assertListEqual(exp, act)

        a = np.array([[1], [1]])
        b = np.array([1, 2])
        exp = [2]
        act = supp.min_dim(a, b)
        self.assertListEqual(exp, act)
Пример #2
0
def sqrtxy(x, y, p):
    if is_np(x) and is_np(y):
        new_dim = min_dim(x, y)
        return np.sqrt(
            np.square(np.resize(x, new_dim)) +
            np.square(np.resize(y, new_dim))) / np.sqrt(2.0)
    return np.sqrt(np.square(x) + np.square(y)) / np.sqrt(2.0)
Пример #3
0
 def test_ypow_array(self):
     x, y = np.random.rand(5, 10), np.random.rand(3, 2)
     dim = supp.min_dim(x, y)
     x, p = np.resize(x, dim), np.resize(y, dim)
     exp = np.abs(x)**np.abs(y)
     act = mat.ypow(x, y, p)
     equal = np.equal(exp, act).all()
     self.assertEqual(equal, True)
Пример #4
0
 def test_cpow_array(self):
     x, p, y = np.random.rand(5, 10), np.random.rand(3, 2), 0
     dim = supp.min_dim(x, p)
     x, p = np.resize(x, dim), np.resize(p, dim)
     exp = np.abs(x)**(p + 1)
     act = mat.cpow(x, y, p)
     equal = np.equal(exp, act).all()
     self.assertEqual(equal, True)
Пример #5
0
 def test_sqrt_array(self):
     x, y = np.random.rand(5, 10), np.random.rand(3, 2)
     dim = supp.min_dim(x, y)
     x, p = np.resize(x, dim), np.resize(y, dim)
     exp = np.sqrt(x)
     act = mat.sqrt(x, y, 0)
     equal = np.equal(exp, act).all()
     self.assertEqual(equal, True)
Пример #6
0
 def test_inv_np_array_0(self):
     x, y = np.random.rand(5, 10), np.random.rand(3, 2)
     dim = supp.min_dim(x, y)
     x, p = np.resize(x, dim), np.resize(y, dim)
     exp = 1 / x
     act = mat.inv(x, y, 0)
     equal = np.equal(exp, act).all()
     self.assertEqual(equal, True)
Пример #7
0
 def test_add_np_array_1(self):
     x, y = np.random.rand(2, 3), np.random.rand(3, 2)
     dim = supp.min_dim(x, y)
     x, y = np.resize(x, dim), np.resize(y, dim)
     exp = (x + y) / 2.0
     act = mat.add(x, y, 0)
     equal = np.equal(exp, act).all()
     self.assertEqual(equal, True)
Пример #8
0
 def test_cmult_np_array_1(self):
     x, y = np.random.rand(5, 10), np.random.rand(3, 2)
     p = np.random.rand(100, 10)
     dim = supp.min_dim(x, p)
     x, p = np.resize(x, dim), np.resize(p, dim)
     exp = x * p
     act = mat.cmult(x, y, p)
     equal = np.equal(exp, act).all()
     self.assertEqual(equal, True)
Пример #9
0
def ypow(x, y, p):
    if is_np(x) and is_np(y):
        new_dim = min_dim(x, y)
        return (np.abs(np.resize(x, new_dim))**np.abs(np.resize(y, new_dim)))
    return np.abs(x)**np.abs(y)
Пример #10
0
def mult(x, y, p):
    if is_np(x) and is_np(y):
        new_dim = min_dim(x, y)
        return np.resize(x, new_dim) * np.resize(y, new_dim)
    return x * y
Пример #11
0
def aminus(x, y, p):
    if is_np(x) and is_np(y):
        new_dim = min_dim(x, y)
        return np.abs(np.resize(x, new_dim) - np.resize(y, new_dim)) / 2.0
    return np.abs(x - y) / 2.0
Пример #12
0
def add(x, y, p):
    if is_np(x) and is_np(y):
        new_dim = min_dim(x, y)
        return (np.resize(x, new_dim) + np.resize(y, new_dim)) / 2.0
    return (x + y) / 2.0
Пример #13
0
def gt(x, y, p):
    if is_np(x) and is_np(y):
        new_dim = min_dim(x, y)
        return np.resize(x, new_dim) > np.resize(y, new_dim)
    return x > y