Ejemplo n.º 1
0
    def test_integral(self):
        symbolic = Broadcast(a * c, (3, ))
        indexed = symbolic[1]

        integ = sympy.Integral(symbolic, (a, 0, b))
        idx_integ = sympy.Integral(indexed, (a, 0, b))
        self.assertEqual(integ,
                         Broadcast(sympy.Integral(a * c, (a, 0, b)), (3, )))
        self.assertEqual(idx_integ,
                         Broadcast(sympy.Integral(a * c, (a, 0, b)), (3, ))[1])

        diffed = sympy.diff(symbolic, a)
        idx_diffed = sympy.diff(indexed, a)
        self.assertEqual(symbolic.subs(a, 1), diffed)
        self.assertEqual(indexed.subs(a, 1), idx_diffed)
Ejemplo n.º 2
0
    def test_scalar_broad_cast(self):
        symbolic = Broadcast(a, (6,))
        self.assertIs(symbolic.func, Broadcast)
        self.assertEqual(symbolic.args, (a, (6,)))

        subs_symbol = symbolic.subs({a: b})
        self.assertIs(subs_symbol.func, Broadcast)
        self.assertEqual(subs_symbol.args, (b, (6,)))

        subs_scalar = symbolic.subs({a: 3.4})
        self.assertEqual(subs_scalar, sympy.Array([3.4, 3.4, 3.4, 3.4, 3.4, 3.4]))

        subs_symbol_vector = symbolic.subs({a: (b, 1, 2, 3, 4, 5)})
        self.assertEqual(subs_symbol_vector, sympy.Array([b, 1, 2, 3, 4, 5]))

        subs_numeric_vector = symbolic.subs({a: (0, 1, 2, 3, 4, 5)})
        self.assertEqual(subs_numeric_vector, sympy.Array([0, 1, 2, 3, 4, 5]))

        with self.assertRaises(ValueError):
            symbolic.subs({a: (b, 4, 5)})

        with self.assertRaises(ValueError):
            symbolic.subs({a: (8, 5, 3, 5, 5, 4, 4, 5)})
Ejemplo n.º 3
0
    def test_symbolic_shape(self):
        symbolic = Broadcast(a, (b, ))
        self.assertIs(symbolic.func, Broadcast)
        self.assertEqual(symbolic.args, (a, (b, )))

        subs_b = symbolic.subs({b: 6})
        self.assertIs(subs_b.func, Broadcast)
        self.assertEqual(subs_b.args, (a, (6, )))

        subs_a = symbolic.subs({a: 3})
        self.assertIs(subs_a.func, Broadcast)
        self.assertEqual(subs_a.args, (3, (b, )))

        subs_both_scalar = symbolic.subs({a: 3, b: 6})
        self.assertEqual(subs_both_scalar, sympy.Array([3, 3, 3, 3, 3, 3]))

        subs_both_array = symbolic.subs({a: (1, 2, 3, 4, 5, 6), b: 6})
        self.assertEqual(subs_both_array, sympy.Array([1, 2, 3, 4, 5, 6]))

        with self.assertRaises(ValueError):
            symbolic.subs({a: (1, 2, 3, 4, 5, 6), b: 7})