def test_sym_func(): a = 1 b = sympy.Symbol("x") c = NewArray((sympy.Symbol("x"), sympy.Symbol("y"))) d = NewArray((sympy.Symbol("x"), sympy.Symbol("x"), sympy.Symbol("z"))) e = NewArray([sympy.Symbol("x")] * self_grpup) sym_func = funcs["sym_func"] sym_func(a) sym_func(b) sym_func(c) s = sym_func(d) s = sym_func(e)
def test_sub(self): self.assertEqual( self.arr3 - self.a, NewArray([self.y - self.a, self.z - self.a, self.x - self.a])) arrs = NewArray([i - j for i, j in zip(self.arr3_, self.arr3)]) self.assertEqual(self.arr3_ - self.arr3, arrs) self.assertNotEqual(self.arr3_NaN - self.arr3, arrs) arrs2 = NewArray([i - j for i, j in zip(self.n, self.arr3)]) self.assertEqual(self.n - self.arr3, arrs2)
def setUp(self): self.a = sympy.Symbol("a") * sympy.Symbol("a") self.nan = nan self.n = NewArray([1.0, 1, Inf]) self.x = sympy.Symbol("x") self.k = sympy.Symbol("k") self.y = sympy.Symbol("y") self.z = sympy.Symbol("z") self.arr3 = NewArray([self.y, self.z, self.x]) self.arr3_ = NewArray([self.x, self.z, self.k]) self.arr3_NaN = NewArray([self.x, self.z, nan]) self.arr4 = NewArray([self.x, self.y, self.z, self.k])
def test_div(self): self.assertEqual( self.arr3 / self.a, NewArray([self.y / self.a, self.z / self.a, self.x / self.a])) # self.assertEqual(self.arr3/self.a, 1/NewArray([self.a/self.y ,self.a/ self.z , self.a/self.x])) arrs = NewArray([i / j for i, j in zip(self.arr3_, self.arr3)]) self.assertEqual(self.arr3_ / self.arr3, arrs) self.assertNotEqual(self.arr3_NaN / self.arr3, arrs) arrs2 = NewArray([i / j for i, j in zip(self.n, self.arr3)]) self.assertEqual(self.n / self.arr3, arrs2)
def test_add(self): self.assertEqual( self.a + self.arr3, NewArray([self.y + self.a, self.z + self.a, self.x + self.a])) self.assertEqual( self.arr3 + self.a, NewArray([self.y + self.a, self.z + self.a, self.x + self.a])) arrs = NewArray([i + j for i, j in zip(self.arr3_, self.arr3)]) self.assertEqual(self.arr3_ + self.arr3, arrs) self.assertNotEqual(self.arr3_NaN + self.arr3, arrs) arrs2 = NewArray([i + j for i, j in zip(self.n, self.arr3)]) self.assertEqual(self.arr3 + self.n, arrs2)
def test_mul(self): self.assertEqual( self.a * self.arr3, NewArray([self.y * self.a, self.z * self.a, self.x * self.a])) self.assertEqual( self.arr3 * self.a, NewArray([self.y * self.a, self.z * self.a, self.x * self.a])) arrs = NewArray([i * j for i, j in zip(self.arr3_, self.arr3)]) self.assertEqual(self.arr3_ * self.arr3, arrs) self.assertNotEqual(self.arr3_NaN * self.arr3, arrs) arrs2 = NewArray([i * j for i, j in zip(self.n, self.arr3)]) self.assertEqual(self.n * self.arr3, arrs2)
def gsymf(x): if isinstance(x, (np.ndarray, NewArray)): if x.shape[0] == 2: res = operation(x[0], x[1]) if keep: return NewArray(res) else: return res else: # >=3 if is_jump: return x else: res = operation(*x) if keep: return NewArray(res) else: return res else: # 1 return x
def test_mdiv(self): f = sym_map()["MDiv"] self.assertEqual(f(self.arr3), self.arr3) self.assertEqual(f(NewArray([self.y, self.z])), self.y / self.z)
def test_msub(self): f = sym_map()["MSub"] self.assertEqual(f(self.arr3), self.arr3) self.assertEqual(f(NewArray([self.y, self.z])), self.y - self.z)
def test_conv(self): f = sym_map()["Conv"] self.assertEqual(f(self.arr3), self.arr3) assert True == (f(NewArray([self.y, self.z])) == NewArray([self.z, self.y]))
def test_sin(self): f = sym_map()["exp"] self.assertEqual(f(self.arr3), NewArray([f(self.y), f(self.z), f(self.x)]))