def __rmul__ (self, other): print "Inside BasisVector.__rmul__" if isinstance(other, Transpose) and isinstance(other.args[0], BasisVector): if other.args[0].idx == self.idx: return one else: return zero if isinstance(other, Tensor): ero = other.rank eso = other.shape if ero == 2: return other.update(add_idx(other.name, self.idx), rank=1) if ero == 1 and eso == (1, n): return other.update(add_idx(other.name, self.idx), rank=0) return super(BasisVector, self).__rmul__(other)
def __new__(cls, pos_or_ten, shape=None, **kws): if isinstance(pos_or_ten, Tensor) and pos_or_ten.rank == 1: return pos_or_ten elif not isinstance(pos_or_ten, int): raise ValueError("Must give either tensor or position, given %s" % \ str(pos_or_ten)) obj = Tensor.__new__(cls, add_idx("e", pos_or_ten), rank=1) obj.idx = pos_or_ten return obj
def __new__ (cls, pos_or_ten, shape=None, **kws): if isinstance(pos_or_ten, Tensor) and pos_or_ten.rank == 1: return pos_or_ten elif not isinstance(pos_or_ten, int): raise ValueError("Must give either tensor or position, given %s" % \ str(pos_or_ten)) obj = Tensor.__new__(cls, add_idx("e", pos_or_ten), rank=1) obj.idx = pos_or_ten return obj