def __rmatmul__(self, other): T = type(other) if T is RationalVector: out = _matmul(other.value, self.value) outRa = RationalVector(out) elif T is RationalMatrix: out = _matmul(other.value, self.value) outRa = RationalMatrix(out) else: out = _matmul(other, self.value) if _utils.isSquare(out): outRa = RationalMatrix(out) elif _utils.isVector(out): outRa = RationalVector(out) return outRa
def __add__(self, other): T = type(other) if T is int or T is _Fraction: out = self.value + other outRa = RationalVector(out) elif T is float: out = self.value + _Fraction(other) outRa = RationalVector(out) else: if T is RationalVector: out = self.value + other.value else: out = self.value + other if _utils.isVector(out): outRa = RationalVector(out) elif _utils.isSquare(out): outRa = RationalMatrix(out) else: raise ValueError('Dimension mismatch.') return outRa