Example #1
0
 def _check_symbolic_index(self, index):
     # Check if any index is symbolic:
     tuple_index = (index if isinstance(index, tuple) else (index,))
     if any([(isinstance(i, Expr) and (not i.is_number)) for i in tuple_index]):
         for i, nth_dim in zip(tuple_index, self.shape):
             if ((i < 0) == True) or ((i >= nth_dim) == True):
                 raise ValueError("index out of range")
         from sympy.tensor import Indexed
         return Indexed(self, *tuple_index)
     return None
Example #2
0
def test_Indexed_subs():
    i, j, k = symbols('i j k', integer=True)
    a, b = symbols('a b')
    A = Indexed(a)
    B = Indexed(b)
    assert A == B.subs(b, a)
Example #3
0
 def __getitem__(self, indices, **kw_args):
     if is_sequence(indices):
         # Special case needed because M[*my_tuple] is a syntax error.
         return Indexed(self, *indices, **kw_args)
     else:
         return Indexed(self, indices, **kw_args)